PreparationService { public Stream<PreparationDTO> listAll(String name, String folderPath, String path, Sort sort, Order order) { if (path != null) { if (path.contains(PATH_SEPARATOR.toString())) { if (!path.startsWith(PATH_SEPARATOR.toString())) { path = PATH_SEPARATOR.toString().concat(path); } folderPath = StringUtils.substringBeforeLast(path, PATH_SEPARATOR.toString()); if (org.apache.commons.lang3.StringUtils.isEmpty(folderPath)) { folderPath = PATH_SEPARATOR.toString(); } name = StringUtils.substringAfterLast(path, PATH_SEPARATOR.toString()); } else { folderPath = PATH_SEPARATOR.toString(); name = path; LOGGER.warn("Using path argument without '{}'. {} filter has been transformed into {}{}.", PATH_SEPARATOR, path, PATH_SEPARATOR, name); } } return listAll(filterPreparation().byName(name).withNameExactMatch(true).byFolderPath(folderPath), sort, order); }  String create(final Preparation preparation, String folderId); Stream<PreparationDTO> listAll(String name, String folderPath, String path, Sort sort, Order order); Stream<PreparationDTO> listAll(PreparationSearchCriterion searchCriterion, Sort sort, Order order); Stream<PreparationDTO> listSummary(String name, String folderPath, String path, Sort sort, Order order); Stream<PreparationDTO> searchPreparations(String dataSetId, String folderId, String name, boolean exactMatch,
            String path, Sort sort, Order order); String copy(String preparationId, String name, String destination); void move(String preparationId, String folder, String destination, String newName); void delete(String preparationId); String update(String preparationId, final PreparationDTO preparation); void copyStepsFrom(String id, String from); PreparationDTO getPreparationDetails(String id, String stepId); PreparationDetailsDTO getPreparationDetailsFull(String id, String stepId); Folder searchLocation(String id); List<String> getSteps(String id); void addPreparationAction(final String preparationId, final AppendStep appendStep); void updateAction(final String preparationId, final String stepToModifyId, final AppendStep newStep); void deleteAction(final String id, final String stepToDeleteId); void setPreparationHead(final String preparationId, final String headId); List<Action> getVersionedAction(final String id, final String version); Iterable<JsonErrorCodeDescription> listErrors(); boolean isDatasetUsedInPreparation(final String datasetId); void moveStep(final String preparationId, String stepId, String parentStepId); PersistentStep getStep(final String stepId); PreparationDTO getPreparation(final String preparationId); PersistentPreparation lockPreparation(String preparationId); void unlockPreparation(String preparationId); void updatePreparationStep(String stepId, RowMetadata rowMetadata); void invalidatePreparationStep(String stepId); RowMetadata getPreparationStep(String stepId);  }
@Test public void testListAllShouldListWhenNameAndFolderPathPointsToASubFolderContainingPreparations() throws Exception { init(); assertThat(preparationService .listAll("prep_name_foo", "/foo", null, null, null) .collect(Collectors.toList()) .size(), is(1)); }
@Test public void testListAllShouldListWhenPathPointsToASubFolderAndDoesNotStartWithASlash() throws Exception { init(); assertThat( preparationService .listAll(null, null, "foo/prep_name_foo", null, null) .collect(Collectors.toList()) .size(), is(1)); }
@Test public void testListAllShouldListWhenPathPointsToASubFolderAndStartsWithASlash() throws Exception { init(); assertThat(preparationService .listAll(null, null, "/foo/prep_name_foo", null, null) .collect(Collectors.toList()) .size(), is(1)); }
@Test public void testListAllShouldListWhenPreparationNameContainsSpecialCharactersAsInTDP4779() throws Exception { init(); assertThat(preparationService .listAll(null, null, "foo/Cr((eate Email A!ddressrrrbb[zzzz (copie-é'(-è_çà)+&.csv", null, null) .collect(Collectors.toList()) .size(), is(1)); }
@Test public void testListAllShouldListWhenFolderAndPreparationNameContainsSpecialCharactersAsInTDP4779() throws Exception { init(); assertThat(preparationService .listAll(null, null, "Folder Cr((eate Email A!ddressrrrbb[zzzz (copie-é'(-è_çà)+&.csv/Cr((eate Email A!ddressrrrbb[zzzz (copie-é'(-è_çà)+&.csv", null, null) .collect(Collectors.toList()) .size(), is(1)); }
@Test public void testListAllShouldOnlyTakeInAccountPathIfPresentEvenIfNameAndFolderPathAreWrong() throws Exception { init(); assertThat(preparationService .listAll("dont_exist", "wrong_folder_path", "/foo/prep_name_foo", null, null) .collect(Collectors.toList()) .size(), is(1)); }
@Test public void testUnnamedPreparation() throws Exception { init(); List<PreparationDTO> preparations = preparationService .listAll(null, "unnamedPreparation", null, null, null) .collect(Collectors.toList()); assertThat(preparations.size(), is(1)); assertThat(preparations.get(0).getName(), is("Preparation")); }
@Test public void testListAllShouldListWhenPathDoesNotContainsAnySlash() throws Exception { init(); assertThat(preparationService .listAll(null, null, "prep_name_home", null, null) .collect(Collectors.toList()) .size(), is(1)); }
@Test public void testListAllShouldListWhenPathIsOneLevelAndStartsWithASlash() throws Exception { init(); assertThat(preparationService .listAll(null, null, "/prep_name_home", null, null) .collect(Collectors.toList()) .size(), is(1)); }
@Test public void testListAllShouldNotListWhenNameAndFolderPathPointsToAnEmptyFolder() throws Exception { init(); assertThat(preparationService .listAll("dont_exist", "wrong_folder_path", null, null, null) .collect(Collectors.toList()) .size(), is(0)); }
@Test public void testListAllShouldListWhenNameAndFolderPathPointsToAFolderContainingPreparations() throws Exception { init(); assertThat(preparationService .listAll("prep_name_home", "/", null, null, null) .collect(Collectors.toList()) .size(), is(1)); }