This is an automated email from the ASF dual-hosted git repository. ofuks pushed a commit to branch integration-tests-ofuks-1 in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git
commit 006ad749a0e3b2387d97f33ca02afff2ea69315e Author: Oleh Fuks <olegfuk...@gmail.com> AuthorDate: Thu Dec 12 12:03:36 2019 +0200 Added project feature --- .../java/org/apache/dlab/dto/CreateProjectDTO.java | 19 ++++ .../org/apache/dlab/dto/EndpointStatusDTO.java | 23 +++++ .../java/org/apache/dlab/dto/ProjectKeyDTO.java | 15 +++ .../java/org/apache/dlab/dto/ProjectStatusDTO.java | 13 +++ .../src/test/java/dlab/Constants.java | 1 + .../src/test/java/dlab/project/ProjectSteps.java | 104 ++++++++++++++++++--- .../src/test/resources/dlab/project.feature | 9 +- 7 files changed, 169 insertions(+), 15 deletions(-) diff --git a/integration-tests-cucumber/src/main/java/org/apache/dlab/dto/CreateProjectDTO.java b/integration-tests-cucumber/src/main/java/org/apache/dlab/dto/CreateProjectDTO.java new file mode 100644 index 0000000..9d22144 --- /dev/null +++ b/integration-tests-cucumber/src/main/java/org/apache/dlab/dto/CreateProjectDTO.java @@ -0,0 +1,19 @@ +package org.apache.dlab.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Set; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class CreateProjectDTO { + private String name; + private Set<String> groups; + private Set<String> endpoints; + private String key; + private String tag; +} + diff --git a/integration-tests-cucumber/src/main/java/org/apache/dlab/dto/EndpointStatusDTO.java b/integration-tests-cucumber/src/main/java/org/apache/dlab/dto/EndpointStatusDTO.java new file mode 100644 index 0000000..86eafdd --- /dev/null +++ b/integration-tests-cucumber/src/main/java/org/apache/dlab/dto/EndpointStatusDTO.java @@ -0,0 +1,23 @@ +package org.apache.dlab.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; + + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class EndpointStatusDTO { + private String name; + private Status status; + + + public enum Status { + CREATING, + STARTING, + RUNNING, + STOPPING, + STOPPED, + TERMINATING, + TERMINATED + } +} diff --git a/integration-tests-cucumber/src/main/java/org/apache/dlab/dto/ProjectKeyDTO.java b/integration-tests-cucumber/src/main/java/org/apache/dlab/dto/ProjectKeyDTO.java new file mode 100644 index 0000000..faf64ca --- /dev/null +++ b/integration-tests-cucumber/src/main/java/org/apache/dlab/dto/ProjectKeyDTO.java @@ -0,0 +1,15 @@ +package org.apache.dlab.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +@AllArgsConstructor +@NoArgsConstructor +public class ProjectKeyDTO { + private String publicKey; + private String username; +} diff --git a/integration-tests-cucumber/src/main/java/org/apache/dlab/dto/ProjectStatusDTO.java b/integration-tests-cucumber/src/main/java/org/apache/dlab/dto/ProjectStatusDTO.java new file mode 100644 index 0000000..efa5b28 --- /dev/null +++ b/integration-tests-cucumber/src/main/java/org/apache/dlab/dto/ProjectStatusDTO.java @@ -0,0 +1,13 @@ +package org.apache.dlab.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; + +import java.util.Set; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class ProjectStatusDTO { + private String name; + private Set<EndpointStatusDTO> endpoints; +} diff --git a/integration-tests-cucumber/src/test/java/dlab/Constants.java b/integration-tests-cucumber/src/test/java/dlab/Constants.java index a27ed77..19309ba 100644 --- a/integration-tests-cucumber/src/test/java/dlab/Constants.java +++ b/integration-tests-cucumber/src/test/java/dlab/Constants.java @@ -4,4 +4,5 @@ import org.apache.dlab.util.PropertyHelper; public interface Constants { String API_URI = PropertyHelper.read("dlab.api.base.uri"); + String LOCAL_ENDPOINT = "local"; } diff --git a/integration-tests-cucumber/src/test/java/dlab/project/ProjectSteps.java b/integration-tests-cucumber/src/test/java/dlab/project/ProjectSteps.java index ed1b207..7a34abf 100644 --- a/integration-tests-cucumber/src/test/java/dlab/project/ProjectSteps.java +++ b/integration-tests-cucumber/src/test/java/dlab/project/ProjectSteps.java @@ -1,35 +1,117 @@ package dlab.project; + +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 dlab.util.KeycloakUtil; +import org.apache.dlab.dto.CreateProjectDTO; +import org.apache.dlab.dto.EndpointStatusDTO; +import org.apache.dlab.dto.ProjectKeyDTO; +import org.apache.dlab.dto.ProjectStatusDTO; +import org.apache.dlab.util.JacksonMapper; + +import java.net.URI; +import java.net.URISyntaxException; +import java.time.LocalDateTime; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import static com.jayway.restassured.RestAssured.given; +import static dlab.Constants.API_URI; +import static dlab.Constants.LOCAL_ENDPOINT; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsEqual.equalTo; import static org.junit.Assert.fail; public class ProjectSteps { - @Then("User wait maximum {string} minutes while project is creating") - public void userWaitMaximumMinutesWhileProjectIsCreating(String arg0) { - fail("Not implemented"); + private RequestSpecification createProjectRequest; + private RequestSpecification generateKeysRequest; + private Response response; + private String projectName; + + + @Given("There is no project with name {string} in DLab") + public void thereIsNoProjectWithNameInDLab(String projectName) throws URISyntaxException { + assertThat(authenticatedRequest() + .get(new URI(API_URI + "project/" + projectName)) + .getStatusCode(), equalTo(404)); } @When("User send create new project request") public void userSendCreateNewProjectRequest() { + response = createProjectRequest.post(API_URI + "project"); } - @And("User try to create new project with name {string}, endpoints {string}, groups {string} " + - "and key {string}") - public void userTryToCreateNewProjectWithNameEndpointsGroupsAndKey(String arg0, String arg1, String arg2, - String arg3) { - } + @And("User try to create new project with name {string}, endpoints {string}, groups {string} and publicKey") + public void userTryToCreateNewProjectWithNameEndpointsGroupsAndKey(String projectName, String endpoints, + String groups) { + this.projectName = projectName; + String publicKey = generateKeysRequest.post(API_URI + "project/keys") + .getBody().as(ProjectKeyDTO.class) + .getPublicKey(); + Set<String> endpointSet = getSetFromString(endpoints); + Set<String> groupSet = getSetFromString(groups); + + createProjectRequest = given() + .body(JacksonMapper.marshall(new CreateProjectDTO(projectName, groupSet, endpointSet, publicKey, projectName))) + .auth() + .oauth2(KeycloakUtil.getToken()) + .contentType(ContentType.JSON); - @Given("There is no project with name {string} in DLab") - public void thereIsNoProjectWithNameInDLab(String arg0) { } @Then("Status code is {int}") - public void statusCodeIs(int arg0) { + public void statusCodeIs(int code) { + assertThat(response.getStatusCode(), equalTo(code)); + } + + @Then("User wait maximum {int} minutes while project is creating") + public void userWaitMaximumMinutesWhileProjectIsCreating(int timeout) throws URISyntaxException, InterruptedException { + boolean isRunning = false; + LocalDateTime withTimeout = LocalDateTime.now().plusMinutes(timeout); + while (!isRunning && LocalDateTime.now().isBefore(withTimeout)) { + ProjectStatusDTO projectDTO = authenticatedRequest() + .get(new URI(API_URI + "project/" + projectName)) + .getBody().as(ProjectStatusDTO.class); + + assertThat(projectDTO.getName(), equalTo(projectName)); + + Optional<EndpointStatusDTO> localEndpoint = projectDTO.getEndpoints() + .stream() + .filter(e -> LOCAL_ENDPOINT.equals(e.getName())) + .findAny(); + isRunning = localEndpoint.isPresent() && EndpointStatusDTO.Status.RUNNING == localEndpoint.get().getStatus(); + TimeUnit.MINUTES.sleep(1); + } + + if (!isRunning) { + fail("Timeout for project status check reached!"); + } + } + + @And("User try to generate new publicKey") + public void userTryToGenerateNewPublicKey() { + generateKeysRequest = given().auth() + .oauth2(KeycloakUtil.getToken()) + .contentType(ContentType.JSON); + } + + private HashSet<String> getSetFromString(String string) { + return new HashSet<>(Arrays.asList(string.split(","))); + } + private RequestSpecification authenticatedRequest() { + return given() + .auth() + .oauth2(KeycloakUtil.getToken()); } } diff --git a/integration-tests-cucumber/src/test/resources/dlab/project.feature b/integration-tests-cucumber/src/test/resources/dlab/project.feature index e717e63..2da19fa 100644 --- a/integration-tests-cucumber/src/test/resources/dlab/project.feature +++ b/integration-tests-cucumber/src/test/resources/dlab/project.feature @@ -4,10 +4,11 @@ Feature: Project management in DLab Scenario Outline: Create new project when it does not exist Given There is no project with name "<name>" in DLab - And User try to create new project with name "<name>", endpoints "<endpoints>", groups "<groups>" and key "<key>" + And User try to generate new publicKey + And User try to create new project with name "<name>", endpoints "<endpoints>", groups "<groups>" and publicKey When User send create new project request - Then User wait maximum "<timeout>" minutes while project is creating + Then User wait maximum <timeout> minutes while project is creating Then Status code is 200 Examples: - | name | endpoints | groups | key | timeout | - | prj1 | test | $anyyser | publicKeyContent | 10 | \ No newline at end of file + | name | endpoints | groups | timeout | + | prj1 | local | $anyuser | 20 | \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@dlab.apache.org For additional commands, e-mail: commits-h...@dlab.apache.org