Skip to content
This repository has been archived by the owner on Oct 18, 2018. It is now read-only.

My API autotests #88

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
40 changes: 40 additions & 0 deletions api-tests-module/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>school-2016</artifactId>
<groupId>ru.qatools.school</groupId>
<version>1.0-SNAPSHOT</version>
</parent>

<dependencies>
<dependency>
<groupId>ru.qatools.school</groupId>
<artifactId>steps-module</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<version>2.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>converter-gson</artifactId>
<version>2.0.2</version>
</dependency>
</dependencies>

<artifactId>api-tests-module</artifactId>
<name>Web API tests</name>

</project>
31 changes: 31 additions & 0 deletions api-tests-module/src/test/java/RestassuredTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import org.apache.http.HttpStatus;
import org.junit.Test;

import static com.jayway.restassured.RestAssured.given;
import static org.hamcrest.Matchers.is;

public class RestassuredTests {

public static final String BASE_URI = "http://weather.lanwen.ru";
public static final String BASE_PATH = "api";
public static final String LIMIT_PARAMETER = "limit";
public static final String CITIES_RESOURCE = "cities";
public static final int POSITIVE_CITIES_LIMIT = 1;
public static final int CITIES_LIST_ONE = 1;
public static final int NEGATIVE_CITIES_LIMIT = -1;

@Test
public void shouldGetCitiesListWhenRequestPositiveCitiesLimit() {
given().baseUri(BASE_URI)
.basePath(BASE_PATH).param(LIMIT_PARAMETER, POSITIVE_CITIES_LIMIT)
.get(CITIES_RESOURCE).then().assertThat().statusCode(HttpStatus.SC_OK)
.and().body("toSet.size()", is(CITIES_LIST_ONE));
}

@Test
public void shouldGetErrorWhenRequestNegativeCitiesLimit() {
given().baseUri(BASE_URI)
.basePath(BASE_PATH).param(LIMIT_PARAMETER, NEGATIVE_CITIES_LIMIT)
.get(CITIES_RESOURCE).then().assertThat().statusCode(HttpStatus.SC_BAD_REQUEST);
}
}
44 changes: 44 additions & 0 deletions api-tests-module/src/test/java/RetrofitTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import org.apache.http.HttpStatus;
import org.junit.Test;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import ru.qatools.school.apiData.Cities;
import ru.qatools.school.apiData.CityJSON;

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

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

public class RetrofitTests {

private static final String BASE_URL = "http://weather.lanwen.ru";
public static final int POSITIVE_CITIES_LIMIT = 1;
public static final int CITIES_LIST_ONE = 1;
private static final String NEGATIVE_CITIES_LIMIT = "-1";

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

@Test
public void shouldGetCitiesListWhenRequestPositiveCitiesLimit() throws IOException {
Cities cities = citiesRetrofit.create(Cities.class);
Call<List<CityJSON>> request = cities.cities(String.valueOf(POSITIVE_CITIES_LIMIT));
Response<List<CityJSON>> response = request.execute();
assertThat(response.code(), is(HttpStatus.SC_OK));
assertThat(response.body().size(), is(CITIES_LIST_ONE));
}

@Test
public void shouldGetErrorWhenRequestNegativeCitiesLimit() throws IOException {
Cities cities = citiesRetrofit.create(Cities.class);
Call<List<CityJSON>> request = cities.cities(NEGATIVE_CITIES_LIMIT);
Response<List<CityJSON>> response = request.execute();
assertThat(response.code(), is(HttpStatus.SC_BAD_REQUEST));
}
}
52 changes: 52 additions & 0 deletions commons-module/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>school-2016</artifactId>
<groupId>ru.qatools.school</groupId>
<version>1.0-SNAPSHOT</version>
</parent>

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

<name>Commons Module</name>

<dependencies>
<dependency>
<groupId>ru.qatools.school</groupId>
<artifactId>steps-module</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.tngtech.java</groupId>
<artifactId>junit-dataprovider</artifactId>
<version>1.10.4</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>

<reporting>
<excludeDefaults>true</excludeDefaults>
<plugins>
<plugin>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-maven-plugin</artifactId>
<version>2.0</version>
</plugin>
</plugins>
</reporting>

</project>
53 changes: 53 additions & 0 deletions commons-module/src/test/java/ru/qatools/school/MyFirstTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package ru.qatools.school;

