From f22297baa1867147d21f26a3ffdecd7a39e7fca5 Mon Sep 17 00:00:00 2001 From: pkupczyk <pkupczyk> Date: Thu, 3 May 2012 08:32:25 +0000 Subject: [PATCH] SP-18 / BIS-20: Ensure a dataset is only deleted on the DSS when it was successfully deleted in the AS database - JUnit SVN: 25148 --- .../event/DeleteDataSetEventBuilderTest.java | 92 +++++++++++++++++++ .../event/DeleteDataSetEventParserTest.java | 83 +++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/event/DeleteDataSetEventBuilderTest.java create mode 100644 openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/event/DeleteDataSetEventParserTest.java diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/event/DeleteDataSetEventBuilderTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/event/DeleteDataSetEventBuilderTest.java new file mode 100644 index 00000000000..90d63de7ede --- /dev/null +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/event/DeleteDataSetEventBuilderTest.java @@ -0,0 +1,92 @@ +/* + * 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.generic.server.dataaccess.event; + +import java.util.Arrays; +import java.util.Collections; + +import org.testng.AssertJUnit; +import org.testng.annotations.Test; + +import ch.systemsx.cisd.openbis.generic.shared.dto.DataPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataStorePE; +import ch.systemsx.cisd.openbis.generic.shared.dto.EventPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.EventPE.EntityType; +import ch.systemsx.cisd.openbis.generic.shared.dto.EventType; +import ch.systemsx.cisd.openbis.generic.shared.dto.ExternalDataPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; + +/** + * @author pkupczyk + */ +public class DeleteDataSetEventBuilderTest extends AssertJUnit +{ + + @Test + public void testBuildForOneDataSet() + { + PersonPE registrator = new PersonPE(); + + DataStorePE store = new DataStorePE(); + store.setCode("TEST-DSS"); + + ExternalDataPE dataSet = new ExternalDataPE(); + dataSet.setCode("TEST-DATA-SET"); + dataSet.setDataStore(store); + dataSet.setShareId("TEST-SHARE-ID"); + dataSet.setLocation("TEST-LOCATION"); + + DeleteDataSetEventBuilder builder = new DeleteDataSetEventBuilder(dataSet, registrator); + + EventPE event = builder.getEvent(); + assertEquals(EntityType.DATASET, event.getEntityType()); + assertEquals(EventType.DELETION, event.getEventType()); + assertEquals(Collections.singletonList("TEST-DATA-SET"), event.getIdentifiers()); + assertEquals("/TEST-DSS/TEST-SHARE-ID/TEST-LOCATION", event.getDescription()); + assertEquals(registrator, event.getRegistrator()); + } + + @Test + public void testBuildForManyDataSets() + { + PersonPE registrator = new PersonPE(); + + DataStorePE store = new DataStorePE(); + store.setCode("TEST-DSS"); + + ExternalDataPE dataSet1 = new ExternalDataPE(); + dataSet1.setCode("TEST-DATA-SET-1"); + dataSet1.setDataStore(store); + dataSet1.setShareId("TEST-SHARE-ID-1"); + dataSet1.setLocation("TEST-LOCATION-1"); + + DataPE dataSet2 = new DataPE(); + dataSet2.setCode("TEST-DATA-SET-2"); + dataSet2.setDataStore(store); + + DeleteDataSetEventBuilder builder = + new DeleteDataSetEventBuilder(Arrays.asList(dataSet1, dataSet2), registrator); + + EventPE event = builder.getEvent(); + assertEquals(EntityType.DATASET, event.getEntityType()); + assertEquals(EventType.DELETION, event.getEventType()); + assertEquals(Arrays.asList("TEST-DATA-SET-1", "TEST-DATA-SET-2"), event.getIdentifiers()); + assertEquals("/TEST-DSS/TEST-SHARE-ID-1/TEST-LOCATION-1, /TEST-DSS//", + event.getDescription()); + assertEquals(registrator, event.getRegistrator()); + } +} diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/event/DeleteDataSetEventParserTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/event/DeleteDataSetEventParserTest.java new file mode 100644 index 00000000000..85ef007c920 --- /dev/null +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/event/DeleteDataSetEventParserTest.java @@ -0,0 +1,83 @@ +/* + * 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.generic.server.dataaccess.event; + +import java.util.Arrays; +import java.util.List; + +import org.testng.AssertJUnit; +import org.testng.annotations.Test; + +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DeletedDataSet; +import ch.systemsx.cisd.openbis.generic.shared.dto.EventPE; + +/** + * @author pkupczyk + */ +public class DeleteDataSetEventParserTest extends AssertJUnit +{ + + @Test + public void testParseOneDataSet() + { + EventPE event = new EventPE(); + event.setId(100L); + event.setIdentifiers(Arrays.asList("TEST-DATA-SET-1")); + event.setDescription("/TEST-DSS/TEST-SHARE/TEST-LOCATION"); + + List<DeletedDataSet> dataSets = new DeleteDataSetEventParser(event).getDeletedDatasets(); + + assertEquals(1, dataSets.size()); + assertEquals(100L, dataSets.get(0).getEventId()); + assertEquals("TEST-DATA-SET-1", dataSets.get(0).getCode()); + assertEquals("TEST-DSS", dataSets.get(0).getDatastoreCodeOrNull()); + assertEquals("TEST-SHARE", dataSets.get(0).getShareIdOrNull()); + assertEquals("TEST-LOCATION", dataSets.get(0).getLocationOrNull()); + } + + @Test + public void testParseManyDataSets() + { + EventPE event = new EventPE(); + event.setId(100L); + event.setIdentifiers(Arrays.asList("TEST-DATA-SET-1", "TEST-DATA-SET-2", "TEST-DATA-SET-3")); + event.setDescription("/TEST-DSS/TEST-SHARE/TEST-LOCATION, /TEST-DSS-2//, "); + + List<DeletedDataSet> dataSets = new DeleteDataSetEventParser(event).getDeletedDatasets(); + + assertEquals(3, dataSets.size()); + + assertEquals(100L, dataSets.get(0).getEventId()); + assertEquals("TEST-DATA-SET-1", dataSets.get(0).getCode()); + assertEquals("TEST-DSS", dataSets.get(0).getDatastoreCodeOrNull()); + assertEquals("TEST-SHARE", dataSets.get(0).getShareIdOrNull()); + assertEquals("TEST-LOCATION", dataSets.get(0).getLocationOrNull()); + + assertEquals(100L, dataSets.get(1).getEventId()); + assertEquals("TEST-DATA-SET-2", dataSets.get(1).getCode()); + assertEquals("TEST-DSS-2", dataSets.get(1).getDatastoreCodeOrNull()); + assertEquals(null, dataSets.get(1).getShareIdOrNull()); + assertEquals(null, dataSets.get(1).getLocationOrNull()); + + assertEquals(100L, dataSets.get(2).getEventId()); + assertEquals("TEST-DATA-SET-3", dataSets.get(2).getCode()); + assertEquals(null, dataSets.get(2).getDatastoreCodeOrNull()); + assertEquals(null, dataSets.get(2).getShareIdOrNull()); + assertEquals(null, dataSets.get(2).getLocationOrNull()); + } + +} -- GitLab