-
Notifications
You must be signed in to change notification settings - Fork 28
db vs api test #73
base: master
Are you sure you want to change the base?
db vs api test #73
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package ru.qatools.school.webtests; | ||
|
||
import org.apache.http.HttpStatus; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import retrofit2.Call; | ||
import retrofit2.Response; | ||
import retrofit2.Retrofit; | ||
import retrofit2.converter.gson.GsonConverterFactory; | ||
import ru.qatools.school.ApiData.retrofits.APITestService; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Этого модуля в коммите вообще нет. В твоем репозитории ApiData и retrofits лежат отдельно, вроде бы это |
||
import ru.qatools.school.ApiData.retrofits.City; | ||
import ru.qatools.school.DbClient; | ||
import ru.yandex.qatools.allure.annotations.Title; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.hamcrest.core.Is.is; | ||
import static org.junit.Assert.assertThat; | ||
import static ru.qatools.school.ApiData.ApiDataPreconditions.BASE_URL; | ||
import static ru.yandex.qatools.matchers.collection.HasSameItemsAsListMatcher.hasSameItemsAsList; | ||
|
||
|
||
/** | ||
* @author arrumm 09.05.2016. | ||
*/ | ||
public class MyDbTest { | ||
|
||
private APITestService service; | ||
private DbClient MyClient; | ||
|
||
private static final String SUGGEST_STRING = "bu"; | ||
|
||
@Before | ||
public void initService() { | ||
MyClient = new DbClient(); | ||
|
||
Retrofit retrofit = new Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build(); | ||
service = retrofit.create(APITestService.class); | ||
} | ||
|
||
@Test | ||
@Title("Should get equal lists both by query to database and by api method") | ||
//@TestCaseId("14") | ||
public void shouldGetCitiesWithBuApiDb() throws IOException { | ||
|
||
List<String> cities = MyClient.getCitiesNameContains(SUGGEST_STRING); | ||
|
||
Call<List<City>> request = service.suggest("bu"); | ||
Response<List<City>> response = request.execute(); | ||
assertThat("Request status different from expected", response.code(), is(HttpStatus.SC_OK)); | ||
|
||
List<String> names = response.body().stream().map(City::getName).collect(Collectors.toList()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Не очень понятно, почему сначала мы собираем города в список |
||
|
||
assertThat("Cities from api don't match cities from db", | ||
cities, | ||
hasSameItemsAsList(names)); | ||
|
||
} | ||
|
||
@After | ||
public void closeConnection() { | ||
MyClient.close(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,11 @@ | |
<artifactId>mysql-connector-java</artifactId> | ||
<version>5.1.6</version> | ||
</dependency> | ||
<dependency> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Но почему? Где ты от него зависишь? |
||
<groupId>ru.qatools.school</groupId> | ||
<artifactId>api-tests-module</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,28 @@ | ||
package ru.qatools.school; | ||
|
||
import org.jooq.*; | ||
import org.jooq.DSLContext; | ||
import org.jooq.Record1; | ||
import org.jooq.SQLDialect; | ||
import org.jooq.impl.DSL; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
import java.util.List; | ||
|
||
import static org.jooq.impl.DSL.field; | ||
import static org.jooq.impl.DSL.table; | ||
import static ru.qatools.school.DbPreconditions.*; | ||
|
||
/** | ||
* Created by omaz on 27.04.16. | ||
* edited by arrumm | ||
*/ | ||
public class DbClient { | ||
private static final String CONNECTION_STRING = | ||
System.getProperty("db.url", "jdbc:mysql://db.host.ru:3310/db_name"); | ||
private static final String USER = System.getProperty("db.user", "user"); | ||
private static final String PASSWORD = System.getProperty("db.password", "password");; | ||
System.getProperty("db.url", DB_URL); | ||
private static final String USER = System.getProperty("db.user", DB_USER); | ||
private static final String PASSWORD = System.getProperty("db.password", DB_PASSWORD); | ||
|
||
private Connection connection; | ||
private DSLContext create; | ||
|
@@ -36,7 +41,15 @@ public String getCityById(Integer id) { | |
.from(table("table_name")) | ||
.where(field("id").equal(id)) | ||
.fetchOne(); | ||
return result.getValue(0, String.class); | ||
return result.getValue(0, String.class); | ||
} | ||
|
||
public List<String> getCitiesNameContains(String name) { | ||
List<String> cities = create.select() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Local variable 'cities' is redundant, подсказывает нам Идея. |
||
.from(table("City")) | ||
.where(field("name").like("%" + name + "%")) | ||
.limit(100).fetch().getValues("name", String.class); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Я бы назвала метод как-то типа getUpTo100CitiesContaining с учетом вот этого лимит 100. А то это нигде не документировано и может уронить тест, например, если ты будешь запрашивать саджест для городов, которые содержат ovo. Апи тебе всяких Протасово и Домодедово отдаст кучу, а БД - только сотню |
||
return cities; | ||
} | ||
|
||
public void close() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Дубль.