This is an automated email from the ASF dual-hosted git repository. ofuks pushed a commit to branch DLAB-1300 in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git
The following commit(s) were added to refs/heads/DLAB-1300 by this push: new 7bfd05a [DLAB-1263] Fixed issue with starting notebook when project quota is depleted new 0589b4c Merge remote-tracking branch 'origin/DLAB-1300' into DLAB-1300 7bfd05a is described below commit 7bfd05a74d04bf3ff5bd9b24c8cbf050c5a10ac7 Author: Oleh Fuks <olegfuk...@gmail.com> AuthorDate: Fri Nov 22 16:36:18 2019 +0200 [DLAB-1263] Fixed issue with starting notebook when project quota is depleted --- .../backendapi/resources/ExploratoryResource.java | 2 +- .../resources/dto/ExploratoryActionFormDTO.java | 29 ++++++++++----------- .../resources/ExploratoryResourceTest.java | 30 +++++++++++++++++++--- 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/ExploratoryResource.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/ExploratoryResource.java index 6fa0b51..9f478c3 100644 --- a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/ExploratoryResource.java +++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/ExploratoryResource.java @@ -94,7 +94,7 @@ public class ExploratoryResource implements ExploratoryAPI { @Valid @NotNull ExploratoryActionFormDTO formDTO) { log.debug("Starting exploratory environment {} for user {}", formDTO.getNotebookInstanceName(), userInfo.getName()); - return exploratoryService.start(userInfo, formDTO.getNotebookInstanceName(), ""); + return exploratoryService.start(userInfo, formDTO.getNotebookInstanceName(), formDTO.getProjectName()); } /** diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/dto/ExploratoryActionFormDTO.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/dto/ExploratoryActionFormDTO.java index b953be3..d3361df 100644 --- a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/dto/ExploratoryActionFormDTO.java +++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/dto/ExploratoryActionFormDTO.java @@ -19,27 +19,26 @@ package com.epam.dlab.backendapi.resources.dto; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.base.MoreObjects; - +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; import org.hibernate.validator.constraints.NotBlank; -/** Stores info about the action of exploratory notebook. - * */ +/** + * Stores info about action on the exploratory resource. + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) public class ExploratoryActionFormDTO { @NotBlank @JsonProperty("notebook_instance_name") private String notebookInstanceName; - /** Returns the name of notebook instance. */ - public String getNotebookInstanceName() { - return notebookInstanceName; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("notebookInstanceName", notebookInstanceName) - .toString(); - } + @NotBlank + @JsonProperty("project_name") + private String projectName; } diff --git a/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/ExploratoryResourceTest.java b/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/ExploratoryResourceTest.java index 0999019..cc3a16a 100644 --- a/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/ExploratoryResourceTest.java +++ b/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/ExploratoryResourceTest.java @@ -103,12 +103,32 @@ public class ExploratoryResourceTest extends TestBase { @Test public void start() { + ExploratoryActionFormDTO exploratoryDTO = getExploratoryActionFormDTO(); when(exploratoryService.start(any(UserInfo.class), anyString(), anyString())).thenReturn("someUuid"); final Response response = resources.getJerseyTest() .target("/infrastructure_provision/exploratory_environment") .request() .header("Authorization", "Bearer " + TOKEN) - .post(Entity.json(getExploratoryActionFormDTO())); + .post(Entity.json(exploratoryDTO)); + + assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals("someUuid", response.readEntity(String.class)); + assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE)); + + verify(exploratoryService).start(getUserInfo(), exploratoryDTO.getNotebookInstanceName(), + exploratoryDTO.getProjectName()); + + verifyZeroInteractions(exploratoryService); + } + + @Test + public void startUnprocessableEntity() { + when(exploratoryService.start(any(UserInfo.class), anyString(), anyString())).thenReturn("someUuid"); + final Response response = resources.getJerseyTest() + .target("/infrastructure_provision/exploratory_environment") + .request() + .header("Authorization", "Bearer " + TOKEN) + .post(Entity.json(getEmptyExploratoryActionFormDTO())); assertEquals(HttpStatus.SC_UNPROCESSABLE_ENTITY, response.getStatus()); assertEquals("{\"errors\":[\"notebookInstanceName may not be empty\"]}", response.readEntity(String.class)); @@ -125,7 +145,7 @@ public class ExploratoryResourceTest extends TestBase { .target("/infrastructure_provision/exploratory_environment") .request() .header("Authorization", "Bearer " + TOKEN) - .post(Entity.json(getExploratoryActionFormDTO())); + .post(Entity.json(getEmptyExploratoryActionFormDTO())); assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatus()); assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE)); @@ -294,10 +314,14 @@ public class ExploratoryResourceTest extends TestBase { return ecfDto; } - private ExploratoryActionFormDTO getExploratoryActionFormDTO() { + private ExploratoryActionFormDTO getEmptyExploratoryActionFormDTO() { return new ExploratoryActionFormDTO(); } + private ExploratoryActionFormDTO getExploratoryActionFormDTO() { + return new ExploratoryActionFormDTO("notebook_instance_name", "project_name"); + } + private Exploratory getExploratory(@Valid @NotNull ExploratoryCreateFormDTO formDTO) { return Exploratory.builder() .name(formDTO.getName()) --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@dlab.apache.org For additional commands, e-mail: commits-h...@dlab.apache.org