import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
import org.junit.Test;
import org.junit.runner.RunWith;
import ru.qatools.school.data.Place;

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

import static ru.qatools.school.steps.UserSteps.user;


/**
* @author gladnik (Nikolai Gladkov)
*/
@RunWith(DataProviderRunner.class)
public class MyFirstTest {

@DataProvider
public static List<Object> places() {
List<Object> placesList
= new ArrayList<Object>(Arrays.asList(Place.values()));
placesList.add(null);
return placesList;
}

@Test
public void shouldBeAtNullWhenDefault() {
user().shouldBeAtPlace(null);
}

@Test
@UseDataProvider("places")
public void afterGoSomewhereShouldBeThere(Place place) {
user().goTo(place).shouldBeAtPlace(place);
}

@Test
@UseDataProvider("places")
public void afterGoSomewhereTwiceShouldBeThere(Place place) {
user().goTo(place).goTo(place).shouldBeAtPlace(place);
}

@Test
public void afterGoSomewhereElseShouldBeThere() {
user().goTo(Place.HOME).goTo(Place.AT_YANDEX)
.shouldBeAtPlace(Place.AT_YANDEX);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package ru.qatools.school.tp;

import org.junit.Rule;
import org.junit.Test;
import ru.yandex.qatools.allure.annotations.TestCaseId;

import java.io.IOException;

import static java.util.concurrent.TimeUnit.SECONDS;
import static junit.framework.TestCase.fail;
import static org.hamcrest.Matchers.is;
import static org.junit.Assume.assumeThat;


public class ConnectedToTPTest {

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


@Test
@TestCaseId("1")
public void shouldMarkCaseStatusAsPassed() throws IOException, InterruptedException {
SECONDS.sleep(15);
}


@Test
@TestCaseId("2")
public void shouldFail() throws IOException, InterruptedException {
SECONDS.sleep(5);
fail();
}

@Test
@TestCaseId("3")
public void shouldBroke() throws IOException, InterruptedException {
SECONDS.sleep(5);
throw new RuntimeException();
}

@Test
@TestCaseId("4")
public void shouldBeSkipped() throws IOException, InterruptedException {
SECONDS.sleep(5);
assumeThat(true, is(false));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ru.qatools.school.webtests;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import ru.qatools.school.pages.MainPage;
import ru.qatools.school.rules.WebDriverRule;
import ru.qatools.school.steps.websteps.DefaultSteps;
import ru.yandex.qatools.allure.annotations.Title;

public class WeatherWebTest {

public static final String MOSCOW = "Moscow";

private DefaultSteps defaultSteps;

@Rule
public WebDriverRule webDriverRule = new WebDriverRule();

@Before
public void initSteps() {
defaultSteps = new DefaultSteps(webDriverRule.getDriver());
}

@Test
@Title("Должны видеть виджет на главной странице")
public void shouldSeeWidgetOnMainPage() {
defaultSteps.openMainPageWithCity(MOSCOW);
defaultSteps.shouldSee(onMainPage().getWeatherWidget().get(0));
}

private MainPage onMainPage() {
return new MainPage(webDriverRule.getDriver());
}

}
28 changes: 28 additions & 0 deletions dbclient-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>dbclient-module</artifactId>

<dependencies>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>3.7.3</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
</dependencies>


</project>
49 changes: 49 additions & 0 deletions dbclient-module/src/main/java/ru/qatools/school/DbClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package ru.qatools.school;

import org.jooq.*;
import org.jooq.impl.DSL;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.table;

/**
* Created by omaz on 27.04.16.
*/
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");;

private Connection connection;
private DSLContext create;

public DbClient() {
try {
connection = DriverManager.getConnection(CONNECTION_STRING, USER, PASSWORD);
} catch (SQLException e) {
throw new DbClientException("Не удалось установить подключение к " + CONNECTION_STRING, e);
}
create = DSL.using(connection, SQLDialect.MYSQL);
}

public String getCityById(Integer id) {
Record1 result = create.select(field("name"))
.from(table("table_name"))
.where(field("id").equal(id))
.fetchOne();
return result.getValue(0, String.class);
}

public void close() {
try {
connection.close();
} catch (SQLException e) {
throw new DbClientException("Не удалось закрыть подключение к " + CONNECTION_STRING, e);
}
}
}
Loading