PreparationController { @RequestMapping(value = "/preparations/{id}", method = GET) @ApiOperation(value = "Get preparation", notes = "Return the preparation with provided id.") @Timed public PreparationDTO get(@ApiParam("id") @PathVariable("id") String id) { return preparationService.getPreparation(id); }  @RequestMapping(value = "/preparations", method = POST) @ApiOperation(value = "Create a preparation", notes = "Returns the id of the created preparation.") @Timed String create(@ApiParam("preparation") @RequestBody @Valid final Preparation preparation,
            @ApiParam(value = "The folderId path to create the entry.") @RequestParam String folderId); @RequestMapping(value = "/preparations", method = GET) @ApiOperation(value = "List all preparations id", notes = "Returns the list of preparations ids the current user is allowed to see. Creation date is always displayed in UTC time zone. See 'preparations/all' to get all details at once.") @Timed Stream<String> list(
            @ApiParam(name = "name",
                    value = "Filter preparations by name.") @RequestParam(required = false) String name,
            @ApiParam(name = "folder_path", value = "Filter preparations by folder path.") @RequestParam(
                    required = false, name = "folder_path") String folderPath,
            @ApiParam(name = "path",
                    value = "Filter preparations by full path (<folder path>/<preparation name>).") @RequestParam(
                            required = false, name = "path") String path,
            @ApiParam(value = "Sort key (by name or date).") @RequestParam(
                    defaultValue = "lastModificationDate") Sort sort,
            @ApiParam(value = "Order for sort key (desc or asc).") @RequestParam(defaultValue = "desc") Order order); @RequestMapping(value = "/preparations/details", method = GET) @ApiOperation(value = "List all preparations", notes = "Returns the list of preparations details the current user is allowed to see. Creation date is always displayed in UTC time zone. This operation return all details on the preparations.") @Timed Stream<PreparationDTO> listAll(
            @ApiParam(name = "name",
                    value = "Filter preparations by name.") @RequestParam(required = false) String name,
            @ApiParam(name = "folder_path", value = "Filter preparations by folder path.") @RequestParam(
                    required = false, name = "folder_path") String folderPath,
            @ApiParam(name = "path",
                    value = "Filter preparations by full path (<folder path>/<preparation name>).") @RequestParam(
                            required = false, name = "path") String path,
            @ApiParam(value = "Sort key (by name or date).") @RequestParam(
                    defaultValue = "lastModificationDate") Sort sort,
            @ApiParam(value = "Order for sort key (desc or asc).") @RequestParam(defaultValue = "desc") Order order); @RequestMapping(value = "/preparations/summaries", method = GET) @ApiOperation(value = "List all preparations", notes = "Returns the list of preparations summaries the current user is allowed to see. Creation date is always displayed in UTC time zone.") @Timed Stream<PreparationDTO> listSummary(
            @ApiParam(name = "name",
                    value = "Filter preparations by name.") @RequestParam(required = false) String name,
            @ApiParam(name = "folder_path", value = "Filter preparations by folder path.") @RequestParam(
                    required = false, name = "folder_path") String folderPath,
            @ApiParam(name = "path",
                    value = "Filter preparations by full path (<folder path>/<preparation name>).") @RequestParam(
                            required = false, name = "path") String path,
            @ApiParam(value = "Sort key (by name or date).") @RequestParam(
                    defaultValue = "lastModificationDate") Sort sort,
            @ApiParam(value = "Order for sort key (desc or asc).") @RequestParam(defaultValue = "desc") Order order); @RequestMapping(value = "/preparations/search", method = GET) @ApiOperation(value = "Search for preparations details", notes = "Returns the list of preparations details that match the search criteria.") @Timed Stream<PreparationDTO> searchPreparations(
            @RequestParam(required = false) @ApiParam("dataSetId") String dataSetId,
            @RequestParam(required = false) @ApiParam(
                    value = "Id of the folder where to look for preparations") String folderId,
            @RequestParam(required = false) @ApiParam(
                    value = "Path of the folder where to look for preparations") String folderPath,
            @RequestParam(required = false) @ApiParam("name") String name,
            @RequestParam(defaultValue = "true") @ApiParam("exactMatch") boolean exactMatch,
            @RequestParam(defaultValue = "lastModificationDate") @ApiParam(
                    value = "Sort key (by name or date).") Sort sort,
            @RequestParam(defaultValue = "desc") @ApiParam(value = "Order for sort key (desc or asc).") Order order); @RequestMapping(value = "/preparations/{id}/copy", method = POST, produces = TEXT_PLAIN_VALUE) @ApiOperation(value = "Copy a preparation", produces = TEXT_PLAIN_VALUE, notes = "Copy the preparation to the new name / folder and returns the new id.") @Timed String copy(
            @PathVariable(value = "id") @ApiParam(name = "id",
                    value = "Id of the preparation to copy") String preparationId,
            @ApiParam(value = "The name of the copied preparation.") @RequestParam(required = false) String name,
            @ApiParam(value = "The folder path to create the copy.") @RequestParam() String destination); @RequestMapping(value = "/preparations/{id}/move", method = PUT) @ApiOperation(value = "Move a preparation", notes = "Move a preparation to an other folder.") @Timed void move(
            @PathVariable(value = "id") @ApiParam(name = "id",
                    value = "Id of the preparation to move") String preparationId,
            @ApiParam(value = "The original folder path of the preparation.") @RequestParam String folder,
            @ApiParam(value = "The new folder path of the preparation.") @RequestParam String destination,
            @ApiParam(value = "The new name of the moved dataset.") @RequestParam(defaultValue = "") String newName); @RequestMapping(value = "/preparations/{id}", method = RequestMethod.DELETE) @ApiOperation(value = "Delete a preparation by id", notes = "Delete a preparation content based on provided id. Id should be a UUID returned by the list operation. Not valid or non existing preparation id returns empty content.") @Timed void delete(
            @PathVariable(value = "id") @ApiParam(name = "id", value = "Id of the preparation to delete") String id); @RequestMapping(value = "/preparations/{id}", method = PUT) @ApiOperation(value = "Create a preparation", notes = "Returns the id of the updated preparation.") @Timed String update(@ApiParam("id") @PathVariable("id") String id,
            @RequestBody @ApiParam("preparation") final PreparationDTO preparation); @RequestMapping(value = "/preparations/steps/{stepId}/metadata", method = PUT, produces = TEXT_PLAIN_VALUE, consumes = APPLICATION_JSON_VALUE) @ApiOperation(value = "Update a preparation steps", notes = "Returns the id of the updated step.") @Timed String updateStepMetadata(@ApiParam("stepId") @PathVariable("stepId") String stepId,
            @RequestBody @ApiParam("rowMetadata") final RowMetadata rowMetadata); @RequestMapping(value = "/preparations/steps/{stepId}/metadata", method = DELETE) @ApiOperation(value = "Deletes the metadata associated with step") @Timed void invalidateStepMetadata(@ApiParam("stepId") @PathVariable("stepId") String stepId); @RequestMapping(value = "/preparations/steps/{stepId}/metadata", method = GET, produces = APPLICATION_JSON_VALUE) @ApiOperation(value = "Update a preparation steps", notes = "Returns the id of the updated step.") @Timed RowMetadata getStepMetadata(@ApiParam("stepId") @PathVariable("stepId") String stepId); @RequestMapping(value = "/preparations/{id}/steps/copy", method = PUT) @ApiOperation(value = "Copy the steps from another preparation", notes = "Copy the steps from another preparation if this one has no steps.") @Timed void copyStepsFrom(@ApiParam(value = "the preparation id to update") @PathVariable("id") String id,
            @ApiParam(value = "the preparation to copy the steps from.") @RequestParam String from); @RequestMapping(value = "/preparations/{id}/details", method = GET) @ApiOperation(value = "Get preparation details", notes = "Return the details of the preparation with provided id.") @Timed PreparationDTO getDetails( //
            @ApiParam("id") @PathVariable("id") String id, //
            @ApiParam(value = "stepId", defaultValue = "head") @RequestParam(value = "stepId",
                    defaultValue = "head") String stepId); @RequestMapping(value = "/preparations/{id}/details/full", method = GET) @ApiOperation(value = "Get preparation details", notes = "Return the details of the preparation with provided id.") @Timed PreparationDetailsDTO getDetailsFull( //
            @ApiParam("id") @PathVariable("id") String id, //
            @ApiParam(value = "stepId", defaultValue = "head") @RequestParam(value = "stepId",
                    defaultValue = "head") String stepId); @RequestMapping(value = "/preparations/{id}", method = GET) @ApiOperation(value = "Get preparation", notes = "Return the preparation with provided id.") @Timed PreparationDTO get(@ApiParam("id") @PathVariable("id") String id); @RequestMapping(value = "/preparations/{id}/folder", method = GET) @ApiOperation(value = "Get preparation details", notes = "Return the details of the preparation with provided id.") @Timed Folder searchLocation(@ApiParam(value = "the preparation id") @PathVariable("id") String id); @RequestMapping(value = "/preparations/{id}/steps", method = GET) @ApiOperation(value = "Get all preparation steps id", notes = "Return the steps of the preparation with provided id.") @Timed List<String> getSteps(@ApiParam("id") @PathVariable("id") String id); @RequestMapping(value = "/preparations/{id}/actions/{stepId}", method = PUT) @ApiOperation(value = "Updates an action in a preparation", notes = "Modifies an action in preparation's steps.") @Timed void updateAction(@PathVariable("id") final String preparationId,
            @PathVariable("stepId") final String stepToModifyId, @RequestBody final AppendStep newStep); @RequestMapping(value = "/preparations/{id}/actions/{stepId}", method = DELETE) @ApiOperation(value = "Delete an action in a preparation", notes = "Delete a step and all following steps from a preparation") @Timed void deleteAction(@PathVariable("id") final String id, @PathVariable("stepId") final String stepToDeleteId); @RequestMapping(value = "/preparations/{id}/head/{headId}", method = PUT) @ApiOperation(value = "Move preparation head", notes = "Set head to the specified head id") @Timed void setPreparationHead(@PathVariable("id") final String preparationId, //
            @PathVariable("headId") final String headId); @RequestMapping(value = "/preparations/{id}/actions/{version}", method = GET) @ApiOperation(value = "Get all the actions of a preparation at given version.", notes = "Returns the action JSON at version.") @Timed List<Action> getVersionedAction(@ApiParam("id") @PathVariable("id") final String id,
            @ApiParam("version") @PathVariable("version") final String version); @RequestMapping(value = "/preparations/errors", method = RequestMethod.GET) @ApiOperation(value = "Get all preparation related error codes.", notes = "Returns the list of all preparation related error codes.") @Timed Iterable<JsonErrorCodeDescription> listErrors(); @RequestMapping(value = "/preparations/{preparationId}/lock", method = PUT) @ApiOperation(value = "Lock the specified preparation.", notes = "Returns a locked resource.") @Timed void lockPreparation(@ApiParam("preparationId") @PathVariable("preparationId") final String preparationId); @RequestMapping(value = "/preparations/{preparationId}/unlock", method = PUT) @ApiOperation(value = "Unlock the specified preparation.", notes = "Returns a locked resource.") @Timed void unlockPreparation(@ApiParam("preparationId") @PathVariable("preparationId") final String preparationId); @RequestMapping(value = "/preparations/use/dataset/{datasetId}", method = HEAD) @ApiOperation(value = "Check if dataset is used by a preparation.", notes = "Returns no content, the response code is the meaning.") @Timed ResponseEntity<Void> preparationsThatUseDataset(@ApiParam("datasetId") @PathVariable("datasetId") final String datasetId); @RequestMapping(value = "/preparations/{id}/steps/{stepId}/order", method = POST) @ApiOperation(value = "Moves a step within a preparation after a specified step", notes = "Moves a step within a preparation after a specified step.") @Timed void moveStep(@PathVariable("id") final String preparationId,
            @ApiParam(value = "The id of the step we want to move.") @PathVariable String stepId,
            @ApiParam(value = "The step that will become the parent of stepId") @RequestParam String parentStepId); @RequestMapping(value = "/preparations/{id}/actions", method = POST) @ApiOperation(value = "Adds an action at the end of preparation.", notes = "Does not return any value, client may expect successful operation based on HTTP status code.") @Timed void addPreparationAction(
            @ApiParam(name = "id", value = "Preparation id.") @PathVariable(value = "id") final String preparationId,
            @ApiParam("Action to add at end of the preparation.") @RequestBody final List<AppendStep> steps); @RequestMapping(value = "/steps/{id}", method = GET) @ApiOperation(value = "Retrieve a specific step.", notes = "Just find the step for this ID.") @Timed Step getStep(@PathVariable("id") final String stepId);  }
