diff options
Diffstat (limited to 'services/activity-spec/activity-spec-web/activity-spec-service/src/test')
4 files changed, 670 insertions, 718 deletions
diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/onap/sdc/activityspec/be/dao/impl/ActivitySpecZusammenDaoImplTest.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/onap/sdc/activityspec/be/dao/impl/ActivitySpecZusammenDaoImplTest.java new file mode 100644 index 0000000000..26b9adb89c --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/onap/sdc/activityspec/be/dao/impl/ActivitySpecZusammenDaoImplTest.java @@ -0,0 +1,368 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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 org.onap.sdc.activityspec.be.dao.impl; + +import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementConflict; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ItemVersionConflict; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; +import com.amdocs.zusammen.commons.health.data.HealthInfo; +import com.amdocs.zusammen.datatypes.Id; +import com.amdocs.zusammen.datatypes.SessionContext; +import com.amdocs.zusammen.datatypes.item.Action; +import com.amdocs.zusammen.datatypes.item.ElementContext; +import com.amdocs.zusammen.datatypes.item.Info; +import com.amdocs.zusammen.datatypes.item.Item; +import com.amdocs.zusammen.datatypes.item.ItemVersion; +import com.amdocs.zusammen.datatypes.item.ItemVersionData; +import com.amdocs.zusammen.datatypes.item.ItemVersionStatus; +import com.amdocs.zusammen.datatypes.item.Resolution; +import com.amdocs.zusammen.datatypes.itemversion.ItemVersionRevisions; +import com.amdocs.zusammen.datatypes.itemversion.Tag; + +import java.io.InputStream; + +import org.onap.sdc.activityspec.be.dao.impl.ActivitySpecDaoZusammenImpl.InfoPropertyName; +import org.onap.sdc.activityspec.be.dao.types.ActivitySpecEntity; +import org.onap.sdc.activityspec.be.datatypes.ActivitySpecData; +import org.onap.sdc.activityspec.be.datatypes.ActivitySpecParameter; +import org.onap.sdc.activityspec.be.datatypes.ElementType; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.sdc.common.session.SessionContextProviderFactory; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.types.ElementPropertyName; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; +import java.util.stream.Collectors; + +import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; + +public class ActivitySpecZusammenDaoImplTest { + + private static final Version version = new Version(); + private static final String versionId = "1234"; + private static final String itemId = "5678"; + private static final String tenant = "dox"; + + private ZusammenAdaptorMock zusammenAdaptor; + private ActivitySpecDaoZusammenImpl daoImpl; + private ActivitySpecEntity entity; + + + @BeforeMethod + public void setUp() { + SessionContextProviderFactory.getInstance().createInterface().create("test", tenant); + zusammenAdaptor = new ZusammenAdaptorMock(); + daoImpl = new ActivitySpecDaoZusammenImpl(zusammenAdaptor); + entity = new ActivitySpecEntity(); + entity = new ActivitySpecEntity(); + + entity.setId(itemId); + version.setId(versionId); + entity.setVersion(version); + entity.setName("activitySpec"); + List<String> categoryList = new ArrayList<>(); + categoryList.add("category1"); + entity.setCategoryList(categoryList); + ActivitySpecParameter inputParams = new ActivitySpecParameter("dbhost", "String"); + inputParams.setValue("localhost"); + List<ActivitySpecParameter> inputs = new ArrayList<>(); + inputs.add(inputParams); + entity.setInputs(inputs); + } + + @AfterMethod + public void tearDown() { + SessionContextProviderFactory.getInstance().createInterface().close(); + } + + @Test + public void testCreate() { + ItemVersion itemVersionmock = new ItemVersion(); + itemVersionmock.setId(new Id()); + + daoImpl.create(entity); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(entity.getId(), entity.getVersion().getId()); + Optional<ElementInfo> testElementInfo = + zusammenAdaptor.getElementInfoByName(context, elementContext, Id.ZERO, ElementType.ACTIVITYSPEC.name()); + Assert.assertTrue(testElementInfo.isPresent()); + Assert.assertEquals(testElementInfo.get().getInfo().getName(), ElementType.ACTIVITYSPEC.name()); + Assert.assertEquals(testElementInfo.get().getInfo().getProperty( + ActivitySpecDaoZusammenImpl.InfoPropertyName.DESCRIPTION.getValue()), entity.getDescription()); + Assert.assertEquals(testElementInfo.get().getInfo().getProperty(InfoPropertyName.CATEGORY.getValue()), + entity.getCategoryList()); + Assert.assertEquals(testElementInfo.get().getInfo() + .getProperty(ActivitySpecDaoZusammenImpl.InfoPropertyName.NAME.getValue()), + entity.getName()); + + final Optional<Element> testElement = + zusammenAdaptor.getElement(context, elementContext, zusammenAdaptor.elementId); + final InputStream data = testElement.get().getData(); + final ActivitySpecData activitySpecData = JsonUtil.json2Object(data, ActivitySpecData.class); + Assert.assertEquals(activitySpecData.getInputs().get(0).getName(), entity.getInputs().get(0).getName()); + } + + @Test + public void testGet() { + final ActivitySpecEntity retrieved = daoImpl.get(entity); + Assert.assertEquals(retrieved.getName(), entity.getName()); + Assert.assertEquals(retrieved.getDescription(), entity.getDescription()); + Assert.assertEquals(retrieved.getCategoryList(), entity.getCategoryList()); + } + + @Test + public void testUpdate() { + entity.setDescription("Update AS version1"); + daoImpl.update(entity); + final ActivitySpecEntity retrieved = daoImpl.get(entity); + Assert.assertEquals(retrieved.getName(), entity.getName()); + Assert.assertEquals(retrieved.getDescription(), entity.getDescription()); + Assert.assertEquals(retrieved.getCategoryList(), entity.getCategoryList()); + } + + private class ZusammenAdaptorMock implements ZusammenAdaptor { + + private ItemVersion itemVersion; + private final Map<String, Element> elementMap = new HashMap<>(); + String elementId; + + @Override + public Optional<ItemVersion> getFirstVersion(SessionContext context, Id itemId) { + + return Optional.ofNullable(itemVersion); + } + + @Override + public Collection<ItemVersion> listPublicVersions(SessionContext context, Id itemId) { + return null; + } + + @Override + public ItemVersion getPublicVersion(SessionContext context, Id itemId, Id versionId) { + return null; + } + + @Override + public Optional<Element> getElement(SessionContext context, ElementContext elementContext, String elementId) { + return Optional.of(elementMap.get(elementId)); + } + + @Override + public Optional<Element> getElementByName(SessionContext context, ElementContext elementContext, + Id parentElementId, String elementName) { + //return Optional.empty(); + ZusammenElement element = new ZusammenElement(); + Info info = new Info(); + element.setElementId(Id.ZERO); + info.addProperty("name", entity.getName()); + info.addProperty("description", entity.getDescription()); + info.addProperty("category", entity.getCategoryList()); + element.setInfo(info); + return Optional.ofNullable(element); + } + + @Override + public Collection<ElementInfo> listElements(SessionContext context, ElementContext elementContext, + Id parentElementId) { + return null; + } + + @Override + public Collection<Element> listElementData(SessionContext context, ElementContext elementContext, + Id parentElementId) { + return elementMap.values(); + } + + @Override + public Collection<ElementInfo> listElementsByName(SessionContext context, ElementContext elementContext, + Id parentElementId, String elementName) { + + return elementMap.values().stream() + .filter(element -> elementName.equals(element.getInfo() + .getProperty( + ElementPropertyName.elementType + .name()))) + .map(element -> { + ElementInfo elementInfo = new ElementInfo(); + elementInfo.setId(element.getElementId()); + elementInfo.setInfo(element.getInfo()); + return elementInfo; + }).collect(Collectors.toList()); + + } + + @Override + public Optional<ElementInfo> getElementInfoByName(SessionContext context, ElementContext elementContext, + Id parentElementId, String elementName) { + + + return elementMap.values().stream() + .filter(element -> elementName.equals(element.getInfo() + .getProperty( + ElementPropertyName.elementType + .name()))) + .map(element -> { + ElementInfo elementInfo = new ElementInfo(); + elementInfo.setId(element.getElementId()); + elementInfo.setInfo(element.getInfo()); + return elementInfo; + }).findAny(); + + + } + + @Override + public Element saveElement(SessionContext context, ElementContext elementContext, ZusammenElement element, + String message) { + if (element.getAction().equals(Action.CREATE) || element.getAction().equals(Action.UPDATE)) { + element.setElementId(new Id(UUID.randomUUID().toString())); + } + elementMap.put(element.getElementId().getValue(), element); + elementId = element.getElementId().getValue(); + return element; + } + + @Override + public void resolveElementConflict(SessionContext context, ElementContext elementContext, + ZusammenElement element, Resolution resolution) { + + } + + @Override + public Collection<HealthInfo> checkHealth(SessionContext context) { + return null; + } + + @Override + public Id createItem(SessionContext context, Info info) { + return null; + } + + @Override + public void updateItem(SessionContext context, Id itemId, Info info) { + + } + + @Override + public Id createVersion(SessionContext context, Id itemId, Id baseVersionId, ItemVersionData itemVersionData) { + return null; + } + + @Override + public void updateVersion(SessionContext context, Id itemId, Id versionId, ItemVersionData itemVersionData) { + + } + + @Override + public ItemVersion getVersion(SessionContext context, Id itemId, Id versionId) { + return null; + } + + @Override + public String getVersion(SessionContext sessionContext) { + return null; + } + + @Override + public ItemVersionStatus getVersionStatus(SessionContext context, Id itemId, Id versionId) { + return null; + } + + @Override + public ItemVersionConflict getVersionConflict(SessionContext context, Id itemId, Id versionId) { + return null; + } + + @Override + public void tagVersion(SessionContext context, Id itemId, Id versionId, Tag tag) { + + } + + @Override + public void resetVersionHistory(SessionContext context, Id itemId, Id versionId, String changeRef) { + + } + + + @Override + public void publishVersion(SessionContext context, Id itemId, Id versionId, String message) { + + } + + @Override + public void syncVersion(SessionContext sessionContext, Id itemId, Id versionId) { + + } + + @Override + public void forceSyncVersion(SessionContext context, Id itemId, Id versionId) { + + } + + @Override + public Optional<ElementInfo> getElementInfo(SessionContext context, ElementContext elementContext, + Id elementId) { + return Optional.empty(); + } + + @Override + public void revert(SessionContext sessionContext, Id itemId, Id versionId, Id revisionId) { + + } + + @Override + public ItemVersionRevisions listRevisions(SessionContext sessionContext, Id itemId, Id versionId) { + return null; + } + + @Override + public Optional<ElementConflict> getElementConflict(SessionContext context, ElementContext elementContext, + Id id) { + return Optional.empty(); + } + + @Override + public Collection<Item> listItems(SessionContext context) { + return null; + } + + @Override + public Item getItem(SessionContext context, Id itemId) { + return null; + } + + @Override + public void deleteItem(SessionContext context, Id itemId) { + + } + + } + +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/onap/sdc/activityspec/be/impl/ActivitySpecManagerImplTest.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/onap/sdc/activityspec/be/impl/ActivitySpecManagerImplTest.java new file mode 100644 index 0000000000..21d1709537 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/onap/sdc/activityspec/be/impl/ActivitySpecManagerImplTest.java @@ -0,0 +1,302 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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 org.onap.sdc.activityspec.be.impl; + +import java.util.Arrays; +import java.util.Collection; + +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.onap.sdc.activityspec.be.dao.ActivitySpecDao; +import org.onap.sdc.activityspec.api.rest.types.ActivitySpecAction; +import org.onap.sdc.activityspec.be.dao.types.ActivitySpecEntity; +import org.onap.sdc.activityspec.be.datatypes.ActivitySpecParameter; +import org.onap.sdc.activityspec.errors.ActivitySpecNotFoundException; +import org.openecomp.core.dao.UniqueValueDao; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.errors.SdcRuntimeException; +import org.openecomp.sdc.common.session.SessionContextProviderFactory; +import org.openecomp.sdc.versioning.ItemManager; +import org.openecomp.sdc.versioning.VersioningManager; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.dao.types.VersionStatus; +import org.openecomp.sdc.versioning.types.Item; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.verify; +import static org.onap.sdc.activityspec.utils.ActivitySpecConstant.ACTIVITY_SPEC_NOT_FOUND; +import static org.onap.sdc.activityspec.utils.ActivitySpecConstant.INVALID_STATE; +import static org.onap.sdc.activityspec.utils.ActivitySpecConstant.VERSION_ID_DEFAULT_VALUE; + +public class ActivitySpecManagerImplTest { + + private static final String STRING_TYPE = "String"; + private static final String TEST_ERROR_MSG = "Test Error"; + private ActivitySpecEntity input; + private static final Version VERSION01 = new Version("12345"); + private static final String ID = "ID1"; + + @Spy + @InjectMocks + private ActivitySpecManagerImpl activitySpecManager; + + @Mock + private ItemManager itemManagerMock; + + @Mock + private VersioningManager versionManagerMock; + + @Mock + private ActivitySpecDao activitySpecDaoMock; + + //This is used to mock UniqueValueUtil. This should not be removed. + @Mock + private UniqueValueDao uniqueValueDaoMock; + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @AfterMethod + public void tearDown() { + activitySpecManager = null; + } + + @Test + public void testCreate() { + + SessionContextProviderFactory.getInstance().createInterface().create("testUser", "testTenant"); + + ActivitySpecEntity activitySpecToCreate = new ActivitySpecEntity(); + activitySpecToCreate.setName("startserver"); + activitySpecToCreate.setDescription("start the server"); + activitySpecToCreate.setVersion(VERSION01); + + List<String> categoryList = new ArrayList<>(); + categoryList.add("category1"); + categoryList.add("category2"); + activitySpecToCreate.setCategoryList(categoryList); + + ActivitySpecParameter inputParams = new ActivitySpecParameter("dbhost", STRING_TYPE); + inputParams.setValue("localhost"); + ActivitySpecParameter inputParams1 = new ActivitySpecParameter("dbname", STRING_TYPE); + inputParams.setValue("prod"); + List<ActivitySpecParameter> inputs = new ArrayList<>(); + inputs.add(inputParams); + inputs.add(inputParams1); + activitySpecToCreate.setInputs(inputs); + + ActivitySpecParameter outputParams = new ActivitySpecParameter("status", STRING_TYPE); + outputParams.setValue("started"); + List<ActivitySpecParameter> outputs = new ArrayList<>(); + outputs.add(outputParams); + activitySpecToCreate.setOutputs(outputs); + + activitySpecToCreate.setId("ID1"); + activitySpecToCreate.setVersion(VERSION01); + + Item item = new Item(); + doReturn(item).when(itemManagerMock).create(anyObject()); + + ActivitySpecEntity activitySpec = activitySpecManager.createActivitySpec(activitySpecToCreate); + + Assert.assertNotNull(activitySpec); + activitySpec.setId("ID1"); + activitySpec.setStatus(VersionStatus.Draft.name()); + assertActivitySpecEquals(activitySpec, activitySpecToCreate); + } + + + @Test + public void testList() { + ActivitySpecEntity activitySpec = new ActivitySpecEntity(); + activitySpec.setName("stopServer"); + doReturn(Arrays.asList(activitySpec)).when(itemManagerMock).list(anyObject()); + final Collection<Item> activitySpecs = activitySpecManager.list("Certified"); + Assert.assertEquals(activitySpecs.size(), 1); + } + + @Test + public void testListInvalidFilter() { + final Collection<Item> activitySpecs = activitySpecManager.list("invalid_status"); + Assert.assertEquals(activitySpecs.size(), 0); + } + + @Test + public void testListNoFilter() { + final Collection<Item> activitySpecs = activitySpecManager.list(null); + Assert.assertEquals(activitySpecs.size(), 0); + } + + @Test + public void testGet() { + input = new ActivitySpecEntity(); + input.setId(ID); + input.setVersion(VERSION01); + + doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); + doReturn(input).when(activitySpecDaoMock).get(anyObject()); + VERSION01.setStatus(VersionStatus.Draft); + doReturn(VERSION01).when(versionManagerMock).get(anyObject(), anyObject()); + ActivitySpecEntity retrieved = activitySpecManager.get(input); + assertActivitySpecEquals(retrieved, input); + Assert.assertEquals(retrieved.getStatus(), VersionStatus.Draft.name()); + + + input.setVersion(new Version(VERSION_ID_DEFAULT_VALUE)); + retrieved = activitySpecManager.get(input); + assertActivitySpecEquals(retrieved, input); + Assert.assertEquals(retrieved.getStatus(), VersionStatus.Draft.name()); + } + + @Test + public void testGetActivitySpecDaoFail() { + input = new ActivitySpecEntity(); + input.setId(ID); + input.setVersion(VERSION01); + doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); + doReturn(input).when(activitySpecDaoMock).get(anyObject()); + doThrow(new SdcRuntimeException(TEST_ERROR_MSG)).when(activitySpecDaoMock).get(anyObject()); + try { + activitySpecManager.get(input); + Assert.fail(); + } catch (ActivitySpecNotFoundException exception) { + Assert.assertEquals(exception.getMessage(), ACTIVITY_SPEC_NOT_FOUND); + } + } + + @Test + public void testListVersionFail() { + input = new ActivitySpecEntity(); + input.setId(ID); + input.setVersion(VERSION01); + input.getVersion().setId(VERSION_ID_DEFAULT_VALUE); + doThrow(new SdcRuntimeException(TEST_ERROR_MSG)).when(versionManagerMock).list(anyObject()); + try { + activitySpecManager.get(input); + Assert.fail(); + } catch (ActivitySpecNotFoundException exception) { + Assert.assertEquals(exception.getMessage(), ACTIVITY_SPEC_NOT_FOUND); + } + } + + @Test + public void testInvalidDeprecate() { + try { + activitySpecManager.actOnAction(ID, VERSION01.getId(), ActivitySpecAction.DEPRECATE); + } catch (CoreException exception) { + Assert.assertEquals(exception.getMessage(), INVALID_STATE); + } + } + + @Test + public void testInvalidDelete() { + try { + activitySpecManager.actOnAction(ID, VERSION01.getId(), ActivitySpecAction.DELETE); + } catch (CoreException exception) { + Assert.assertEquals(exception.getMessage(), INVALID_STATE); + } + } + + @Test + public void testCertify() { + doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); + doReturn(VERSION01).when(versionManagerMock).get(anyObject(), anyObject()); + activitySpecManager.actOnAction(ID, VERSION01.getId(), ActivitySpecAction.CERTIFY); + + verify(versionManagerMock).updateVersion(ID, VERSION01); + verify(itemManagerMock).updateVersionStatus(ID, VersionStatus.Certified, VersionStatus.Draft); + verify(versionManagerMock).publish(anyObject(), anyObject(), anyObject()); + } + + @Test + public void testInvalidCertify() { + try { + activitySpecManager.actOnAction(ID, VERSION01.getId(), ActivitySpecAction.CERTIFY); + } catch (CoreException exception) { + Assert.assertEquals(exception.getMessage(), INVALID_STATE); + } + } + + @Test + public void testGetVersionFailOnStatusChangeAction() { + doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); + doThrow(new SdcRuntimeException(TEST_ERROR_MSG)).when(versionManagerMock).get(anyObject(), anyObject()); + try { + activitySpecManager.actOnAction(ID, VERSION01.getId(), ActivitySpecAction.CERTIFY); + Assert.fail(); + } catch (ActivitySpecNotFoundException exception) { + Assert.assertEquals(exception.getMessage(), ACTIVITY_SPEC_NOT_FOUND); + } + } + + @Test + public void testDeprecate() { + VERSION01.setStatus(VersionStatus.Certified); + Version retrivedVersion = new Version("12"); + retrivedVersion.setStatus(VersionStatus.Certified); + doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); + doReturn(retrivedVersion).when(versionManagerMock).get(anyObject(), anyObject()); + activitySpecManager.actOnAction(ID, VERSION_ID_DEFAULT_VALUE, ActivitySpecAction.DEPRECATE); + + verify(versionManagerMock).updateVersion(ID, retrivedVersion); + verify(itemManagerMock).updateVersionStatus(ID, VersionStatus.Deprecated, VersionStatus.Certified); + verify(versionManagerMock).publish(anyObject(), anyObject(), anyObject()); + } + + @Test + public void testDelete() { + ActivitySpecEntity activitySpec = new ActivitySpecEntity(); + VERSION01.setStatus(VersionStatus.Deprecated); + activitySpec.setName("stopServer"); + activitySpec.setVersion(VERSION01); + + Version retrivedVersion = new Version("12"); + retrivedVersion.setStatus(VersionStatus.Deprecated); + + doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); + doReturn(retrivedVersion).when(versionManagerMock).get(anyObject(), anyObject()); + doReturn(activitySpec).when(activitySpecDaoMock).get(anyObject()); + activitySpecManager.actOnAction(ID, VERSION_ID_DEFAULT_VALUE, ActivitySpecAction.DELETE); + + verify(versionManagerMock).updateVersion(ID, VERSION01); + verify(itemManagerMock).updateVersionStatus(ID, VersionStatus.Deleted, VersionStatus.Deprecated); + verify(versionManagerMock).publish(anyObject(), anyObject(), anyObject()); + } + + private void assertActivitySpecEquals(ActivitySpecEntity actual, ActivitySpecEntity expected) { + Assert.assertEquals(actual.getId(), expected.getId()); + Assert.assertEquals(actual.getName(), expected.getName()); + Assert.assertEquals(actual.getDescription(), expected.getDescription()); + Assert.assertEquals(actual.getCategoryList(), expected.getCategoryList()); + Assert.assertEquals(actual.getInputs(), expected.getInputs()); + Assert.assertEquals(actual.getOutputs(), expected.getOutputs()); + } + +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecZusammenDaoImplTest.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecZusammenDaoImplTest.java deleted file mode 100644 index b03f4544d2..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecZusammenDaoImplTest.java +++ /dev/null @@ -1,400 +0,0 @@ -/* - * Copyright © 2016-2018 European Support Limited - * - * 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 org.openecomp.activityspec.be.dao.impl; - -import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; -import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementConflict; -import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; -import com.amdocs.zusammen.adaptor.inbound.api.types.item.ItemVersionConflict; -import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; -import com.amdocs.zusammen.commons.health.data.HealthInfo; -import com.amdocs.zusammen.datatypes.Id; -import com.amdocs.zusammen.datatypes.SessionContext; -import com.amdocs.zusammen.datatypes.item.Action; -import com.amdocs.zusammen.datatypes.item.ElementContext; -import com.amdocs.zusammen.datatypes.item.Info; -import com.amdocs.zusammen.datatypes.item.Item; -import com.amdocs.zusammen.datatypes.item.ItemVersion; -import com.amdocs.zusammen.datatypes.item.ItemVersionData; -import com.amdocs.zusammen.datatypes.item.ItemVersionStatus; -import com.amdocs.zusammen.datatypes.item.Resolution; -import com.amdocs.zusammen.datatypes.itemversion.ItemVersionRevisions; -import com.amdocs.zusammen.datatypes.itemversion.Tag; -import java.io.InputStream; -import org.openecomp.activityspec.be.dao.impl.ActivitySpecDaoZusammenImpl.InfoPropertyName; -import org.openecomp.activityspec.be.datatypes.ActivitySpecData; -import org.openecomp.activityspec.be.datatypes.ActivitySpecParameter; -import org.openecomp.core.utilities.json.JsonUtil; -import org.openecomp.core.zusammen.api.ZusammenAdaptor; -import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity; -import org.openecomp.activityspec.be.datatypes.ElementType; -import org.openecomp.sdc.common.session.SessionContextProviderFactory; -import org.openecomp.sdc.versioning.dao.types.Version; -import org.openecomp.types.ElementPropertyName; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; -import java.util.stream.Collectors; - -import static org.mockito.Mockito.verify; -import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; - -public class ActivitySpecZusammenDaoImplTest { - - private static final Version version = new Version(); - private static final String versionId = "1234"; - private static final String itemId = "5678"; - private static final String tenant = "dox"; - - ZusammenAdaptorMock zusammenAdaptor; - ActivitySpecDaoZusammenImpl daoImpl; - ActivitySpecEntity entity; - - - @BeforeMethod - public void setUp(){ - SessionContextProviderFactory.getInstance().createInterface().create("test", - tenant); - zusammenAdaptor = new ZusammenAdaptorMock(); - daoImpl = new ActivitySpecDaoZusammenImpl(zusammenAdaptor); - entity = new ActivitySpecEntity(); - entity = new ActivitySpecEntity(); - - entity.setId(itemId); - version.setId(versionId); - entity.setVersion(version); - entity.setName("activitySpec"); - List<String> categoryList = new ArrayList<String>(); - categoryList.add("category1"); - entity.setCategoryList(categoryList); - ActivitySpecParameter inputParams = new ActivitySpecParameter("dbhost", "String"); - inputParams.setValue("localhost"); - List<ActivitySpecParameter> inputs = new ArrayList<>(); - inputs.add(inputParams); - entity.setInputs(inputs); - } - - @AfterMethod - public void tearDown(){ - SessionContextProviderFactory.getInstance().createInterface().close(); - } - - @Test - public void testCreate() { - ItemVersion itemVersionmock = new ItemVersion(); - itemVersionmock.setId(new Id()); - - daoImpl.create(entity); - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(entity.getId(), entity.getVersion().getId()); - Optional<ElementInfo> testElementInfo = - zusammenAdaptor.getElementInfoByName(context, elementContext,Id.ZERO, - ElementType.ACTIVITYSPEC.name() ); - Assert.assertTrue(testElementInfo.isPresent()); - Assert.assertEquals(testElementInfo.get().getInfo().getName(), ElementType.ACTIVITYSPEC.name()); - Assert.assertEquals(testElementInfo.get().getInfo().getProperty( - ActivitySpecDaoZusammenImpl.InfoPropertyName.DESCRIPTION.getValue()), - entity.getDescription()); - Assert.assertEquals(testElementInfo.get().getInfo().getProperty( - InfoPropertyName.CATEGORY.getValue()), - entity.getCategoryList()); - Assert.assertEquals(testElementInfo.get().getInfo().getProperty( - ActivitySpecDaoZusammenImpl.InfoPropertyName.NAME.getValue()), - entity.getName()); - - final Optional<Element> testElement = zusammenAdaptor - .getElement(context, elementContext, zusammenAdaptor.elementId); - final InputStream data = testElement.get().getData(); - final ActivitySpecData activitySpecData = JsonUtil.json2Object(data, ActivitySpecData.class); - Assert.assertEquals(activitySpecData.getInputs().get(0).getName(), - entity.getInputs().get(0).getName()); - } - - @Test - public void testGet () { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(entity.getId(), entity.getVersion().getId()); - final ActivitySpecEntity retrieved = daoImpl.get(entity); - Assert.assertEquals(retrieved.getName(), entity.getName()); - Assert.assertEquals(retrieved.getDescription(), entity.getDescription()); - Assert.assertEquals(retrieved.getCategoryList(), entity.getCategoryList()); - } - - @Test - public void testUpdate () { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(entity.getId(), entity.getVersion().getId()); - entity.setDescription("Update AS version1"); - daoImpl.update(entity); - final ActivitySpecEntity retrieved = daoImpl.get(entity); - Assert.assertEquals(retrieved.getName(), entity.getName()); - Assert.assertEquals(retrieved.getDescription(), entity.getDescription()); - Assert.assertEquals(retrieved.getCategoryList(), entity.getCategoryList()); - } - - private class ZusammenAdaptorMock implements ZusammenAdaptor { - - private ItemVersion itemVersion; - private Map<String,Element> elementMap = new HashMap<>(); - String elementId; - - /* private void setItemVersion(ItemVersion itemVersion) { - this.itemVersion = itemVersion; - } - - private void addElementInfo(String key, ElementInfo elementInfo) { - elementInfoMap.put(key, elementInfo); - } - - private void addElement(Element element) { - elements.add(element); - }*/ - - @Override - public Optional<ItemVersion> getFirstVersion(SessionContext context, Id itemId) { - - return Optional.ofNullable(itemVersion); - } - - @Override - public Collection<ItemVersion> listPublicVersions(SessionContext context, Id itemId) { - return null; - } - - @Override - public ItemVersion getPublicVersion(SessionContext context, Id itemId, Id versionId) { - return null; - } - - @Override - public Optional<Element> getElement(SessionContext context, ElementContext elementContext, - String elementId) { - return Optional.of(elementMap.get(elementId)); - } - - @Override - public Optional<Element> getElementByName(SessionContext context, - ElementContext elementContext, - Id parentElementId, String elementName) { - //return Optional.empty(); - ZusammenElement element = new ZusammenElement(); - Info info = new Info(); - element.setElementId(Id.ZERO); - info.addProperty("name", entity.getName()); - info.addProperty("description", entity.getDescription()); - info.addProperty("category", entity.getCategoryList()); - element.setInfo(info); - return Optional.ofNullable(element); - } - - @Override - public Collection<ElementInfo> listElements(SessionContext context, - ElementContext elementContext, - Id parentElementId) { - return null; - } - - @Override - public Collection<Element> listElementData(SessionContext context, - ElementContext elementContext, - Id parentElementId) { - return elementMap.values(); - } - - @Override - public Collection<ElementInfo> listElementsByName(SessionContext context, - ElementContext elementContext, - Id parentElementId, String elementName) { - - return elementMap.values().stream(). - filter(element->elementName.equals(element.getInfo().getProperty - (ElementPropertyName.elementType.name()))).map(element->{ - ElementInfo elementInfo = new ElementInfo(); - elementInfo.setId(element.getElementId()); - elementInfo.setInfo(element.getInfo()); - return elementInfo; - }).collect(Collectors.toList()); - - } - - @Override - public Optional<ElementInfo> getElementInfoByName(SessionContext context, - ElementContext elementContext, - Id parentElementId, String elementName) { - - - return elementMap.values().stream(). - filter(element -> elementName.equals(element.getInfo().getProperty - (ElementPropertyName.elementType.name()))).map(element -> { - ElementInfo elementInfo = new ElementInfo(); - elementInfo.setId(element.getElementId()); - elementInfo.setInfo(element.getInfo()); - return elementInfo; - }).findAny(); - - - - } - - @Override - public Element saveElement(SessionContext context, ElementContext elementContext, - ZusammenElement element, String message) { - if(element.getAction().equals(Action.CREATE) || - element.getAction().equals(Action.UPDATE)){ - element.setElementId(new Id(UUID.randomUUID().toString())); - } - elementMap.put(element.getElementId().getValue(),element); - elementId = element.getElementId().getValue(); - return element; - } - - @Override - public void resolveElementConflict(SessionContext context, ElementContext elementContext, - ZusammenElement element, Resolution resolution) { - - } - - @Override - public Collection<HealthInfo> checkHealth(SessionContext context) { - return null; - } - - @Override - public Id createItem(SessionContext context, Info info) { - return null; - } - - @Override - public void updateItem(SessionContext context, Id itemId, Info info) { - - } - - @Override - public Id createVersion(SessionContext context, Id itemId, Id baseVersionId, - ItemVersionData itemVersionData) { - return null; - } - - @Override - public void updateVersion(SessionContext context, Id itemId, Id versionId, - ItemVersionData itemVersionData) { - - } - - @Override - public ItemVersion getVersion(SessionContext context, Id itemId, Id versionId) { - return null; - } - - @Override - public ItemVersionStatus getVersionStatus(SessionContext context, Id itemId, Id versionId) { - return null; - } - - @Override - public ItemVersionConflict getVersionConflict(SessionContext context, Id itemId, Id versionId) { - return null; - } - - @Override - public void tagVersion(SessionContext context, Id itemId, Id versionId, Tag tag) { - - } - - @Override - public void resetVersionHistory(SessionContext context, Id itemId, Id versionId, - String changeRef) { - - } - - - @Override - public void publishVersion(SessionContext context, Id itemId, Id versionId, String message) { - - } - - @Override - public void syncVersion(SessionContext sessionContext, Id itemId, Id versionId) { - - } - - @Override - public void forceSyncVersion(SessionContext context, Id itemId, Id versionId) { - - } - - @Override - public Optional<ElementInfo> getElementInfo(SessionContext context, - ElementContext elementContext, - Id elementId) { - return Optional.empty(); - } - - @Override - public String getVersion(SessionContext sessionContext) { - return null; - } - - @Override - public void revert(SessionContext sessionContext, Id itemId, Id versionId, - Id revisionId) { - - } - - @Override - public ItemVersionRevisions listRevisions(SessionContext sessionContext, Id itemId, - Id versionId) { - return null; - } - - @Override - public Optional<ElementConflict> getElementConflict(SessionContext context, - ElementContext elementContext, - Id id) { - return Optional.empty(); - } - - @Override - public Collection<Item> listItems(SessionContext context) { - return null; - } - - @Override - public Item getItem(SessionContext context, Id itemId) { - return null; - } - - @Override - public void deleteItem(SessionContext context, Id itemId) { - - } - - } - -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImplTest.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImplTest.java deleted file mode 100644 index e930dd9454..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImplTest.java +++ /dev/null @@ -1,318 +0,0 @@ -/* - * Copyright © 2016-2018 European Support Limited - * - * 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 org.openecomp.activityspec.be.impl; - -import java.util.Arrays; -import java.util.Collection; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.Spy; -import org.openecomp.activityspec.api.rest.types.ActivitySpecAction; -import org.openecomp.activityspec.be.dao.ActivitySpecDao; -import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity; -import org.openecomp.activityspec.be.datatypes.ActivitySpecParameter; -import org.openecomp.activityspec.errors.ActivitySpecNotFoundException; -import org.openecomp.core.dao.UniqueValueDao; -import org.openecomp.sdc.common.errors.CoreException; -import org.openecomp.sdc.common.errors.SdcRuntimeException; -import org.openecomp.sdc.common.session.SessionContextProviderFactory; -import org.openecomp.sdc.versioning.ItemManager; -import org.openecomp.sdc.versioning.VersioningManager; -import org.openecomp.sdc.versioning.dao.types.Version; -import org.openecomp.sdc.versioning.dao.types.VersionStatus; -import org.openecomp.sdc.versioning.types.Item; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.util.ArrayList; -import java.util.List; - -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.verify; -import static org.openecomp.activityspec.utils.ActivitySpecConstant.ACTIVITY_SPEC_NOT_FOUND; -import static org.openecomp.activityspec.utils.ActivitySpecConstant.INVALID_STATE; -import static org.openecomp.activityspec.utils.ActivitySpecConstant.VERSION_ID_DEFAULT_VALUE; - -public class ActivitySpecManagerImplTest { - - private static final String STRING_TYPE = "String"; - private static final String TEST_ERROR_MSG = "Test Error"; - private ActivitySpecEntity input; - private static final Version VERSION01 = new Version("12345"); - private static final String ID = "ID1"; - - @Spy - @InjectMocks - private ActivitySpecManagerImpl activitySpecManager; - - @Mock - private ItemManager itemManagerMock; - - @Mock - private VersioningManager versionManagerMock; - - @Mock - private ActivitySpecDao activitySpecDaoMock; - - //This is used to mock UniqueValueUtil. This should not be removed. - @Mock - private UniqueValueDao uniqueValueDaoMock; - - @BeforeMethod - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - } - - @AfterMethod - public void tearDown() { - activitySpecManager = null; - } - - @Test - public void testCreate() { - - SessionContextProviderFactory.getInstance().createInterface().create("testUser", "testTenant"); - - ActivitySpecEntity activitySpecToCreate = new ActivitySpecEntity(); - activitySpecToCreate.setName("startserver"); - activitySpecToCreate.setDescription("start the server"); - activitySpecToCreate.setVersion(VERSION01); - - List<String> categoryList = new ArrayList<>(); - categoryList.add("category1"); - categoryList.add("category2"); - activitySpecToCreate.setCategoryList(categoryList); - - ActivitySpecParameter inputParams = new ActivitySpecParameter("dbhost", STRING_TYPE); - inputParams.setValue("localhost"); - ActivitySpecParameter inputParams1 = new ActivitySpecParameter("dbname", STRING_TYPE); - inputParams.setValue("prod"); - List<ActivitySpecParameter> inputs = new ArrayList<>(); - inputs.add(inputParams); - inputs.add(inputParams1); - activitySpecToCreate.setInputs(inputs); - - ActivitySpecParameter outputParams = new ActivitySpecParameter("status", STRING_TYPE); - outputParams.setValue("started"); - List<ActivitySpecParameter> outputs = new ArrayList<>(); - outputs.add(outputParams); - activitySpecToCreate.setOutputs(outputs); - - activitySpecToCreate.setId("ID1"); - activitySpecToCreate.setVersion(VERSION01); - - Item item = new Item(); - doReturn(item).when(itemManagerMock).create(anyObject()); - - ActivitySpecEntity activitySpec = activitySpecManager.createActivitySpec - (activitySpecToCreate); - - Assert.assertNotNull(activitySpec); - activitySpec.setId("ID1"); - activitySpec.setStatus(VersionStatus.Draft.name()); - assertActivitySpecEquals(activitySpec, activitySpecToCreate); - } - - - - @Test - public void testList () { - ActivitySpecEntity activitySpec = new ActivitySpecEntity(); - activitySpec.setName("stopServer"); - doReturn(Arrays.asList( - activitySpec)) - .when(itemManagerMock).list(anyObject()); - final Collection<Item> activitySpecs = activitySpecManager.list("Certified"); - Assert.assertEquals(activitySpecs.size(), 1); - } - - @Test - public void testListInvalidFilter () { - final Collection<Item> activitySpecs = activitySpecManager.list("invalid_status"); - Assert.assertEquals(activitySpecs.size(), 0); - } - - @Test - public void testListNoFilter () { - final Collection<Item> activitySpecs = activitySpecManager.list(null); - Assert.assertEquals(activitySpecs.size(), 0); - } - - @Test - public void testGet () { - input = new ActivitySpecEntity(); - input.setId(ID); - input.setVersion(VERSION01); - - doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); - doReturn(input).when(activitySpecDaoMock).get(anyObject()); - VERSION01.setStatus(VersionStatus.Draft); - doReturn(VERSION01).when(versionManagerMock).get(anyObject(), anyObject()); - ActivitySpecEntity retrieved = activitySpecManager.get(input); - assertActivitySpecEquals(retrieved, input); - Assert.assertEquals(retrieved.getStatus(), VersionStatus.Draft.name()); - - - input.setVersion(new Version(VERSION_ID_DEFAULT_VALUE)); - retrieved = activitySpecManager.get(input); - assertActivitySpecEquals(retrieved, input); - Assert.assertEquals(retrieved.getStatus(), VersionStatus.Draft.name()); - } - - @Test - public void testGetActivitySpecDaoFail () { - input = new ActivitySpecEntity(); - input.setId(ID); - input.setVersion(VERSION01); - doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); - doReturn(input).when(activitySpecDaoMock).get(anyObject()); - doThrow(new SdcRuntimeException(TEST_ERROR_MSG)).when(activitySpecDaoMock).get(anyObject()); - try { - activitySpecManager.get(input); - Assert.fail(); - } catch (ActivitySpecNotFoundException exception) { - Assert.assertEquals(exception.getMessage(), ACTIVITY_SPEC_NOT_FOUND); - } - } - - @Test - public void testListVersionFail () { - input = new ActivitySpecEntity(); - input.setId(ID); - input.setVersion(VERSION01); - input.getVersion().setId(VERSION_ID_DEFAULT_VALUE); - doThrow(new SdcRuntimeException(TEST_ERROR_MSG)).when(versionManagerMock).list(anyObject()); - try { - activitySpecManager.get(input); - Assert.fail(); - } catch (ActivitySpecNotFoundException exception) { - Assert.assertEquals(exception.getMessage(), ACTIVITY_SPEC_NOT_FOUND); - } - } - - @Test - public void testInvalidDeprecate () { - try { - activitySpecManager.actOnAction(ID, - VERSION01.getId(), ActivitySpecAction.DEPRECATE); - } - catch (CoreException exception) { - Assert.assertEquals(exception.getMessage(), INVALID_STATE); - } - } - - @Test - public void testInvalidDelete () { - try { - activitySpecManager.actOnAction(ID, - VERSION01.getId(), ActivitySpecAction.DELETE); - } - catch (CoreException exception) { - Assert.assertEquals(exception.getMessage(), INVALID_STATE); - } - } - - @Test - public void testCertify () { - doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); - doReturn(VERSION01).when(versionManagerMock).get(anyObject(), anyObject()); - activitySpecManager.actOnAction(ID, - VERSION01.getId(), ActivitySpecAction.CERTIFY); - - verify(versionManagerMock).updateVersion(ID, VERSION01); - verify(itemManagerMock).updateVersionStatus(ID, VersionStatus.Certified, - VersionStatus.Draft); - verify(versionManagerMock).publish(anyObject(), anyObject(), anyObject()); - } - - @Test - public void testInvalidCertify () { - try { - activitySpecManager.actOnAction(ID, - VERSION01.getId(), ActivitySpecAction.CERTIFY); - } - catch (CoreException exception) { - Assert.assertEquals(exception.getMessage(), INVALID_STATE); - } - } - - @Test - public void testGetVersionFailOnStatusChangeAction () { - doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); - doThrow(new SdcRuntimeException(TEST_ERROR_MSG)).when(versionManagerMock).get(anyObject(), anyObject()); - try { - activitySpecManager.actOnAction(ID, - VERSION01.getId(), ActivitySpecAction.CERTIFY); - Assert.fail(); - } catch (ActivitySpecNotFoundException exception) { - Assert.assertEquals(exception.getMessage(), ACTIVITY_SPEC_NOT_FOUND); - } - } - - @Test - public void testDeprecate () { - VERSION01.setStatus(VersionStatus.Certified); - Version retrivedVersion = new Version("12"); - retrivedVersion.setStatus(VersionStatus.Certified); - doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); - doReturn(retrivedVersion).when(versionManagerMock).get(anyObject(), anyObject()); - activitySpecManager.actOnAction(ID, - VERSION_ID_DEFAULT_VALUE, ActivitySpecAction.DEPRECATE); - - verify(versionManagerMock).updateVersion(ID, retrivedVersion); - verify(itemManagerMock).updateVersionStatus(ID, VersionStatus.Deprecated, - VersionStatus.Certified); - verify(versionManagerMock).publish(anyObject(), anyObject(), anyObject()); - } - - @Test - public void testDelete () { - ActivitySpecEntity activitySpec = new ActivitySpecEntity(); - VERSION01.setStatus(VersionStatus.Deprecated); - activitySpec.setName("stopServer"); - activitySpec.setVersion(VERSION01); - - Version retrivedVersion = new Version("12"); - retrivedVersion.setStatus(VersionStatus.Deprecated); - - doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); - doReturn(retrivedVersion).when(versionManagerMock).get(anyObject(), anyObject()); - doReturn(activitySpec).when(activitySpecDaoMock).get(anyObject()); - activitySpecManager.actOnAction(ID, - VERSION_ID_DEFAULT_VALUE, ActivitySpecAction.DELETE); - - verify(versionManagerMock).updateVersion(ID, VERSION01); - verify(itemManagerMock).updateVersionStatus(ID, VersionStatus.Deleted, - VersionStatus.Deprecated); - verify(versionManagerMock).publish(anyObject(), anyObject(), anyObject()); - } - - private void assertActivitySpecEquals(ActivitySpecEntity actual, ActivitySpecEntity expected) { - Assert.assertEquals(actual.getId(), expected.getId()); - Assert.assertEquals(actual.getName(), expected.getName()); - Assert.assertEquals(actual.getDescription(), expected.getDescription()); - Assert.assertEquals(actual.getCategoryList(), expected.getCategoryList()); - Assert.assertEquals(actual.getInputs(), expected.getInputs()); - Assert.assertEquals(actual.getOutputs(), expected.getOutputs()); - } - -} |