diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/DeleteDataSetBeforePostRegistrationTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/DeleteDataSetBeforePostRegistrationTest.java new file mode 100644 index 0000000000000000000000000000000000000000..14aed3277bf7eb825686208ff2e0758fc9972fca --- /dev/null +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/DeleteDataSetBeforePostRegistrationTest.java @@ -0,0 +1,70 @@ +/* + * Copyright 2012 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.systemtest; + +import static org.testng.AssertJUnit.assertEquals; + +import java.util.Collection; + +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Project; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Space; +import ch.systemsx.cisd.openbis.systemtest.base.BaseTest; + +/** + * A test the moves a data set to the trash before post registration runs. + * + * @author cramakri + */ +public class DeleteDataSetBeforePostRegistrationTest extends BaseTest +{ + + Sample sample; + + @Test + public void emptyTrashWithDataSetInPostRegistrationQueue() throws Exception + { + assertEquals(0, getDataSetsForPostRegistration().size()); + ExternalData dataSet = create(aDataSet().inSample(sample)); + + daoFactory.getPostRegistrationDAO().addDataSet(dataSet.getCode()); + assertEquals(1, getDataSetsForPostRegistration().size()); + perform(trash(dataSet)); + + perform(emptyTrash()); + assertEquals(0, getDataSetsForPostRegistration().size()); + } + + private Collection<Long> getDataSetsForPostRegistration() + { + return daoFactory.getPostRegistrationDAO().listDataSetsForPostRegistration(); + } + + @BeforeClass(dependsOnMethods = "loginAsSystem") + void createFixture() throws Exception + { + Space space = create(aSpace()); + Project project = create(aProject().inSpace(space)); + Experiment experiment = create(anExperiment().inProject(project)); + sample = create(aSample().inExperiment(experiment)); + } +} diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/BaseTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/BaseTest.java index c6d54896b8d460115fded1bfda0f909d700ce8cd..8100ee39e5c75243373540a865efa33b2c4bbcb3 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/BaseTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/BaseTest.java @@ -63,6 +63,7 @@ import ch.systemsx.cisd.openbis.systemtest.base.auth.GuardedDomain; import ch.systemsx.cisd.openbis.systemtest.base.auth.NotAuthorizationRule; import ch.systemsx.cisd.openbis.systemtest.base.auth.OrAuthorizationRule; import ch.systemsx.cisd.openbis.systemtest.base.builder.Builder; +import ch.systemsx.cisd.openbis.systemtest.base.builder.DataSetDeletionBuilder; import ch.systemsx.cisd.openbis.systemtest.base.builder.DataSetUpdateBuilder; import ch.systemsx.cisd.openbis.systemtest.base.builder.ExperimentBuilder; import ch.systemsx.cisd.openbis.systemtest.base.builder.ExperimentUpdateBuilder; @@ -73,6 +74,7 @@ import ch.systemsx.cisd.openbis.systemtest.base.builder.SampleBuilder; import ch.systemsx.cisd.openbis.systemtest.base.builder.SampleUpdateBuilder; import ch.systemsx.cisd.openbis.systemtest.base.builder.SessionBuilder; import ch.systemsx.cisd.openbis.systemtest.base.builder.SpaceBuilder; +import ch.systemsx.cisd.openbis.systemtest.base.builder.TrashEmptyBuilder; import ch.systemsx.cisd.openbis.systemtest.base.builder.UpdateBuilder; import ch.systemsx.cisd.openbis.systemtest.base.matcher.ExternalDataHasChildrenMatcher; import ch.systemsx.cisd.openbis.systemtest.base.matcher.ExternalDataHasContainerMatcher; @@ -280,6 +282,16 @@ public abstract class BaseTest extends AbstractTransactionalTestNGSpringContextT return new DataSetUpdateBuilder(commonServer, genericServer, refresh(dataset)); } + protected DataSetDeletionBuilder trash(ExternalData dataset) + { + return new DataSetDeletionBuilder(commonServer, genericServer, refresh(dataset)); + } + + protected TrashEmptyBuilder emptyTrash() + { + return new TrashEmptyBuilder(commonServer, genericServer); + } + protected SessionBuilder aSession() { return new SessionBuilder(commonServer, genericServer); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/DataSetDeletionBuilder.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/DataSetDeletionBuilder.java new file mode 100644 index 0000000000000000000000000000000000000000..0b16c46f81cf3ae97f474c8aceb74ff6a79acd2a --- /dev/null +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/DataSetDeletionBuilder.java @@ -0,0 +1,55 @@ +/* + * Copyright 2012 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.systemtest.base.builder; + +import java.util.Collections; +import java.util.List; + +import ch.systemsx.cisd.openbis.generic.server.ICommonServerForInternalUse; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DeletionType; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData; +import ch.systemsx.cisd.openbis.plugin.generic.shared.IGenericServer; + +/** + * A builder that puts a data set into the trash. + * + * @author cramakri + */ +public class DataSetDeletionBuilder extends UpdateBuilder<List<String>> +{ + private String dataSetCode; + + public DataSetDeletionBuilder(ICommonServerForInternalUse commonServer, + IGenericServer genericServer, ExternalData data) + { + super(commonServer, genericServer); + this.dataSetCode = data.getCode(); + } + + @Override + public List<String> create() + { + return Collections.singletonList(dataSetCode); + } + + @Override + public void perform() + { + commonServer.deleteDataSets(this.sessionToken, this.create(), "Test", DeletionType.TRASH, + true); + } +} \ No newline at end of file diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/TrashEmptyBuilder.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/TrashEmptyBuilder.java new file mode 100644 index 0000000000000000000000000000000000000000..ff736c8623cd68822a81c1bcd48354c4a89e15a3 --- /dev/null +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/TrashEmptyBuilder.java @@ -0,0 +1,50 @@ +/* + * Copyright 2012 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.systemtest.base.builder; + +import java.util.List; + +import ch.systemsx.cisd.openbis.generic.server.ICommonServerForInternalUse; +import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Deletion; +import ch.systemsx.cisd.openbis.plugin.generic.shared.IGenericServer; + +/** + * A builder that empties the trash. + * + * @author cramakri + */ +public class TrashEmptyBuilder extends UpdateBuilder<String> +{ + public TrashEmptyBuilder(ICommonServerForInternalUse commonServer, IGenericServer genericServer) + { + super(commonServer, genericServer); + } + + @Override + public String create() + { + return ""; + } + + @Override + public void perform() + { + List<Deletion> deletions = commonServer.listDeletions(sessionToken, false); + commonServer.deletePermanently(sessionToken, TechId.createList(deletions)); + } +} \ No newline at end of file