@Test public void CORSHeaders() throws Exception { given().header("Origin", "fake.host.to.trigger.cors").when().get("/preparations").then().header( "Access-Control-Allow-Origin", "fake.host.to.trigger.cors"); }
@Test public void shouldListAllPreparations() throws Exception { when().get("/preparations/details").then().statusCode(HttpStatus.OK.value()).body(sameJSONAs("[]")); final Preparation preparation = new Preparation("#548425458", "1234", Step.ROOT_STEP.id(), versionService.version().getVersionId()); preparation.setCreationDate(0); preparation.setLastModificationDate(12345); repository.add(preparation); final Response response = when().get("/preparations/details"); response.then().statusCode(HttpStatus.OK.value()).body( sameJSONAs("[{\"id\":\"#548425458\"," + "\"dataSetId\":\"1234\"," + "\"creationDate\":0," + "\"lastModificationDate\":12345}]").allowingExtraUnexpectedFields()); final Preparation preparation1 = new Preparation("#1438725", "5678", Step.ROOT_STEP.id(), versionService.version().getVersionId()); preparation1.setCreationDate(500); preparation1.setLastModificationDate(456789); repository.add(preparation1); final Response responseMultiple = when().get("/preparations/details"); responseMultiple.then() .statusCode(HttpStatus.OK.value()) .body(sameJSONAs( "[" + "{\"id\":\"#548425458\"," + "\"dataSetId\":\"1234\"," + "\"creationDate\":0," + "\"lastModificationDate\":12345" + "}," + "{\"id\":\"#1438725\"," + "\"dataSetId\":\"5678\"," + "\"creationDate\":500," + "\"lastModificationDate\":456789" + "}" + "]") .allowingExtraUnexpectedFields() .allowingAnyArrayOrdering()); }
@Test public void listPreparationsShouldBeOrderedByLastModificationDate() throws Exception { when().get("/preparations/details").then().statusCode(HttpStatus.OK.value()).body(sameJSONAs("[]")); List<String> preparationIds = new ArrayList<>(5); for (int i = 0; i < 5; i++) { final long now = new Date().getTime(); Preparation preparation = new Preparation(UUID.randomUUID().toString(), "12345", Step.ROOT_STEP.id(), versionService.version().getVersionId()); preparation.setName("prep-" + i); preparation.setLastModificationDate(now); repository.add(preparation); preparationIds.add(0, preparation.id()); Thread.sleep(100); } final InputStream responseContent = when().get("/preparations/details").asInputStream(); final List<Preparation> actual = mapper.readValue(responseContent, new TypeReference<List<Preparation>>() { }); assertEquals(preparationIds.size(), actual.size()); for (int i = 0; i < actual.size(); i++) { assertEquals(preparationIds.get(i), actual.get(i).getId()); } }
@Test public void shouldCopy() throws Exception { final Folder fromFolder = folderRepository.addFolder(home.getId(), "from"); final Folder toFolder = folderRepository.addFolder(home.getId(), "to"); final String originalId = clientTest.createPreparation(createTestPreparation("test_name", "1234"), fromFolder.getId()).getId(); repository.get(originalId, Preparation.class).setAuthor("tagada"); final Response response = given() .queryParam("name", "the new preparation") .queryParam("destination", toFolder.getId()) .when() .expect() .statusCode(200) .log() .ifError() .post("/preparations/{id}/copy", originalId); final String copyId = response.asString(); assertThat(response.getStatusCode(), is(200)); assertThatPreparationIsFirstInsideFolder(copyId, toFolder.getId()); assertEquals("the new preparation", repository.get(copyId, Preparation.class).getName()); assertEquals(System.getProperty("user.name"), repository.get(copyId, Preparation.class).getAuthor()); assertNotNull(repository.get(copyId, Preparation.class).getRowMetadata()); }
@Test public void shouldCopyWithDefaultParameters() throws Exception { final Folder folder = folderRepository.addFolder(home.getId(), "yet_another_folder"); final String originalId = clientTest.createPreparation(createTestPreparation("prep_1", "1234"), folder.getId()).getId(); final Folder toFolder = folderRepository.addFolder(home.getId(), "to"); final Response response = given() .queryParam("destination", toFolder.getId()) .when() .expect() .statusCode(200) .log() .ifError() .post("/preparations/{id}/copy", originalId); final String copyId = response.asString(); assertThat(response.getStatusCode(), is(200)); final Iterator<FolderEntry> iterator; try (Stream<FolderEntry> folderEntriesStream = folderRepository.entries(toFolder.getId(), PREPARATION)) { iterator = folderEntriesStream.iterator(); boolean found = false; while (iterator.hasNext()) { final FolderEntry entry = iterator.next(); if (entry.getContentId().equals(copyId)) { found = true; assertEquals("prep_1 copy", repository.get(entry.getContentId(), Preparation.class).getName()); } } assertTrue(found); } }
@Test public void shouldMove() throws Exception { final Folder fromFolder = folderRepository.addFolder(home.getId(), "from"); final Folder toFolder = folderRepository.addFolder(home.getId(), "to"); final String originalId = clientTest.createPreparation(createTestPreparation("test_move", "7535"), fromFolder.getId()).getId(); final Response response = given() .queryParam("folder", fromFolder.getId()) .queryParam("destination", toFolder.getId()) .queryParam("newName", "moved preparation") .when() .expect() .statusCode(200) .log() .ifError() .put("/preparations/{id}/move", originalId); assertThat(response.getStatusCode(), is(200)); assertThatPreparationIsFirstInsideFolder(originalId, toFolder.getId()); assertEquals("moved preparation", repository.get(originalId, Preparation.class).getName()); }
@Test public void shouldMoveWithDefaultParameters() throws Exception { final Folder fromFolder = folderRepository.addFolder(home.getId(), "from"); final Folder toFolder = folderRepository.addFolder(home.getId(), "to"); final String originalId = clientTest.createPreparation(createTestPreparation("yap", "7535"), fromFolder.getId()).getId(); final Response response = given() .queryParam("folder", fromFolder.getId()) .queryParam("destination", toFolder.getId()) .when() .expect() .statusCode(200) .log() .ifError() .put("/preparations/{id}/move", originalId); assertThat(response.getStatusCode(), is(200)); assertThatPreparationIsFirstInsideFolder(originalId, toFolder.getId()); assertEquals("yap", repository.get(originalId, Preparation.class).getName()); }
@Test public void shouldReturnListOfSpecificDatasetPreparations() throws Exception { final String wantedDataSetId = "wanted"; final String preparation1 = createPreparation(wantedDataSetId, "prep_1"); final String preparation2 = createPreparation(wantedDataSetId, "prep_2"); final String preparation3 = createPreparation("4523", "prep_3"); final String preparation4 = createPreparation("7534", "prep_4"); final String preparation5 = createPreparation("1598", "prep_5"); final String result = when().get("/preparations/search?dataSetId=" + wantedDataSetId).asString(); final List<String> preparationIds = JsonPath.from(result).get("id"); assertThat(preparationIds, hasItem(preparation1)); assertThat(preparationIds, hasItem(preparation2)); assertThat(preparationIds, not(hasItem(preparation3))); assertThat(preparationIds, not(hasItem(preparation4))); assertThat(preparationIds, not(hasItem(preparation5))); }
@Test public void shouldLocatePreparation() throws Exception { final Folder bar = folderRepository.addFolder(home.getId(), "/foo/bar"); final String barEntry = clientTest.createPreparation(createTestPreparation("youpi", "4824"), bar.getId()).getId(); final Response response = given() .when() .expect() .statusCode(200) .log() .ifError() .get("/preparations/{id}/folder", barEntry); assertThat(response.getStatusCode(), is(200)); try (InputStream responseAsInputStream = response.asInputStream()) { final Folder actual = mapper.readValue(responseAsInputStream, Folder.class); assertEquals(bar.getId(), actual.getId()); } }
@Test public void locateUnknownPreparationShouldSend404() throws Exception { final Response response = given() .when() .expect() .statusCode(404) .log() .ifError() .get("/preparations/{id}/folder", "unknown preparation"); assertThat(response.getStatusCode(), is(404)); }
@Test public void shouldListErrors() throws Exception { final String errors = when().get("/preparations/errors").asString(); final ObjectMapper mapper = new ObjectMapper(); final JsonNode actualErrorCodes = mapper.readTree(errors); assertTrue(actualErrorCodes.isArray()); assertTrue(actualErrorCodes.size() > 0); for (final JsonNode currentCode : actualErrorCodes) { assertTrue(currentCode.has("code")); assertTrue(currentCode.has("http-status-code")); } }
@Test public void shouldNotCopyStepsBecauseReferencePreparationIsNotFound() throws Exception { final String preparationId = createPreparation("154753", "preparation"); final Preparation expected = repository.get(preparationId, Preparation.class); final Response response = given() .param("from", "not to be found") .when() .expect() .statusCode(200) .log() .ifError() .put("/preparations/{id}/steps/copy", preparationId); assertThat(response.getStatusCode(), is(200)); final Preparation actual = repository.get(preparationId, Preparation.class); assertEquals(expected, actual); }
@Test public void shouldReleaseALockAfterAMove() throws Exception { final Folder fromFolder = folderRepository.addFolder(home.getId(), "from"); final Folder toFolder = folderRepository.addFolder(home.getId(), "to"); final String originalId = clientTest.createPreparation(createTestPreparation("yap", "7535"), fromFolder.getId()).getId(); Preparation expected = repository.get(originalId, Preparation.class); final Response response = given() .queryParam("folder", fromFolder.getId()) .queryParam("destination", toFolder.getId()) .when() .expect() .statusCode(200) .log() .ifError() .put("/preparations/{id}/move", originalId); assertThat(response.getStatusCode(), is(200)); }
@Test public void shouldGetPreparation() throws Exception { final Folder fromFolder = folderRepository.addFolder(home.getId(), "from"); final String preparationId = clientTest.createPreparation(createTestPreparation("yap", "7535"), fromFolder.getId()).getId(); final Preparation preparation = repository.get(preparationId, Preparation.class); final String expected = "{" + "\"id\":\"" + preparation.getId() + "\"," + "\"dataSetId\":\"7535\"," + "\"author\":\"" + preparation.getAuthor() + "\"," + "\"name\":\"yap\"," + "\"creationDate\":" + preparation.getCreationDate() + "," + "\"lastModificationDate\":" + preparation.getCreationDate() + "," + "\"headId\":\"f6e172c33bdacbc69bca9d32b2bd78174712a171\"" + "}"; final Response response = given() .queryParam("id", preparationId) .when() .expect() .statusCode(200) .log() .ifError() .get("/preparations/{id}", preparationId); assertThat(response.asString(), sameJSONAs(expected).allowingExtraUnexpectedFields()); }
@Test public void shouldChangePreparationHead() throws Exception { final String preparationId = createPreparation("1234", "my preparation"); final String firstStepId = applyTransformation(preparationId, "actions/append_upper_case.json"); final String secondStepId = applyTransformation(preparationId, "actions/append_lower_case.json"); Preparation preparation = repository.get(preparationId, Preparation.class); assertThat(preparation.getHeadId(), is(secondStepId)); given() .when() .put("/preparations/{id}/head/{stepId}", preparationId, firstStepId) .then() .statusCode(200); preparation = repository.get(preparationId, Preparation.class); assertThat(preparation.getHeadId(), is(firstStepId)); }
@Test public void shouldThrowExceptionOnPreparationHeadChangeWithUnknownStep() throws Exception { final String preparationId = createPreparation("1234", "my preparation"); final String firstStepId = applyTransformation(preparationId, "actions/append_upper_case.json"); Preparation preparation = repository.get(preparationId, Preparation.class); assertThat(preparation.getHeadId(), is(firstStepId)); final Response response = given() .when() .put("/preparations/{id}/head/{stepId}", preparationId, "unknown_step_id"); response .then() .statusCode(404) .assertThat() .body("code", is("TDP_PS_PREPARATION_STEP_DOES_NOT_EXIST")); }
@Test public void shouldAddActionStepAfterHead() throws Exception { final String preparationId = createPreparation("1234", "my preparation"); Preparation preparation = repository.get(preparationId, Preparation.class); final long oldModificationDate = preparation.getLastModificationDate(); assertThat(preparation.getHeadId(), is(Step.ROOT_STEP.getId())); applyTransformation(preparationId, "actions/append_copy_lastname.json"); preparation = repository.get(preparation.id(), Preparation.class); assertThat(preparation.getLastModificationDate(), is(greaterThan(oldModificationDate))); final Step head = repository.get(preparation.getHeadId(), Step.class); final PreparationActions headAction = repository.get(head.getContent(), PreparationActions.class); assertThat(headAction.getActions(), hasSize(1)); assertThat(headAction.getActions().get(0).getName(), is("copy")); }
@Test public void shouldAddMultipleActionStepAfterHead() throws Exception { final String preparationId = createPreparation("1234", "my preparation"); Preparation preparation = repository.get(preparationId, Preparation.class); final long oldModificationDate = preparation.getLastModificationDate(); assertThat(preparation.getHeadId(), is(Step.ROOT_STEP.getId())); applyTransformation(preparationId, "actions/append_multi_upper_case.json"); preparation = repository.get(preparation.id(), Preparation.class); assertThat(preparation.getLastModificationDate(), is(greaterThan(oldModificationDate))); final Step head = repository.get(preparation.getHeadId(), Step.class); final Step lastBeforeHead = repository.get(head.getParent(), Step.class); final PreparationActions headAction = repository.get(head.getContent(), PreparationActions.class); final PreparationActions lastBeforeHeadAction = repository.get(lastBeforeHead.getContent(), PreparationActions.class); assertThat(lastBeforeHeadAction.getActions(), hasSize(1)); assertThat(lastBeforeHeadAction.getActions().get(0).getName(), is("uppercase")); assertThat(lastBeforeHeadAction.getActions().get(0).getParameters().get("column_name"), is("lastname")); assertThat(headAction.getActions(), hasSize(2)); assertThat(headAction.getActions().get(0).getName(), is("uppercase")); assertThat(headAction.getActions().get(0).getParameters().get("column_name"), is("lastname")); assertThat(headAction.getActions().get(1).getName(), is("uppercase")); assertThat(headAction.getActions().get(1).getParameters().get("column_name"), is("firstname")); }
@Test public void shouldAddActionWithFilterStepAfterHead() throws Exception { final String preparationId = createPreparation("1234", "my preparation"); Preparation preparation = repository.get(preparationId, Preparation.class); final long oldModificationDate = preparation.getLastModificationDate(); assertThat(preparation.getHeadId(), is(Step.ROOT_STEP.getId())); applyTransformation(preparationId, "actions/append_copy_lastname_filter.json"); preparation = repository.get(preparation.id(), Preparation.class); assertThat(preparation.getLastModificationDate(), is(greaterThan(oldModificationDate))); final Step head = repository.get(preparation.getHeadId(), Step.class); final PreparationActions headAction = repository.get(head.getContent(), PreparationActions.class); assertThat(headAction.getActions(), hasSize(1)); final Action copyAction = headAction.getActions().get(0); assertThat(copyAction.getName(), is("copy")); assertThat(copyAction.getParameters().get(ImplicitParameters.FILTER.getKey()), is("{\"eq\":{\"field\":\"0001\",\"value\":\"value\"}}")); }
@Test public void shouldModifySingleAction() throws Exception { final String preparationId = createPreparation("1234", "my preparation"); final String firstStepId = applyTransformation(preparationId, "actions/append_upper_case.json"); Preparation preparation = repository.get(preparationId, Preparation.class); final long oldModificationDate = preparation.getLastModificationDate(); try (InputStream inputStream = PreparationControllerTest.class.getResourceAsStream("actions/append_update_upper_case.json")) { given() .body(IOUtils.toString(inputStream, UTF_8)) .contentType(ContentType.JSON) .when() .put("/preparations/{id}/actions/{action}", preparationId, firstStepId); preparation = repository.get(preparationId, Preparation.class); assertThat(preparation.getLastModificationDate(), is(greaterThan(oldModificationDate))); final Step head = repository.get(preparation.getHeadId(), Step.class); assertThat(head.getParent(), is(Step.ROOT_STEP.getId())); } }
@Test public void shouldModifyLastAction() throws Exception { final String preparationId = createPreparation("1234", "my preparation"); final String firstStepId = applyTransformation(preparationId, "actions/append_upper_case.json"); final String secondStepId = applyTransformation(preparationId, "actions/append_lower_case.json"); Preparation preparation = repository.get(preparationId, Preparation.class); final long oldModificationDate = preparation.getLastModificationDate(); given() .body(IOUtils.toString( PreparationControllerTest.class.getResourceAsStream("actions/append_update_upper_case.json"), UTF_8)) .contentType(ContentType.JSON) .when() .put("/preparations/{id}/actions/{action}", preparationId, secondStepId); preparation = repository.get(preparationId, Preparation.class); assertThat(preparation.getLastModificationDate(), is(greaterThan(oldModificationDate))); final Step head = repository.get(preparation.getHeadId(), Step.class); assertThat(head.getParent(), is(firstStepId)); }
@Test public void shouldModifyFirstAction() throws Exception { final String preparationId = createPreparation("1234", "my preparation"); final String firstStepId = applyTransformation(preparationId, "actions/append_upper_case.json"); final String secondStepId = applyTransformation(preparationId, "actions/append_lower_case.json"); Preparation preparation = repository.get(preparationId, Preparation.class); final long oldModificationDate = preparation.getLastModificationDate(); given() .body(IOUtils.toString( PreparationControllerTest.class.getResourceAsStream("actions/append_update_upper_case.json"), UTF_8)) .contentType(ContentType.JSON) .when() .put("/preparations/{id}/actions/{action}", preparation.id(), "a41184275b046d86c8d98d413ed019bc0a7f3c49"); preparation = repository.get(preparationId, Preparation.class); assertThat(preparation.getHeadId(), is(secondStepId)); assertThat(preparation.getLastModificationDate(), is(greaterThanOrEqualTo(oldModificationDate))); final Step head = repository.get(secondStepId, Step.class); assertThat(head.getParent(), is(firstStepId)); final Step first = repository.get(firstStepId, Step.class); assertThat(first.getParent(), is(Step.ROOT_STEP.getId())); }
@Test public void updateAction_shouldSaveUpdatedStepDiffAndShiftColumnsIds() throws Exception { final String preparationId = createPreparation("1234", "my preparation"); AppendStep firstStep = step(null, action("copy", paramsColAction("0003", "birth"))); clientTest.addStep(preparationId, firstStep); AppendStep secondStep = step(null, action("split", params("column_id", "0001", "column_name", "firstname", "scope", "column", "limit", "2"))); clientTest.addStep(preparationId, secondStep); final Preparation preparation = repository.get(preparationId, Preparation.class); final List<String> stepIds = preparationUtils.listStepsIds(preparation.getHeadId(), repository); assertEquals(3, stepIds.size()); assertEquals(singletonList("0004"), repository.get(stepIds.get(1), Step.class).getDiff().getCreatedColumns()); assertEquals(asList("0005", "0006"), repository.get(stepIds.get(2), Step.class).getDiff().getCreatedColumns()); given() .body(step(diff("0004", "0005", "0006"), action("split", paramsColAction("0001", "firstname")))) .contentType(ContentType.JSON) .when() .put("/preparations/{id}/actions/{action}", preparationId, stepIds.get(1)); final String newHeadId = repository.get(preparationId, Preparation.class).getHeadId(); final List<String> stepIdsAfter = preparationUtils.listStepsIds(newHeadId, repository); assertThatStepHasCreatedColumns(stepIdsAfter.get(1), "0004", "0005", "0006"); assertThatStepHasCreatedColumns(stepIdsAfter.get(2), "0007", "0008"); }
@Test public void shouldTurnInconsistentPreparationToConsistentState() throws Exception { final String preparationId = createPreparation("1234", "My preparation"); clientTest.addStep(preparationId, step(null, action("copy", paramsColAction("0001", "lastname")))); clientTest.addStep(preparationId, step(null, action("uppercase", paramsColAction("0005", "lastname_copy")))); clientTest.addStep(preparationId, step(null, action("uppercase", paramsColAction("0005", "lastname_copy")))); final Preparation preparation = repository.get(preparationId, Preparation.class); final List<String> stepIds = preparationUtils.listStepsIds(preparation.getHeadId(), repository); assertEquals(4, stepIds.size()); final Step step4 = repository.get(stepIds.get(3), Step.class); final Step step3 = repository.get(stepIds.get(2), Step.class); final PreparationActions actionStep4 = repository.get(step4.getContent(), PreparationActions.class); final PreparationActions actionStep3 = repository.get(step3.getContent(), PreparationActions.class); repository.remove(actionStep4); repository.remove(actionStep3); Response response = when().get("/preparations/{id}/details", preparationId); Preparation newPreparation = repository.get(preparationId, Preparation.class); String newHead = stepIds.get(1); assertEquals(newHead, newPreparation.getHeadId()); }
@Test public void shouldMoveAStepToFirstPositionIfLegal() throws Exception { final String preparationId = createPreparation("1234", "My preparation"); applyTransformation(preparationId, "actions/append_upper_case.json"); final String copyStepId = applyTransformation(preparationId, "actions/append_copy_lastname.json"); applyTransformation(preparationId, "actions/append_rename_copy_lastname.json"); final String headStepId = applyTransformation(preparationId, "actions/append_lower_case.json"); Step head = repository.get(headStepId, Step.class); PreparationActions headActions = repository.get(head.getContent(), PreparationActions.class); assertThat(headActions.getActions(), hasSize(4)); assertThat(headActions.getActions().get(0).getName(), is("uppercase")); assertThat(headActions.getActions().get(1).getName(), is("copy")); assertThat(headActions.getActions().get(2).getName(), is("rename_column")); assertThat(headActions.getActions().get(3).getName(), is("lowercase")); given() .queryParam("parentStepId", Step.ROOT_STEP.getId()) .when().post("/preparations/{id}/steps/{stepId}/order", preparationId, copyStepId) .then() .statusCode(200); final Preparation preparation = repository.get(preparationId, Preparation.class); final String newHeadStepId = preparation.getHeadId(); head = repository.get(newHeadStepId, Step.class); headActions = repository.get(head.getContent(), PreparationActions.class); assertThat(headActions.getActions(), hasSize(4)); assertThat(headActions.getActions().get(0).getName(), is("copy")); assertThat(headActions.getActions().get(1).getName(), is("uppercase")); assertThat(headActions.getActions().get(2).getName(), is("rename_column")); assertThat(headActions.getActions().get(3).getName(), is("lowercase")); }
@Test public void shouldMoveAStepToLastPositionIfLegal() throws Exception { final String preparationId = createPreparation("1234", "My preparation"); final String upperCaseStepId = applyTransformation(preparationId, "actions/append_upper_case.json"); applyTransformation(preparationId, "actions/append_copy_lastname.json"); applyTransformation(preparationId, "actions/append_rename_copy_lastname.json"); final String headStepId = applyTransformation(preparationId, "actions/append_lower_case.json"); Step head = repository.get(headStepId, Step.class); PreparationActions headActions = repository.get(head.getContent(), PreparationActions.class); assertThat(headActions.getActions(), hasSize(4)); assertThat(headActions.getActions().get(0).getName(), is("uppercase")); assertThat(headActions.getActions().get(1).getName(), is("copy")); assertThat(headActions.getActions().get(2).getName(), is("rename_column")); assertThat(headActions.getActions().get(3).getName(), is("lowercase")); given() .queryParam("parentStepId", headStepId) .when() .post("/preparations/{id}/steps/{stepId}/order", preparationId, upperCaseStepId) .then() .statusCode(200); final Preparation preparation = repository.get(preparationId, Preparation.class); final String newHeadStepId = preparation.getHeadId(); head = repository.get(newHeadStepId, Step.class); headActions = repository.get(head.getContent(), PreparationActions.class); assertThat(headActions.getActions(), hasSize(4)); assertThat(headActions.getActions().get(0).getName(), is("copy")); assertThat(headActions.getActions().get(1).getName(), is("rename_column")); assertThat(headActions.getActions().get(2).getName(), is("lowercase")); assertThat(headActions.getActions().get(3).getName(), is("uppercase")); }
@Test public void shouldMoveAStepToNonBoundaryPositionIfLegal() throws Exception { final String preparationId = createPreparation("1234", "My preparation"); final String upperCaseStepId = applyTransformation(preparationId, "actions/append_upper_case.json"); final String copyStepId = applyTransformation(preparationId, "actions/append_copy_lastname.json"); applyTransformation(preparationId, "actions/append_rename_copy_lastname.json"); final String headStepId = applyTransformation(preparationId, "actions/append_lower_case.json"); Step head = repository.get(headStepId, Step.class); PreparationActions headActions = repository.get(head.getContent(), PreparationActions.class); assertThat(headActions.getActions(), hasSize(4)); assertThat(headActions.getActions().get(0).getName(), is("uppercase")); assertThat(headActions.getActions().get(1).getName(), is("copy")); assertThat(headActions.getActions().get(2).getName(), is("rename_column")); assertThat(headActions.getActions().get(3).getName(), is("lowercase")); given() .queryParam("parentStepId", copyStepId) .when() .post("/preparations/{id}/steps/{stepId}/order", preparationId, upperCaseStepId) .then() .statusCode(200); final Preparation preparation = repository.get(preparationId, Preparation.class); final String newHeadStepId = preparation.getHeadId(); head = repository.get(newHeadStepId, Step.class); headActions = repository.get(head.getContent(), PreparationActions.class); assertThat(headActions.getActions(), hasSize(4)); assertThat(headActions.getActions().get(0).getName(), is("copy")); assertThat(headActions.getActions().get(1).getName(), is("uppercase")); assertThat(headActions.getActions().get(2).getName(), is("rename_column")); assertThat(headActions.getActions().get(3).getName(), is("lowercase")); }
@Test public void shouldNotMoveAStepIfItUseANotYetCreatedColumn() throws Exception { final String preparationId = createPreparation("1234", "My preparation"); clientTest.addStep(preparationId, step(null, action("copy", paramsColAction("0001", "lastname")))); clientTest.addStep(preparationId, step(null, action("copy", paramsColAction("0001", "lastname")))); clientTest.addStep(preparationId, step(null, action("uppercase", paramsColAction("0005", "lastname_copy")))); final Preparation preparation = repository.get(preparationId, Preparation.class); final List<String> stepIds = preparationUtils.listStepsIds(preparation.getHeadId(), repository); assertEquals(4, stepIds.size()); given() .queryParam("parentStepId", stepIds.get(1)) .when() .post("/preparations/{id}/steps/{stepId}/order", preparationId, stepIds.get(3)) .then() .statusCode(409); final Preparation preparationAfter = repository.get(preparationId, Preparation.class); final String newHeadStepId = preparationAfter.getHeadId(); Step head = repository.get(newHeadStepId, Step.class); PreparationActions headActions = repository.get(head.getContent(), PreparationActions.class); assertThat(headActions.getActions(), hasSize(3)); assertThat(headActions.getActions().get(0).getName(), is("copy")); assertThat(headActions.getActions().get(1).getName(), is("copy")); assertThat(headActions.getActions().get(2).getName(), is("uppercase")); }
@Test public void shouldNotMoveAStepIfItUsesADeletedColumn() throws Exception { final String preparationId = createPreparation("1234", "My preparation"); clientTest.addStep(preparationId, step(null, action("uppercase", paramsColAction("0001", "lastname")))); clientTest.addStep(preparationId, step(null, action("delete_column", paramsColAction("0001", "lastname")))); final Preparation preparation = repository.get(preparationId, Preparation.class); final List<String> stepIds = preparationUtils.listStepsIds(preparation.getHeadId(), repository); assertEquals(3, stepIds.size()); given() .queryParam("parentStepId", stepIds.get(0)) .when() .post("/preparations/{id}/steps/{stepId}/order", preparationId, stepIds.get(2)) .then() .statusCode(409); final Preparation preparationAfter = repository.get(preparationId, Preparation.class); final String newHeadStepId = preparationAfter.getHeadId(); Step head = repository.get(newHeadStepId, Step.class); PreparationActions headActions = repository.get(head.getContent(), PreparationActions.class); assertThat(headActions.getActions(), hasSize(2)); assertThat(headActions.getActions().get(0).getName(), is("uppercase")); assertThat(headActions.getActions().get(1).getName(), is("delete_column")); }
@Test public void shouldReturnHTTP404WhenNoPreparationUseDataset() throws Exception { final String datasetId = "3214a6748bc4f9674c85"; final String preparationId = createPreparation("other_dataset", "My preparation"); applyTransformation(preparationId, "actions/append_upper_case.json"); repository.get(preparationId, Preparation.class); final Response response = when().head("/preparations/use/dataset/{id}", datasetId); assertThat(response.getStatusCode(), is(404)); }
@Test public void shouldReturnHTTP203WhenPreparationIsOnDataset() throws Exception { final String datasetId = "3214a6748bc4f9674c85"; final String preparationId = createPreparation(datasetId, "My preparation"); applyTransformation(preparationId, "actions/append_upper_case.json"); repository.get(preparationId, Preparation.class); final Response response = when().head("/preparations/use/dataset/{id}", datasetId); assertThat(response.getStatusCode(), is(204)); }