You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dlab.apache.org by bh...@apache.org on 2019/07/22 10:35:18 UTC
[incubator-dlab] branch develop updated: DLAB-000 added new module
for integration tests
This is an automated email from the ASF dual-hosted git repository.
bhliva pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git
The following commit(s) were added to refs/heads/develop by this push:
new e598162 DLAB-000 added new module for integration tests
e598162 is described below
commit e5981624ba6200bd6ce8ea3e295c8fa03c9c0543
Author: bhliva <bo...@epam.com>
AuthorDate: Mon Jul 22 13:34:47 2019 +0300
DLAB-000 added new module for integration tests
---
integration-tests-cucumber/pom.xml | 114 +++++++++++++++++++++
.../main/java/org/apache/dlab/dto/EndpointDTO.java | 19 ++++
.../java/org/apache/dlab/mongo/MongoDBHelper.java | 14 +++
.../java/org/apache/dlab/util/JacksonMapper.java | 16 +++
.../java/org/apache/dlab/util/PropertyHelper.java | 23 +++++
.../src/test/java/dlab/Constants.java | 5 +
.../src/test/java/dlab/RunCucumberTest.java | 10 ++
.../src/test/java/dlab/endpoint/EndpointSteps.java | 97 ++++++++++++++++++
.../src/test/java/dlab/login/LoginSteps.java | 44 ++++++++
.../src/test/resources/config.properties | 2 +
.../src/test/resources/dlab/endpoint.feature | 57 +++++++++++
.../src/test/resources/dlab/login.feature | 12 +++
12 files changed, 413 insertions(+)
diff --git a/integration-tests-cucumber/pom.xml b/integration-tests-cucumber/pom.xml
new file mode 100644
index 0000000..d96a492
--- /dev/null
+++ b/integration-tests-cucumber/pom.xml
@@ -0,0 +1,114 @@
+<?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>
+
+ <groupId>com.epam.dlab</groupId>
+ <artifactId>integration-tests</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <properties>
+ <cucumber.version>4.2.6</cucumber.version>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ <version>2.9.9</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>2.9.9</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ <version>2.9.9</version>
+ </dependency>
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <version>1.18.8</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mongodb</groupId>
+ <artifactId>mongo-java-driver</artifactId>
+ <version>3.10.2</version>
+ </dependency>
+
+
+ <dependency>
+ <groupId>io.cucumber</groupId>
+ <artifactId>cucumber-java</artifactId>
+ <version>${cucumber.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.cucumber</groupId>
+ <artifactId>cucumber-junit</artifactId>
+ <version>${cucumber.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.12</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.jayway.restassured</groupId>
+ <artifactId>rest-assured</artifactId>
+ <version>2.9.0</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <testFailureIgnore>true</testFailureIgnore>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.7.0</version>
+ <configuration>
+ <encoding>UTF-8</encoding>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>net.masterthought</groupId>
+ <artifactId>maven-cucumber-reporting</artifactId>
+ <version>2.8.0</version>
+ <executions>
+ <execution>
+ <id>execution</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ <configuration>
+ <projectName>CucumberWebGui</projectName>
+ <outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory>
+ <cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
+ <skippedFails>true</skippedFails>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/integration-tests-cucumber/src/main/java/org/apache/dlab/dto/EndpointDTO.java b/integration-tests-cucumber/src/main/java/org/apache/dlab/dto/EndpointDTO.java
new file mode 100644
index 0000000..a06a4d7
--- /dev/null
+++ b/integration-tests-cucumber/src/main/java/org/apache/dlab/dto/EndpointDTO.java
@@ -0,0 +1,19 @@
+package org.apache.dlab.dto;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@JsonIgnoreProperties(ignoreUnknown = true)
+@AllArgsConstructor
+@NoArgsConstructor
+public class EndpointDTO {
+ private String name;
+ private String url;
+ private String account;
+ @JsonProperty("endpoint_tag")
+ private String tag;
+}
diff --git a/integration-tests-cucumber/src/main/java/org/apache/dlab/mongo/MongoDBHelper.java b/integration-tests-cucumber/src/main/java/org/apache/dlab/mongo/MongoDBHelper.java
new file mode 100644
index 0000000..11e4dea
--- /dev/null
+++ b/integration-tests-cucumber/src/main/java/org/apache/dlab/mongo/MongoDBHelper.java
@@ -0,0 +1,14 @@
+package org.apache.dlab.mongo;
+
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
+import org.apache.dlab.util.PropertyHelper;
+
+public class MongoDBHelper {
+ private static final MongoClient client = MongoClients
+ .create(PropertyHelper.read("mongo.connection.string"));
+
+ public static void cleanCollection(String collection) {
+ client.getDatabase(PropertyHelper.read("mongo.db.name")).getCollection(collection).drop();
+ }
+}
diff --git a/integration-tests-cucumber/src/main/java/org/apache/dlab/util/JacksonMapper.java b/integration-tests-cucumber/src/main/java/org/apache/dlab/util/JacksonMapper.java
new file mode 100644
index 0000000..a18d4d9
--- /dev/null
+++ b/integration-tests-cucumber/src/main/java/org/apache/dlab/util/JacksonMapper.java
@@ -0,0 +1,16 @@
+package org.apache.dlab.util;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public final class JacksonMapper {
+ private static final ObjectMapper MAPPER = new ObjectMapper();
+
+ public static <T> String marshall(T obj) {
+ try {
+ return MAPPER.writeValueAsString(obj);
+ } catch (JsonProcessingException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+}
diff --git a/integration-tests-cucumber/src/main/java/org/apache/dlab/util/PropertyHelper.java b/integration-tests-cucumber/src/main/java/org/apache/dlab/util/PropertyHelper.java
new file mode 100644
index 0000000..48d7cca
--- /dev/null
+++ b/integration-tests-cucumber/src/main/java/org/apache/dlab/util/PropertyHelper.java
@@ -0,0 +1,23 @@
+package org.apache.dlab.util;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.Properties;
+
+public class PropertyHelper {
+
+ private final static Properties PROPERTIES;
+
+ static {
+ PROPERTIES = new Properties();
+ try (InputStream inputStream = new FileInputStream(System.getProperty("config.file"))) {
+ PROPERTIES.load(inputStream);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static String read(String prop) {
+ return PROPERTIES.getProperty(prop);
+ }
+}
diff --git a/integration-tests-cucumber/src/test/java/dlab/Constants.java b/integration-tests-cucumber/src/test/java/dlab/Constants.java
new file mode 100644
index 0000000..4e30e99
--- /dev/null
+++ b/integration-tests-cucumber/src/test/java/dlab/Constants.java
@@ -0,0 +1,5 @@
+package dlab;
+
+public interface Constants {
+ String API_URI = "https://localhost:8443/api/";
+}
diff --git a/integration-tests-cucumber/src/test/java/dlab/RunCucumberTest.java b/integration-tests-cucumber/src/test/java/dlab/RunCucumberTest.java
new file mode 100644
index 0000000..fdc8a4c
--- /dev/null
+++ b/integration-tests-cucumber/src/test/java/dlab/RunCucumberTest.java
@@ -0,0 +1,10 @@
+package dlab;
+
+import cucumber.api.CucumberOptions;
+import cucumber.api.junit.Cucumber;
+import org.junit.runner.RunWith;
+
+@RunWith(Cucumber.class)
+@CucumberOptions(plugin = {"json:target/cucumber.json"})
+public class RunCucumberTest {
+}
diff --git a/integration-tests-cucumber/src/test/java/dlab/endpoint/EndpointSteps.java b/integration-tests-cucumber/src/test/java/dlab/endpoint/EndpointSteps.java
new file mode 100644
index 0000000..e66fc33
--- /dev/null
+++ b/integration-tests-cucumber/src/test/java/dlab/endpoint/EndpointSteps.java
@@ -0,0 +1,97 @@
+package dlab.endpoint;
+
+import com.jayway.restassured.http.ContentType;
+import com.jayway.restassured.response.Response;
+import com.jayway.restassured.specification.RequestSpecification;
+import cucumber.api.java.en.And;
+import cucumber.api.java.en.Given;
+import cucumber.api.java.en.Then;
+import cucumber.api.java.en.When;
+import org.apache.dlab.dto.EndpointDTO;
+import org.apache.dlab.mongo.MongoDBHelper;
+import org.apache.dlab.util.JacksonMapper;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import static com.jayway.restassured.RestAssured.given;
+import static dlab.Constants.API_URI;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsEqual.equalTo;
+
+public class EndpointSteps {
+ private RequestSpecification request;
+ private Response response;
+ private String name;
+
+ @Given("User try to create new endpoint with name {string} and uri {string} and account {string} and {string}")
+ public void userTryToCreateNewEndpoint(String name, String uri, String account, String tag) {
+ this.name = name;
+ request = given().body(JacksonMapper.marshall(new EndpointDTO(name, uri, account, tag)))
+ .auth()
+ .oauth2("token123")
+ .contentType(ContentType.JSON);
+
+ }
+
+ @When("User send create new endpoint request")
+ public void userSendCreateNewEndpoint() {
+ response = request.post(API_URI + "endpoint");
+ }
+
+ @Given("There is no endpoints in DLab")
+ public void thereIsNoEndpointsInDLab() {
+ MongoDBHelper.cleanCollection("endpoints");
+
+ }
+
+ @Then("Response status code is {int}")
+ public void responseStatusCodeIs(int code) {
+ assertThat(response.getStatusCode(), equalTo(code));
+ }
+
+ @And("Endpoint URI is present in location header")
+ public void endpointURIIsPresentInLocationHeader() {
+ assertThat(response.getHeader("Location"), equalTo(API_URI + "endpoint/" + name));
+ }
+
+ @When("User try to get information about endpoint with name {string}")
+ public void userTryToGetInformationAboutEndpointWithName(String endpoint) throws URISyntaxException {
+ response = authenticatedRequest()
+ .get(new URI(API_URI + "endpoint/" + endpoint));
+
+ }
+
+ @And("Endpoint information is successfully returned with " +
+ "name {string}, uri {string}, account {string}, and tag {string}")
+ public void endpointInformationIsSuccessfullyReturnedWithNameUriAccountAndTag(String name, String uri,
+ String account, String tag) {
+ final EndpointDTO dto = response.getBody().as(EndpointDTO.class);
+ assertThat(dto.getAccount(), equalTo(account));
+ assertThat(dto.getName(), equalTo(name));
+ assertThat(dto.getUrl(), equalTo(uri));
+ assertThat(dto.getTag(), equalTo(tag));
+
+ }
+
+ @When("User try to get information about endpoints")
+ public void userTryToGetInformationAboutEndpoints() throws URISyntaxException {
+ response = authenticatedRequest()
+ .get(new URI(API_URI + "endpoint"));
+
+ }
+
+ @And("There are endpoints with name test1 and test2")
+ public void thereAreEndpointsWithNameTestAndTest() {
+ final EndpointDTO[] endpoints = response.getBody().as(EndpointDTO[].class);
+ assertThat(2, equalTo(endpoints.length));
+ assertThat("test1", equalTo(endpoints[0].getName()));
+ assertThat("test2", equalTo(endpoints[1].getName()));
+ }
+
+ private RequestSpecification authenticatedRequest() {
+ return given()
+ .auth()
+ .oauth2("token123");
+ }
+}
diff --git a/integration-tests-cucumber/src/test/java/dlab/login/LoginSteps.java b/integration-tests-cucumber/src/test/java/dlab/login/LoginSteps.java
new file mode 100644
index 0000000..32b29cb
--- /dev/null
+++ b/integration-tests-cucumber/src/test/java/dlab/login/LoginSteps.java
@@ -0,0 +1,44 @@
+package dlab.login;
+
+import com.jayway.restassured.http.ContentType;
+import com.jayway.restassured.response.Response;
+import com.jayway.restassured.specification.RequestSpecification;
+import cucumber.api.java.en.Given;
+import cucumber.api.java.en.Then;
+import cucumber.api.java.en.When;
+import gherkin.deps.com.google.gson.JsonObject;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import static com.jayway.restassured.RestAssured.given;
+import static dlab.Constants.API_URI;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
+public class LoginSteps {
+
+
+ private static final String LOGIN_RESOURCE_PATH = API_URI + "user/login";
+ private RequestSpecification request;
+ private Response response;
+
+ @Given("User try to login to Dlab with {string} and {string}")
+ public void userProvidedLoginAndPassword(String username, String password) {
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.addProperty("username", username);
+ jsonObject.addProperty("password", password);
+ request = given().body(jsonObject.toString()).contentType(ContentType.JSON);
+ }
+
+ @When("user try to login")
+ public void userTryToLogin() throws URISyntaxException {
+ response = request.post(new URI(LOGIN_RESOURCE_PATH));
+ }
+
+ @Then("response code is {string}")
+ public void responseCodeIs(String status) {
+ assertThat(response.getStatusCode(), equalTo(Integer.valueOf(status)));
+
+ }
+}
diff --git a/integration-tests-cucumber/src/test/resources/config.properties b/integration-tests-cucumber/src/test/resources/config.properties
new file mode 100644
index 0000000..5cfad3c
--- /dev/null
+++ b/integration-tests-cucumber/src/test/resources/config.properties
@@ -0,0 +1,2 @@
+mongo.connection.string=mongodb://localhost:27017/DLAB
+mongo.db.name=DLAB
\ No newline at end of file
diff --git a/integration-tests-cucumber/src/test/resources/dlab/endpoint.feature b/integration-tests-cucumber/src/test/resources/dlab/endpoint.feature
new file mode 100644
index 0000000..7281a24
--- /dev/null
+++ b/integration-tests-cucumber/src/test/resources/dlab/endpoint.feature
@@ -0,0 +1,57 @@
+Feature: Endpoint management in DLab
+ Such feature allowed to manage endpoint inside DLab
+
+ Scenario Outline: Create new endpoint when it does not exist
+
+ Given There is no endpoints in DLab
+ And User try to create new endpoint with name "<name>" and uri "<uri>" and account "<account>" and "<tag>"
+ When User send create new endpoint request
+ Then Response status code is 200
+ And Endpoint URI is present in location header
+ Examples:
+ | name | uri | account | tag |
+ | test_endpoint | someuri | 123231312 | some_tag |
+
+
+ Scenario Outline: Create new endpoint when it exist already
+
+ Given There is no endpoints in DLab
+ And User try to create new endpoint with name "<name>" and uri "<uri>" and account "<account>" and "<tag>"
+ And User send create new endpoint request
+ When User try to create new endpoint with name "<name>" and uri "<uri>" and account "<account>" and "<tag>"
+ And User send create new endpoint request
+ Then Response status code is 409
+ Examples:
+ | name | uri | account | tag |
+ | test_endpoint | someuri | 123231312 | some_tag |
+
+
+ Scenario Outline: Get information for endpoint
+
+ Given There is no endpoints in DLab
+ And User try to create new endpoint with name "<name>" and uri "<uri>" and account "<account>" and "<tag>"
+ And User send create new endpoint request
+ When User try to get information about endpoint with name "<name>"
+ Then Response status code is 200
+ And Endpoint information is successfully returned with name "<name>", uri "<uri>", account "<account>", and tag "<tag>"
+ Examples:
+ | name | uri | account | tag |
+ | test_endpoint | someuri | 123231312 | some_tag |
+
+
+ Scenario: Get list of endpoints
+
+ Given There is no endpoints in DLab
+ And User try to create new endpoint with name "test1" and uri "someuri1" and account "123" and "customTag1"
+ And User send create new endpoint request
+ And User try to create new endpoint with name "test2" and uri "someuri2" and account "1233" and "customTag4"
+ And User send create new endpoint request
+ When User try to get information about endpoints
+ Then Response status code is 200
+ And There are endpoints with name test1 and test2
+
+ Scenario: Get not endpoint that does not exist
+
+ Given There is no endpoints in DLab
+ When User try to get information about endpoint with name "someName"
+ Then Response status code is 404
diff --git a/integration-tests-cucumber/src/test/resources/dlab/login.feature b/integration-tests-cucumber/src/test/resources/dlab/login.feature
new file mode 100644
index 0000000..493a51e
--- /dev/null
+++ b/integration-tests-cucumber/src/test/resources/dlab/login.feature
@@ -0,0 +1,12 @@
+Feature: DLab login API
+ Used to check DLab login flow
+
+ Scenario Outline: User try to login to DLab
+ Given User try to login to Dlab with "<username>" and "<password>"
+ When user try to login
+ Then response code is "<status>"
+
+ Examples:
+ | username | password | status |
+ | test | pass | 200 |
+ | not_valid_user | pass | 401 |
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org