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
56 changes: 56 additions & 0 deletions api-tests-module/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?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-tests-module</artifactId>

<dependencies>

<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>converter-gson</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-junit-adaptor</artifactId>
<version>1.4.23</version>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.matchers</groupId>
<artifactId>collection-matchers</artifactId>
<version>1.3</version>
</dependency>

</dependencies>


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

import com.jayway.restassured.response.Response;
import org.apache.http.HttpStatus;
import org.junit.Before;
import org.junit.Test;
import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.specification.RequestSpecification;
import ru.qatools.school.apitests.data.City;
import ru.qatools.school.apitests.data.WeatherInfo;
import ru.yandex.qatools.allure.annotations.Title;

import java.io.IOException;

import static com.jayway.restassured.RestAssured.given;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

/**
* @author Gavrilov_IS
*/
public class RestAssureAPITest {
private static final String MAIN_PAGE = "http://weather.lanwen.ru/";
private static final String BASE_PATH = "api";
private final String CITY = "Moscow";
private final int CITY_LIMIT = 5;

private RequestSpecification reqSpec;

@Before
public void init() {
reqSpec = new RequestSpecBuilder().build()
.baseUri(MAIN_PAGE)
.basePath(BASE_PATH);
}

@Test
@Title("Проверяем, что запрос обработан и город в ответе соответствует запрошенному")
public void shouldGetInfoForCityInRequest() throws IOException {
WeatherInfo response = given().spec(reqSpec)
.param("city", CITY)
.expect().statusCode(HttpStatus.SC_OK)
.get("weather")
.as(WeatherInfo.class);
assertThat("Город в ответе должен соответствовать запрошенному", response.getCity(), is(CITY));

}

@Test
@Title("Запрос на /cities с параметром limit=CITY_LIMIT вернул указанное количество записей")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ты тайтлы будешь видеть в аллюре и тестпалме, там нет CITY_LIMIT

public void shouldGetExpectedCountOfCities() throws IOException {
Response response = given().spec(reqSpec)
.param("limit", 5)
.get("cities");
response.then().assertThat()
.statusCode(HttpStatus.SC_OK);
City[] cities = response.as(City[].class);
assertThat("Количество городов должно соответствовать указанному лимиту", cities.length, is(CITY_LIMIT));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package ru.qatools.school.apitests;

import org.apache.http.HttpStatus;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import ru.qatools.school.apitests.data.City;
import ru.qatools.school.apitests.data.WeatherInfo;
import ru.qatools.school.apitests.interfaces.WeatherAPI;
import ru.yandex.qatools.allure.annotations.Title;

import java.io.IOException;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

/**
* @author Gavrilov_IS
*/
public class RetrofitAPITest {
private final String BASE_URL = "http://weather.lanwen.ru/api/";
private WeatherAPI weather;
private final String CITY = "Moscow";
private final int CITY_LIMIT = 5;

Retrofit client = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();

@Before
public void init() {
weather = client.create(WeatherAPI.class);
}

@Test
@Title("Проверяем, что запрос обработан и город в ответе соответствует запрошенному")
public void shouldGetInfoForCityInRequest() throws IOException {
Response<WeatherInfo> response = weather.getWeather(CITY).execute();
assertThat("Успешная обработка запроса", response.code(), is(HttpStatus.SC_OK));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это сообщение появится если ассерт упадет, похоже, обработка запроса будет неуспешная

assertThat("Город в ответе должен соответствовать запрошенному", response.body().getCity(), is(CITY));
}

@Test
@Title("Запрос на /cities с параметром limit=CITY_LIMIT вернул указанное количество записей")
public void shouldGetExpectedCountOfCities() throws IOException {
Response<List<City>> response = weather.getCitiesWithLimit(CITY_LIMIT).execute();
assertThat("Успешная обработка запроса", response.code(), is(HttpStatus.SC_OK));
assertEquals("Город в ответе должен соответствовать запрошенному", response.body().size(), CITY_LIMIT);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Копипаст, сообщение вообще не о том

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ru.qatools.school.apitests.data;

/**
* Created by Gavrilov_IS on 11.05.2016.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У тебя то @author, то Created by, ты это руками пишешь? В Идее можно настроить file header по умолчанию

*/
public class City {
private int UID;
private String name;
private String country;

public String getName(){
return name;
}

public int getUID(){
return UID;
}

public String getCountry(){
return country;
}

public void setName(String name){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не очень понятно, зачем тебе сеттеры у этих объектов

this.name = name;
}

public void setUID(int UID){
this.UID = UID;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ru.qatools.school.apitests.data;

/**
* @author Gavrilov_IS
*/
public class Temperature {
private String unit;
private double value;

public String getUnit(){
return unit;
}

public double getValue(){
return value;
}

@Override
public String toString(){
return "unit = " + unit + "; digit = " + value + "; \r\n";
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ru.qatools.school.apitests.data;

import java.util.List;

/**
* @author Gavrilov_IS
*/
public class WeatherInfo {
private String city;
private List<Temperature> temperatures;

public String getCity(){
return city;
}

public List<Temperature> getListOfTemperatures(){
return temperatures;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ru.qatools.school.apitests.interfaces;

import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Query;
import ru.qatools.school.apitests.data.City;
import ru.qatools.school.apitests.data.WeatherInfo;

import java.util.List;


/**
* @author Gavrilov_IS
*/
public interface WeatherAPI {
@GET("cities")
Call<List<City>> getCities();

@GET("cities")
Call<List<City>> getCitiesWithLimit(@Query ("limit") int lim);

@GET("suggest")
Call<List<City>> getSuggest(@Query ("query") String str);

@GET("weather")
Call<WeatherInfo> getWeather(@Query("city") String city);
}

2 changes: 1 addition & 1 deletion commons-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>

<artifactId>commons-module</artifactId>
<packaging>jar</packaging>
<packaging>pom</packaging>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А зачем?


<name>Commons Module</name>

Expand Down
53 changes: 0 additions & 53 deletions commons-module/src/test/java/ru/qatools/school/MyFirstTest.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

public class ConnectedToTPTest {

@Rule
public TPInformerRule tms = new TPInformerRule("ruletest");
/* @Rule
public TPInformerRule tms = new TPInformerRule("ruletest");


@Test
Expand Down Expand Up @@ -44,5 +44,5 @@ public void shouldBroke() throws IOException, InterruptedException {
public void shouldBeSkipped() throws IOException, InterruptedException {
SECONDS.sleep(5);
assumeThat(true, is(false));
}
}*/
}
Loading