From 780c9fb91685d3c898e72d25d8fd842c552a86c0 Mon Sep 17 00:00:00 2001 From: anttil <anttil> Date: Wed, 24 Jun 2015 14:49:22 +0000 Subject: [PATCH] SSDM-1813: First test for searching files SVN: 34281 --- .../simple-dataset-creation/plugin.properties | 6 ++ .../simple-dataset-creation/script.py | 4 ++ .../dss/systemtest/api/v3/SearchFileTest.java | 59 +++++++++++++++++++ .../systemtests/SystemTestCase.java | 23 +++++++- .../v3/dto/search/FileSearchCriterion.java | 10 ++++ 5 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 datastore_server/sourceTest/core-plugins/generic-test/1/dss/drop-boxes/simple-dataset-creation/plugin.properties create mode 100644 datastore_server/sourceTest/core-plugins/generic-test/1/dss/drop-boxes/simple-dataset-creation/script.py create mode 100644 datastore_server/sourceTest/java/ch/ethz/sis/openbis/generic/dss/systemtest/api/v3/SearchFileTest.java diff --git a/datastore_server/sourceTest/core-plugins/generic-test/1/dss/drop-boxes/simple-dataset-creation/plugin.properties b/datastore_server/sourceTest/core-plugins/generic-test/1/dss/drop-boxes/simple-dataset-creation/plugin.properties new file mode 100644 index 00000000000..da29aae62e9 --- /dev/null +++ b/datastore_server/sourceTest/core-plugins/generic-test/1/dss/drop-boxes/simple-dataset-creation/plugin.properties @@ -0,0 +1,6 @@ +incoming-dir = ${root-dir}/incoming-simple-dataset-test +incoming-dir-create = true +incoming-data-completeness-condition = auto-detection +top-level-data-set-handler = ch.systemsx.cisd.etlserver.registrator.api.v2.JythonTopLevelDataSetHandlerV2 +script-path = script.py +storage-processor = ch.systemsx.cisd.etlserver.DefaultStorageProcessor \ No newline at end of file diff --git a/datastore_server/sourceTest/core-plugins/generic-test/1/dss/drop-boxes/simple-dataset-creation/script.py b/datastore_server/sourceTest/core-plugins/generic-test/1/dss/drop-boxes/simple-dataset-creation/script.py new file mode 100644 index 00000000000..beb015c2ead --- /dev/null +++ b/datastore_server/sourceTest/core-plugins/generic-test/1/dss/drop-boxes/simple-dataset-creation/script.py @@ -0,0 +1,4 @@ +def process(transaction): + data = transaction.createNewDataSet("UNKNOWN", transaction.getIncoming().getName()) + data.setExperiment(transaction.getExperiment("/CISD/NEMO/EXP1")) + transaction.moveFile(transaction.getIncoming().getPath(), data) \ No newline at end of file diff --git a/datastore_server/sourceTest/java/ch/ethz/sis/openbis/generic/dss/systemtest/api/v3/SearchFileTest.java b/datastore_server/sourceTest/java/ch/ethz/sis/openbis/generic/dss/systemtest/api/v3/SearchFileTest.java new file mode 100644 index 00000000000..2e615d74414 --- /dev/null +++ b/datastore_server/sourceTest/java/ch/ethz/sis/openbis/generic/dss/systemtest/api/v3/SearchFileTest.java @@ -0,0 +1,59 @@ +package ch.ethz.sis.openbis.generic.dss.systemtest.api.v3; + +import java.io.File; +import java.util.List; +import java.util.UUID; + +import org.testng.annotations.Test; + +import ch.ethz.sis.openbis.generic.dss.api.v3.IDataStoreServerApi; +import ch.ethz.sis.openbis.generic.dss.api.v3.dto.entity.datasetfile.DataSetFile; +import ch.ethz.sis.openbis.generic.dss.api.v3.dto.search.FileSearchCriterion; +import ch.systemsx.cisd.common.filesystem.FileUtilities; +import ch.systemsx.cisd.common.test.AssertionUtil; +import ch.systemsx.cisd.openbis.datastoreserver.systemtests.SystemTestCase; +import ch.systemsx.cisd.openbis.dss.generic.shared.ServiceProvider; +import ch.systemsx.cisd.openbis.generic.shared.api.v1.IGeneralInformationService; + +public class SearchFileTest extends SystemTestCase +{ + + @Override + protected File getIncomingDirectory() + { + return new File(rootDir, "incoming-simple-dataset-test"); + } + + @Override + protected int dataSetImportWaitDurationInSeconds() + { + return 280; + } + + @Test + public void allFilesOfGivenDatasetsAreReturned() throws Exception + { + IDataStoreServerApi dss = (IDataStoreServerApi) ServiceProvider.getDssServiceV3().getService(); + + String dataSetCode = UUID.randomUUID().toString().toUpperCase(); + + File dataSetDir = new File(workingDirectory, dataSetCode); + dataSetDir.mkdirs(); + FileUtilities.writeToFile(new File(dataSetDir, "file1.txt"), "hello world"); + FileUtilities.writeToFile(new File(dataSetDir, "file2.txt"), "hello world"); + moveFileToIncoming(dataSetDir); + waitUntilDataSetImported(); + waitUntilIndexUpdaterIsIdle(); + waitUntilDataSetPostRegistrationCompleted(dataSetCode); + + IGeneralInformationService generalInformationService = ServiceProvider.getGeneralInformationService(); + String sessionToken = generalInformationService.tryToAuthenticateForAllServices("test", "test"); + + FileSearchCriterion sc = new FileSearchCriterion(); + sc.withDataSet().withPermId().thatEquals(dataSetCode); + + List<DataSetFile> searchFiles = dss.searchFiles(sessionToken, sc); + AssertionUtil.assertSize(searchFiles, 1); + } + +} diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/SystemTestCase.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/SystemTestCase.java index 0194a4df49a..75ad83ec4b1 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/SystemTestCase.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/SystemTestCase.java @@ -34,7 +34,6 @@ import java.util.regex.Pattern; import org.apache.commons.io.FileUtils; import org.apache.log4j.Level; import org.apache.log4j.Logger; -import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConnectionFactory; import org.eclipse.jetty.server.Server; @@ -92,6 +91,8 @@ public abstract class SystemTestCase extends AssertJUnit private static final String DATA_SET_IMPORTED_LOG_MARKER = "Successfully registered data set"; + private static final String POST_REGISTRATION_COMPLETE_MARKER = "markSuccessfulPostRegistration"; + public static final ILogMonitoringStopCondition FINISHED_POST_REGISTRATION_CONDITION = new RegexCondition( ".*Post registration of (\\d*). of \\1 data sets: (.*)"); @@ -257,6 +258,26 @@ public abstract class SystemTestCase extends AssertJUnit return new File(workingDirectory, "log-registrations"); } + protected void waitUntilDataSetPostRegistrationCompleted(final String dataSetCode) throws Exception + { + waitUntilDataSetImported(new ILogMonitoringStopCondition() + { + @Override + public boolean stopConditionFulfilled(ParsedLogEntry logEntry) + { + String logMessage = logEntry.getLogMessage(); + return logMessage.contains(POST_REGISTRATION_COMPLETE_MARKER) && logMessage.contains(dataSetCode); + } + + @Override + public String toString() + { + return "Log message contains '" + POST_REGISTRATION_COMPLETE_MARKER + + "' and '" + dataSetCode + "'"; + } + }); + } + protected void waitUntilDataSetImported() throws Exception { waitUntilDataSetImported(new ILogMonitoringStopCondition() diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/dss/api/v3/dto/search/FileSearchCriterion.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/dss/api/v3/dto/search/FileSearchCriterion.java index aa0ecf3055c..8bffdd7572f 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/dss/api/v3/dto/search/FileSearchCriterion.java +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/dss/api/v3/dto/search/FileSearchCriterion.java @@ -18,6 +18,7 @@ package ch.ethz.sis.openbis.generic.dss.api.v3.dto.search; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.search.AbstractCompositeSearchCriterion; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.search.DataSetSearchCriterion; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.search.SearchCriterionToStringBuilder; /** * @author jakubs @@ -30,4 +31,13 @@ public class FileSearchCriterion extends AbstractCompositeSearchCriterion { return with(new DataSetSearchCriterion()); } + + @Override + protected SearchCriterionToStringBuilder createBuilder() + { + SearchCriterionToStringBuilder builder = super.createBuilder(); + builder.setName("FILE"); + return builder; + } + } -- GitLab