Skip to content
This repository was archived by the owner on Oct 18, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions api-data-module/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>school-2016</artifactId>
<groupId>ru.qatools.school</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>api-data-module</artifactId>
<name>API Data Module</name>

<dependencies>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.3</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ru.qatools.school.apiData;

/**
* @author totallynotkate (Kate Kocijevska).
*/
public class CitySuggest {
public int id;

public String country;

public String name;

public int uid;

public int getId() {
return id;
}

public String getCountry() {
return country;
}

public String getName() {
return name;
}

public int getUid() {
return uid;
}

}
30 changes: 30 additions & 0 deletions api-data-module/src/main/java/ru/qatools/school/apiData/URI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ru.qatools.school.apiData;

/**
* @author totallynotkate (Kate Kocijevska)
*/
public enum URI {
BASE_URI("http://weather.lanwen.ru/"),
BASE_PATH("api"),

CITIES_RESOURCE("cities"),
LIMIT_PARAMETER("limit"),

SUGGEST_RESOURCE("suggest"),
QUERY_PARAMETER("query");

private final String URIValue;

URI (String URIValue){
this.URIValue = URIValue;
}

public String getValue(){
return URIValue;
}

@Override
public String toString(){
return URIValue;
}
}
50 changes: 50 additions & 0 deletions api-db-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>school-2016</artifactId>
<groupId>ru.qatools.school</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>dbclient-tests</artifactId>

<dependencies>
<dependency>
<groupId>ru.qatools.school</groupId>
<artifactId>dbclient-module</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-java-annotations</artifactId>
<version>1.4.23</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<version>2.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>json-schema-validator</artifactId>
<version>2.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.matchers</groupId>
<artifactId>collection-matchers</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>com.googlecode.lambdaj</groupId>
<artifactId>lambdaj</artifactId>
<version>2.3.3</version>
</dependency>
</dependencies>

</project>
48 changes: 48 additions & 0 deletions api-db-tests/src/test/java/ru/qatools/school/DbTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package ru.qatools.school;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import ru.qatools.school.apiData.CitySuggest;
import ru.qatools.school.apiData.URI;
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Title;

import java.util.Arrays;
import java.util.List;

import static com.jayway.restassured.RestAssured.given;
import static org.hamcrest.MatcherAssert.assertThat;
import static ru.yandex.qatools.matchers.collection.HasSameItemsAsListMatcher.hasSameItemsAsList;

/**
* @author totallynotkate (Kate Kocijevska)
*/
public class DbTest {

private static final String PARTIAL_CITY_NAME = "mos";
private DbClient dbClient;

@Before
public void before(){
dbClient = new DbClient();
}

@Test
@Title ("Списки саджестов городов из API и БД должны совпадать")
@Features("Запросы к БД и API")
public void shouldGetSameSuggests(){
List<CitySuggest> dbSuggest = dbClient.getSuggestedCities(PARTIAL_CITY_NAME);
List<CitySuggest> apiSuggest = Arrays.asList(given().baseUri(URI.BASE_URI.getValue())
.basePath(URI.BASE_PATH.getValue())
.param(URI.QUERY_PARAMETER.getValue(), PARTIAL_CITY_NAME)
.get(URI.SUGGEST_RESOURCE.getValue())
.as(CitySuggest[].class));
assertThat("Списки саджестов городов из API и БД должны совпадать", apiSuggest, hasSameItemsAsList(dbSuggest));
}

@After
public void after(){
dbClient.close();
}
}
5 changes: 5 additions & 0 deletions dbclient-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>ru.qatools.school</groupId>
<artifactId>api-data-module</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>


Expand Down
9 changes: 9 additions & 0 deletions dbclient-module/src/main/java/ru/qatools/school/DbClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import org.jooq.*;
import org.jooq.impl.DSL;
import ru.qatools.school.apiData.CitySuggest;

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;
Expand Down Expand Up @@ -39,6 +41,13 @@ public String getCityById(Integer id) {
return result.getValue(0, String.class);
}

public List<CitySuggest> getSuggestedCities(String query){
return create.select()
.from(table("City"))
.where(field("name").contains(query))
.fetchInto(CitySuggest.class);
}

public void close() {
try {
connection.close();
Expand Down
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<module>steps-module</module>
<module>commons-module</module>
<module>dbclient-module</module>
<module>dbclient-tests</module>
<module>api-data-module</module>
</modules>

<properties>
Expand Down