diff options
author | talig <talig@amdocs.com> | 2019-11-20 15:13:47 +0200 |
---|---|---|
committer | talig <talig@amdocs.com> | 2019-11-20 15:14:44 +0200 |
commit | c54aacb32df8fcb27375d1b131f76afc0a34d0c7 (patch) | |
tree | 8f2f0d927051a65a391744af845fdd760fbd523a /workflow-designer-be/src/test/java | |
parent | 820f4ec65a28ed822d4205b05ac6fbbd910a46cc (diff) |
Use versioning, zusammen and session libs from sdc-common-be
zusammen-lib in sdc-common-be uses cassandra 3.6.0 withoutJMXReporting
(cassandra 3.4.0 with spring boot 2.1.0 caused:
java.lang.NoClassDefFoundError: com/codahale/metrics/JmxReporter)
Change-Id: I248442d519b2ad5f4869e9384e447e9004d24586
Issue-ID: SDC-2541
Signed-off-by: talig <talig@amdocs.com>
Diffstat (limited to 'workflow-designer-be/src/test/java')
10 files changed, 265 insertions, 504 deletions
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/TestUtil.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/TestUtil.java index 8ea8e9f3..33cc0700 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/TestUtil.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/TestUtil.java @@ -18,10 +18,13 @@ package org.onap.sdc.workflow; import static org.onap.sdc.workflow.services.impl.ItemType.WORKFLOW; +import org.onap.sdc.common.versioning.persistence.types.InternalItem; +import org.onap.sdc.common.versioning.persistence.types.InternalVersion; +import org.onap.sdc.common.versioning.services.types.VersionStatus; import org.onap.sdc.workflow.services.types.Workflow; import org.onap.sdc.workflow.services.types.ArchivingStatus; -import org.openecomp.sdc.versioning.types.Item; -import org.openecomp.sdc.versioning.types.ItemStatus; +import org.onap.sdc.common.versioning.services.types.Item; +import org.onap.sdc.common.versioning.services.types.ItemStatus; public class TestUtil { @@ -38,7 +41,7 @@ public class TestUtil { } public static Item createItem(int itemNum, boolean setType, boolean setId, ItemStatus archivingStatus) { - Item item = new Item(); + InternalItem item = new InternalItem(); if (setId) { item.setId(String.valueOf(itemNum)); } @@ -51,5 +54,12 @@ public class TestUtil { return item; } + public static InternalVersion createRetrievedVersion(String id, VersionStatus status) { + InternalVersion version = new InternalVersion(); + version.setId(id); + version.setStatus(status); + return version; + } + } diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ActivitySpecRepositoryImplTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ActivitySpecRepositoryImplTest.java index bbae56e3..e69d4984 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ActivitySpecRepositoryImplTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ActivitySpecRepositoryImplTest.java @@ -16,76 +16,66 @@ package org.onap.sdc.workflow.persistence.impl; -import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doAnswer; +import static org.onap.sdc.common.zusammen.services.ZusammenElementUtil.ELEMENT_TYPE_PROPERTY; 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 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 org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.sdc.common.versioning.persistence.zusammen.ZusammenSessionContextCreator; +import org.onap.sdc.common.zusammen.services.ZusammenAdaptor; import org.onap.sdc.workflow.persistence.impl.ActivitySpecRepositoryImpl.InfoPropertyName; import org.onap.sdc.workflow.persistence.impl.types.ActivitySpecData; import org.onap.sdc.workflow.persistence.impl.types.ActivitySpecElementType; import org.onap.sdc.workflow.persistence.types.ActivitySpecEntity; import org.onap.sdc.workflow.persistence.types.ActivitySpecParameter; import org.onap.sdc.workflow.services.utilities.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.springframework.test.context.junit4.SpringJUnit4ClassRunner; -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(MockitoJUnitRunner.class) public class ActivitySpecRepositoryImplTest { - 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; + @Mock + private ZusammenAdaptor zusammenAdaptor; + @Mock + private ZusammenSessionContextCreator contextCreator; + @InjectMocks private ActivitySpecRepositoryImpl daoImpl; - private ActivitySpecEntity entity; + private ActivitySpecEntity entity; + private final Map<String, Element> elementMap = new HashMap<>(); + private String elementId; @Before public void setUp() { - SessionContextProviderFactory.getInstance().createInterface().create("test", tenant); - zusammenAdaptor = new ZusammenAdaptorMock(); - daoImpl = new ActivitySpecRepositoryImpl(zusammenAdaptor); + daoImpl = new ActivitySpecRepositoryImpl(zusammenAdaptor, contextCreator); entity = new ActivitySpecEntity(); entity = new ActivitySpecEntity(); entity.setId(itemId); - version.setId(versionId); - entity.setVersion(version); + entity.setVersionId(versionId); entity.setName("activitySpec"); List<String> categoryList = new ArrayList<>(); categoryList.add("category1"); @@ -95,11 +85,9 @@ public class ActivitySpecRepositoryImplTest { List<ActivitySpecParameter> inputs = new ArrayList<>(); inputs.add(inputParams); entity.setInputs(inputs); - } - @After - public void tearDown() { - SessionContextProviderFactory.getInstance().createInterface().close(); + + mockZusammenAdapter(); } @Test @@ -108,10 +96,10 @@ public class ActivitySpecRepositoryImplTest { 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, - ActivitySpecElementType.ACTIVITYSPEC.name()); + ElementContext elementContext = new ElementContext(entity.getId(), entity.getVersionId()); + Optional<ElementInfo> testElementInfo = zusammenAdaptor + .getElementInfoByName(contextCreator.create(), elementContext, + Id.ZERO, ActivitySpecElementType.ACTIVITYSPEC.name()); Assert.assertTrue(testElementInfo.isPresent()); Assert.assertEquals(testElementInfo.get().getInfo().getName(), ActivitySpecElementType.ACTIVITYSPEC.name()); Assert.assertEquals(testElementInfo.get().getInfo() @@ -124,7 +112,7 @@ public class ActivitySpecRepositoryImplTest { entity.getName()); final Optional<Element> testElement = - zusammenAdaptor.getElement(context, elementContext, zusammenAdaptor.elementId); + zusammenAdaptor.getElement(contextCreator.create(), elementContext, new Id(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()); @@ -148,123 +136,15 @@ public class ActivitySpecRepositoryImplTest { Assert.assertEquals(retrieved.getCategoryList(), entity.getCategoryList()); } - private class ZusammenAdaptorMock implements ZusammenAdaptor { - - private final Map<String, Element> elementMap = new HashMap<>(); - String elementId; - private ItemVersion itemVersion; - - @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) { - - } - - @Override - public Id createItem(SessionContext context, Info info) { - return null; - } - - @Override - public void updateItem(SessionContext context, Id itemId, Info info) { - - } - - @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 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) { + private void mockZusammenAdapter() { - } + doAnswer(invocationOnMock -> { + Id elementId = invocationOnMock.getArgument(2); + return Optional.of(elementMap.get(elementId.getValue())); + }).when(zusammenAdaptor).getElement(any(), any(), any()); - @Override - public void forceSyncVersion(SessionContext context, Id itemId, Id versionId) { - - } - - @Override - public void cleanVersion(SessionContext sessionContext, Id itemId, Id versionId) { - - } - - @Override - public Optional<ElementInfo> getElementInfo(SessionContext context, ElementContext elementContext, - Id elementId) { - return Optional.empty(); - } - - @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(); + doAnswer(invocationOnMock -> { ZusammenElement element = new ZusammenElement(); Info info = new Info(); element.setElementId(Id.ZERO); @@ -272,94 +152,29 @@ public class ActivitySpecRepositoryImplTest { 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 Optional<ElementConflict> getElementConflict(SessionContext context, ElementContext elementContext, - Id id) { - return Optional.empty(); - } - - @Override - public Element saveElement(SessionContext context, ElementContext elementContext, ZusammenElement element, - String message) { + return Optional.of(element); + }).when(zusammenAdaptor).getElementByName(any(), any(), any(), any()); + + doAnswer(invocationOnMock -> { + String elementName = invocationOnMock.getArgument(3); + return elementMap.values().stream() + .filter(element -> elementName.equals(element.getInfo().getProperty(ELEMENT_TYPE_PROPERTY))) + .map(element -> { + ElementInfo elementInfo = new ElementInfo(); + elementInfo.setId(element.getElementId()); + elementInfo.setInfo(element.getInfo()); + return elementInfo; + }).findAny(); + }).when(zusammenAdaptor).getElementInfoByName(any(), any(), any(), any()); + + doAnswer(invocationOnMock -> { + ZusammenElement element = invocationOnMock.getArgument(2); 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 void revert(SessionContext sessionContext, Id itemId, Id versionId, Id revisionId) { - - } - - @Override - public ItemVersionRevisions listRevisions(SessionContext sessionContext, Id itemId, Id versionId) { - return null; - } - - @Override - public Collection<HealthInfo> checkHealth(SessionContext context) { - return null; - } - - @Override - public String getVersion(SessionContext sessionContext) { - return null; - } - + }).when(zusammenAdaptor).saveElement(any(), any(), any(), any()); } - } diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java index 0fa67a9a..96f74d58 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java @@ -19,12 +19,12 @@ package org.onap.sdc.workflow.persistence.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.isNull; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; -import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; +import static org.onap.sdc.common.zusammen.services.ZusammenElementUtil.buildStructuralElement; import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; @@ -44,10 +44,10 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.onap.sdc.workflow.persistence.types.ArtifactEntity; +import org.onap.sdc.common.versioning.persistence.zusammen.ZusammenSessionContextCreator; +import org.onap.sdc.common.zusammen.services.ZusammenAdaptor; import org.onap.sdc.workflow.persistence.impl.types.WorkflowElementType; -import org.openecomp.core.zusammen.api.ZusammenAdaptor; -import org.openecomp.sdc.common.session.SessionContextProviderFactory; +import org.onap.sdc.workflow.persistence.types.ArtifactEntity; @RunWith(MockitoJUnitRunner.class) public class ArtifactRepositoryTest { @@ -56,17 +56,19 @@ public class ArtifactRepositoryTest { private static final String FILE_NAME = "fileName.txt"; private static final String ITEM1_ID = "item_id_1"; private static final String VERSION1_ID = "version_id_1"; + private static final SessionContext SESSION_CONTEXT = new SessionContext(); @Mock private ZusammenAdaptor zusammenAdaptorMock; - + @Mock + private ZusammenSessionContextCreator contextCreatorMock; @InjectMocks private ArtifactRepositoryImpl artifactRepository; @Before public void setUp() { - SessionContextProviderFactory.getInstance().createInterface().create("test_user", "workflow"); + doReturn(SESSION_CONTEXT).when(contextCreatorMock).create(); } @Test @@ -77,7 +79,7 @@ public class ArtifactRepositoryTest { artifactRepository.update(ITEM1_ID, VERSION1_ID, artifactMock); verify(zusammenAdaptorMock) - .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class), + .saveElement(eq(SESSION_CONTEXT), any(ElementContext.class), any(ZusammenElement.class), eq("Update WorkflowVersion Artifact Element")); } @@ -90,25 +92,25 @@ public class ArtifactRepositoryTest { Optional<Element> elementOptional = Optional.of(artifactElement); doReturn(elementOptional).when(zusammenAdaptorMock) - .getElementByName(any(SessionContext.class), any(ElementContext.class), isNull(Id.class), + .getElementByName(eq(SESSION_CONTEXT), any(ElementContext.class), isNull(), eq(WorkflowElementType.ARTIFACT.name())); Optional<ArtifactEntity> result = artifactRepository.get(ITEM1_ID, VERSION1_ID); assertTrue(result.isPresent()); assertEquals(FILE_NAME,result.get().getFileName()); - verify(zusammenAdaptorMock).getElementByName(any(SessionContext.class), any(ElementContext.class), isNull(Id.class), + verify(zusammenAdaptorMock).getElementByName(eq(SESSION_CONTEXT), any(ElementContext.class), isNull(), eq(WorkflowElementType.ARTIFACT.name())); } @Test - public void shouldReturnOptionalEmptyWhenDoesNotExist() throws IOException { + public void shouldReturnOptionalEmptyWhenDoesNotExist() { doReturn(Optional.empty()).when(zusammenAdaptorMock) - .getElementByName(any(SessionContext.class), any(ElementContext.class), isNull(Id.class), + .getElementByName(eq(SESSION_CONTEXT), any(ElementContext.class), isNull(), eq(WorkflowElementType.ARTIFACT.name())); Optional<ArtifactEntity> result = artifactRepository.get(ITEM1_ID, VERSION1_ID); - verify(zusammenAdaptorMock).getElementByName(any(SessionContext.class), any(ElementContext.class), isNull(Id.class), + verify(zusammenAdaptorMock).getElementByName(eq(SESSION_CONTEXT), any(ElementContext.class), isNull(), eq(WorkflowElementType.ARTIFACT.name())); assertFalse(result.isPresent()); } @@ -117,14 +119,14 @@ public class ArtifactRepositoryTest { public void shouldCreateArtifactStructure() { artifactRepository.createStructure(ITEM1_ID, VERSION1_ID); verify(zusammenAdaptorMock) - .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class), + .saveElement(eq(SESSION_CONTEXT), any(ElementContext.class), any(ZusammenElement.class), eq("Create WorkflowVersion Artifact Element")); } @Test public void shouldDeleteArtifact() { artifactRepository.delete(ITEM1_ID,VERSION1_ID); - verify(zusammenAdaptorMock).saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class), + verify(zusammenAdaptorMock).saveElement(eq(SESSION_CONTEXT), any(ElementContext.class), any(ZusammenElement.class), eq("Delete WorkflowVersion Artifact Data")); } @@ -137,7 +139,7 @@ public class ArtifactRepositoryTest { elementInfo.setInfo(info); doReturn(Optional.of(elementInfo)).when(zusammenAdaptorMock) - .getElementInfoByName(any(SessionContext.class), any(ElementContext.class), isNull(), + .getElementInfoByName(eq(SESSION_CONTEXT), any(ElementContext.class), isNull(), eq(WorkflowElementType.ARTIFACT.name())); assertTrue(artifactRepository.isExist(ITEM1_ID, VERSION1_ID)); diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java index 2953d0c2..4112ab4e 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java @@ -41,13 +41,13 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; +import org.onap.sdc.common.versioning.persistence.zusammen.ZusammenSessionContextCreator; +import org.onap.sdc.common.zusammen.services.ZusammenAdaptor; import org.onap.sdc.workflow.persistence.impl.types.ParameterPropertyName; import org.onap.sdc.workflow.persistence.impl.types.WorkflowElementType; import org.onap.sdc.workflow.persistence.types.ParameterEntity; import org.onap.sdc.workflow.persistence.types.ParameterRole; import org.onap.sdc.workflow.persistence.types.ParameterType; -import org.openecomp.core.zusammen.api.ZusammenAdaptor; -import org.openecomp.sdc.common.session.SessionContextProviderFactory; @RunWith(MockitoJUnitRunner.class) public class ParameterRepositoryTest { @@ -57,17 +57,19 @@ public class ParameterRepositoryTest { private static final String PARAMETER1_ID = "parameter_id_1"; private static final String PARAMETER2_ID = "parameter_id_2"; private static final String PARAMETERS_PARENT_ID = "parameters_id"; - + private static final SessionContext SESSION_CONTEXT = new SessionContext(); @Mock private ZusammenAdaptor zusammenAdaptorMock; + @Mock + private ZusammenSessionContextCreator contextCreatorMock; @Spy @InjectMocks private ParameterRepositoryImpl parameterRepository; @Before public void setUp() { - SessionContextProviderFactory.getInstance().createInterface().create("test_user", "workflow"); + doReturn(SESSION_CONTEXT).when(contextCreatorMock).create(); } @Test @@ -81,11 +83,11 @@ public class ParameterRepositoryTest { info.addProperty(ParameterPropertyName.MANDATORY.name(), true); element.setInfo(info); doReturn(Optional.of(element)).when(zusammenAdaptorMock) - .getElementInfo(any(SessionContext.class), any(ElementContext.class), + .getElementInfo(eq(SESSION_CONTEXT), any(ElementContext.class), eq(new Id(PARAMETER1_ID))); ParameterEntity result = parameterRepository.get(ITEM1_ID, VERSION1_ID, PARAMETER1_ID); verify(zusammenAdaptorMock) - .getElementInfo(any(SessionContext.class), any(ElementContext.class), eq(new Id(PARAMETER1_ID))); + .getElementInfo(eq(SESSION_CONTEXT), any(ElementContext.class), eq(new Id(PARAMETER1_ID))); assertEquals("testInput", result.getName()); } @@ -101,7 +103,7 @@ public class ParameterRepositoryTest { parameterRepository.update(ITEM1_ID, VERSION1_ID, ParameterRole.INPUT, parameterEntityToUpdate); verify(zusammenAdaptorMock) - .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class), + .saveElement(eq(SESSION_CONTEXT), any(ElementContext.class), any(ZusammenElement.class), eq("Update WorkflowVersion Parameter")); } @@ -110,10 +112,10 @@ public class ParameterRepositoryTest { public void shouldCreateParameterStructure() { parameterRepository.createStructure(ITEM1_ID, VERSION1_ID); verify(zusammenAdaptorMock) - .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class), + .saveElement(eq(SESSION_CONTEXT), any(ElementContext.class), any(ZusammenElement.class), eq("Create WorkflowVersion INPUTS Element")); verify(zusammenAdaptorMock) - .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class), + .saveElement(eq(SESSION_CONTEXT), any(ElementContext.class), any(ZusammenElement.class), eq("Create WorkflowVersion OUTPUTS Element")); } @@ -121,7 +123,7 @@ public class ParameterRepositoryTest { public void shouldDeleteParameter() { parameterRepository.delete(ITEM1_ID, VERSION1_ID, PARAMETER1_ID); verify(zusammenAdaptorMock) - .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class), + .saveElement(eq(SESSION_CONTEXT), any(ElementContext.class), any(ZusammenElement.class), eq("Delete Parameter with id parameter_id_1")); } @@ -145,11 +147,11 @@ public class ParameterRepositoryTest { parameter2.setInfo(info2); Collection<ElementInfo> parameters = Collections.asSet(parameter1, parameter2); doReturn(parameters).when(zusammenAdaptorMock) - .listElementsByName(any(SessionContext.class), any(ElementContext.class), isNull(), + .listElementsByName(eq(SESSION_CONTEXT), any(ElementContext.class), isNull(), eq(WorkflowElementType.INPUTS.name())); Collection<ParameterEntity> results = parameterRepository.list(ITEM1_ID, VERSION1_ID, ParameterRole.INPUT); - verify(zusammenAdaptorMock).listElementsByName(any(SessionContext.class), any(ElementContext.class), isNull(), + verify(zusammenAdaptorMock).listElementsByName(eq(SESSION_CONTEXT), any(ElementContext.class), isNull(), eq(WorkflowElementType.INPUTS.name())); assertTrue(results.stream().anyMatch(parameterEntity -> parameterEntity.getId().equals(PARAMETER1_ID))); assertTrue(results.stream().anyMatch(parameterEntity -> parameterEntity.getId().equals(PARAMETER2_ID))); @@ -170,19 +172,19 @@ public class ParameterRepositoryTest { Optional<ElementInfo> elementOptional = Optional.of(parameterParentElement); doReturn(elementOptional).when(zusammenAdaptorMock) - .getElementInfoByName(any(SessionContext.class), any(ElementContext.class), isNull(), + .getElementInfoByName(eq(SESSION_CONTEXT), any(ElementContext.class), isNull(), eq(WorkflowElementType.INPUTS.name())); parameterRepository.deleteAll(ITEM1_ID, VERSION1_ID, ParameterRole.INPUT); verify(zusammenAdaptorMock) - .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class), + .saveElement(eq(SESSION_CONTEXT), any(ElementContext.class), any(ZusammenElement.class), eq("Delete all INPUT")); } @Test(expected = IllegalStateException.class) public void shouldFailIfParentElementDoesNotExist() { doReturn(Optional.empty()).when(zusammenAdaptorMock) - .getElementInfoByName(any(SessionContext.class), any(ElementContext.class), isNull(), + .getElementInfoByName(eq(SESSION_CONTEXT), any(ElementContext.class), isNull(), eq(WorkflowElementType.INPUTS.name())); parameterRepository.deleteAll(ITEM1_ID, VERSION1_ID, ParameterRole.INPUT); } @@ -195,7 +197,7 @@ public class ParameterRepositoryTest { zusammenElement.setElementId(new Id(PARAMETER1_ID)); zusammenParentElement.addSubElement(zusammenElement); doReturn(zusammenParentElement).when(zusammenAdaptorMock) - .saveElement(any(SessionContext.class), any(ElementContext.class), + .saveElement(eq(SESSION_CONTEXT), any(ElementContext.class), any(ZusammenElement.class), eq("Create WorkflowVersion Parameter Element")); ParameterEntity parameterEntity = new ParameterEntity("test_input_parameter"); parameterEntity.setType(ParameterType.INTEGER); @@ -204,7 +206,7 @@ public class ParameterRepositoryTest { ParameterEntity returnedParameter = parameterRepository.create(ITEM1_ID, VERSION1_ID, ParameterRole.INPUT, parameterEntity); verify(zusammenAdaptorMock) - .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class), + .saveElement(eq(SESSION_CONTEXT), any(ElementContext.class), any(ZusammenElement.class), eq("Create WorkflowVersion Parameter Element")); assertEquals(PARAMETER1_ID, returnedParameter.getId()); } diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/ActivitySpecManagerImplTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/ActivitySpecManagerImplTest.java index 719531bf..3166e06f 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/ActivitySpecManagerImplTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/ActivitySpecManagerImplTest.java @@ -17,8 +17,12 @@ package org.onap.sdc.workflow.services.impl; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; +import static org.onap.sdc.workflow.TestUtil.createRetrievedVersion; import static org.onap.sdc.workflow.services.ActivitySpecConstant.ACTIVITY_SPEC_NOT_FOUND; import static org.onap.sdc.workflow.services.ActivitySpecConstant.VERSION_ID_DEFAULT_VALUE; @@ -35,6 +39,14 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.mockito.Spy; +import org.onap.sdc.common.versioning.persistence.types.InternalItem; +import org.onap.sdc.common.versioning.persistence.types.InternalVersion; +import org.onap.sdc.common.versioning.services.ItemManager; +import org.onap.sdc.common.versioning.services.VersioningManager; +import org.onap.sdc.common.versioning.services.types.Item; +import org.onap.sdc.common.versioning.services.types.Version; +import org.onap.sdc.common.versioning.services.types.VersionCreationMethod; +import org.onap.sdc.common.versioning.services.types.VersionStatus; import org.onap.sdc.workflow.api.types.activityspec.ActivitySpecAction; import org.onap.sdc.workflow.persistence.ActivitySpecRepository; import org.onap.sdc.workflow.persistence.types.ActivitySpecEntity; @@ -43,19 +55,13 @@ import org.onap.sdc.workflow.services.UniqueValueService; import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException; import org.onap.sdc.workflow.services.exceptions.VersionStatusModificationException; import org.onap.sdc.workflow.services.impl.mappers.ActivitySpecMapper; -import org.openecomp.sdc.common.errors.SdcRuntimeException; -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; public class ActivitySpecManagerImplTest { private static final String STRING_TYPE = "String"; private static final String TEST_ERROR_MSG = "Test Error"; private static final String ID = "ID1"; - private Version version01 = new Version("12345"); + private String version01 = "12345"; private ActivitySpecEntity input; @Spy @@ -87,7 +93,7 @@ public class ActivitySpecManagerImplTest { ActivitySpecEntity activitySpecToCreate = new ActivitySpecEntity(); activitySpecToCreate.setName("startserver"); activitySpecToCreate.setDescription("start the server"); - activitySpecToCreate.setVersion(version01); + activitySpecToCreate.setVersionId(version01); List<String> categoryList = new ArrayList<>(); categoryList.add("category1"); @@ -109,17 +115,21 @@ public class ActivitySpecManagerImplTest { outputs.add(outputParams); activitySpecToCreate.setOutputs(outputs); - activitySpecToCreate.setId("ID1"); - activitySpecToCreate.setVersion(version01); + activitySpecToCreate.setVersionId(version01); - Item mappedItem = new Item(); - doReturn(mappedItem).when(activitySpecMapperMock).activitySpecToItem(activitySpecToCreate); - doReturn(new Item()).when(itemManagerMock).create(mappedItem); + String itemId = "ID1"; + + InternalItem createdItem = new InternalItem(); + createdItem.setId(itemId); + doReturn(createdItem).when(itemManagerMock).create(any()); + + doReturn(createRetrievedVersion(version01, VersionStatus.Draft)).when(versionManagerMock) + .create(eq(itemId), isNull(), any(Version.class), eq(VersionCreationMethod.major)); ActivitySpecEntity activitySpec = activitySpecManager.createActivitySpec(activitySpecToCreate); Assert.assertNotNull(activitySpec); - activitySpec.setId("ID1"); + activitySpec.setId(itemId); activitySpec.setStatus(VersionStatus.Draft.name()); assertActivitySpecEquals(activitySpec, activitySpecToCreate); } @@ -136,7 +146,6 @@ public class ActivitySpecManagerImplTest { @Test public void testList() { Item item = new Item(); - item.setId(ID); doReturn(Collections.singletonList(item)).when(itemManagerMock).list(any()); doReturn(new ActivitySpecEntity(ID, null)).when(activitySpecMapperMock).itemToActivitySpec(item); @@ -161,35 +170,33 @@ public class ActivitySpecManagerImplTest { public void testGet() { input = new ActivitySpecEntity(); input.setId(ID); - input.setVersion(version01); + input.setVersionId(version01); mockListVersions(); doReturn(input).when(activitySpecRepositoryMock).get(any()); - version01.setStatus(VersionStatus.Draft); - doReturn(version01).when(versionManagerMock).get(any(), any()); + doReturn(createRetrievedVersion(version01,VersionStatus.Draft)).when(versionManagerMock).get(any(), any()); 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()); } private void mockListVersions() { - doReturn(Collections.singletonList(version01)).when(versionManagerMock).list(any()); + doReturn(Collections.singletonList((Version)createRetrievedVersion(version01,VersionStatus.Draft))).when(versionManagerMock).list(any()); } @Test public void testGetActivitySpecDaoFail() { input = new ActivitySpecEntity(); input.setId(ID); - input.setVersion(version01); + input.setVersionId(version01); mockListVersions(); doReturn(input).when(activitySpecRepositoryMock).get(any()); - Mockito.doThrow(new SdcRuntimeException(TEST_ERROR_MSG)).when(activitySpecRepositoryMock).get(any()); + Mockito.doThrow(new RuntimeException(TEST_ERROR_MSG)).when(activitySpecRepositoryMock).get(any()); try { activitySpecManager.get(input); Assert.fail(); @@ -202,9 +209,8 @@ public class ActivitySpecManagerImplTest { public void testListVersionFail() { input = new ActivitySpecEntity(); input.setId(ID); - input.setVersion(version01); - input.getVersion().setId(VERSION_ID_DEFAULT_VALUE); - Mockito.doThrow(new SdcRuntimeException(TEST_ERROR_MSG)).when(versionManagerMock).list(any()); + input.setVersionId(VERSION_ID_DEFAULT_VALUE); + Mockito.doThrow(new RuntimeException(TEST_ERROR_MSG)).when(versionManagerMock).list(any()); try { activitySpecManager.get(input); Assert.fail(); @@ -215,8 +221,7 @@ public class ActivitySpecManagerImplTest { @Test(expected = VersionStatusModificationException.class) public void testInvalidDeprecate() { - Version version = new Version(version01.getId()); - version.setStatus(VersionStatus.Draft); + InternalVersion version = createRetrievedVersion(version01, VersionStatus.Draft); doReturn(version).when(versionManagerMock).get(ID, version01); activitySpecManager.actOnAction(new ActivitySpecEntity(ID, version01), ActivitySpecAction.DEPRECATE); } @@ -228,8 +233,7 @@ public class ActivitySpecManagerImplTest { } private void mockCertifiedVersion() { - Version version = new Version(version01.getId()); - version.setStatus(VersionStatus.Certified); + InternalVersion version = createRetrievedVersion(version01, VersionStatus.Certified); doReturn(version).when(versionManagerMock).get(ID, version01); } @@ -241,22 +245,18 @@ public class ActivitySpecManagerImplTest { @Test public void testCertify() { - Version retrievedVersion = new Version(version01.getId()); - retrievedVersion.setStatus(VersionStatus.Draft); + InternalVersion retrievedVersion = createRetrievedVersion(version01, VersionStatus.Draft); doReturn(Collections.singletonList(retrievedVersion)).when(versionManagerMock).list(any()); doReturn(retrievedVersion).when(versionManagerMock).get(any(), any()); activitySpecManager.actOnAction(new ActivitySpecEntity(ID, version01), ActivitySpecAction.CERTIFY); - verify(versionManagerMock).updateVersion(ID, retrievedVersion); - verify(itemManagerMock).updateVersionStatus(ID, VersionStatus.Certified, VersionStatus.Draft); - verify(versionManagerMock).publish(ID, retrievedVersion, "actionOnActivitySpec :CERTIFY"); + verify(versionManagerMock).updateStatus(eq(ID), eq(version01), eq(VersionStatus.Certified), anyString()); } @Test public void testGetVersionFailOnStatusChangeAction() { mockListVersions(); - Mockito.doThrow(new SdcRuntimeException(TEST_ERROR_MSG)).when(versionManagerMock).get(any(), any()); try { activitySpecManager.actOnAction(new ActivitySpecEntity(ID, version01), ActivitySpecAction.CERTIFY); Assert.fail(); @@ -267,35 +267,27 @@ public class ActivitySpecManagerImplTest { @Test public void testDeprecate() { - version01.setStatus(VersionStatus.Certified); - Version retrivedVersion = new Version("12"); - retrivedVersion.setStatus(VersionStatus.Certified); + InternalVersion retrievedVersion = createRetrievedVersion(version01, VersionStatus.Certified); mockListVersions(); - doReturn(retrivedVersion).when(versionManagerMock).get(any(), any()); - activitySpecManager.actOnAction(new ActivitySpecEntity(ID, new Version(VERSION_ID_DEFAULT_VALUE)), ActivitySpecAction.DEPRECATE); + doReturn(retrievedVersion).when(versionManagerMock).get(any(), any()); + activitySpecManager + .actOnAction(new ActivitySpecEntity(ID, VERSION_ID_DEFAULT_VALUE), ActivitySpecAction.DEPRECATE); - verify(versionManagerMock).updateVersion(ID, retrivedVersion); - verify(itemManagerMock).updateVersionStatus(ID, VersionStatus.Deprecated, VersionStatus.Certified); - verify(versionManagerMock).publish(any(), any(), any()); + verify(versionManagerMock).updateStatus(eq(ID), eq(version01), eq(VersionStatus.Deprecated), anyString()); } @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); + activitySpec.setVersionId(version01); mockListVersions(); - doReturn(retrivedVersion).when(versionManagerMock).get(any(), any()); + doReturn(createRetrievedVersion(version01, VersionStatus.Deprecated)).when(versionManagerMock).get(any(), any()); doReturn(activitySpec).when(activitySpecRepositoryMock).get(any()); - activitySpecManager.actOnAction(new ActivitySpecEntity(ID, new Version(VERSION_ID_DEFAULT_VALUE)), ActivitySpecAction.DELETE); + activitySpecManager + .actOnAction(new ActivitySpecEntity(ID, VERSION_ID_DEFAULT_VALUE), ActivitySpecAction.DELETE); - verify(versionManagerMock).updateVersion(ID, version01); - verify(itemManagerMock).updateVersionStatus(ID, VersionStatus.Deleted, VersionStatus.Deprecated); - verify(versionManagerMock).publish(any(), any(), any()); + verify(versionManagerMock).updateStatus(eq(ID), eq(version01), eq(VersionStatus.Deleted), anyString()); } } diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java index 2a69dbd6..1db24092 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java @@ -19,16 +19,16 @@ package org.onap.sdc.workflow.services.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.onap.sdc.common.versioning.services.types.VersionStatus.Certified; import static org.onap.sdc.workflow.TestUtil.createItem; import static org.onap.sdc.workflow.TestUtil.createWorkflow; import static org.onap.sdc.workflow.services.types.PagingConstants.DEFAULT_LIMIT; import static org.onap.sdc.workflow.services.types.PagingConstants.DEFAULT_OFFSET; import static org.onap.sdc.workflow.services.types.PagingConstants.MAX_LIMIT; -import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Certified; import java.util.ArrayList; import java.util.Arrays; @@ -42,9 +42,11 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.onap.sdc.common.versioning.services.ItemManager; +import org.onap.sdc.common.versioning.services.types.Item; +import org.onap.sdc.common.versioning.services.types.ItemStatus; import org.onap.sdc.workflow.services.UniqueValueService; import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException; -import org.onap.sdc.workflow.services.exceptions.WorkflowStatusModificationException; import org.onap.sdc.workflow.services.impl.mappers.VersionStateMapper; import org.onap.sdc.workflow.services.impl.mappers.WorkflowMapper; import org.onap.sdc.workflow.services.types.ArchivingStatus; @@ -56,11 +58,6 @@ import org.onap.sdc.workflow.services.types.Sort; import org.onap.sdc.workflow.services.types.SortingRequest; import org.onap.sdc.workflow.services.types.Workflow; import org.onap.sdc.workflow.services.types.WorkflowVersionState; -import org.openecomp.sdc.common.errors.CoreException; -import org.openecomp.sdc.common.errors.ErrorCode; -import org.openecomp.sdc.versioning.ItemManager; -import org.openecomp.sdc.versioning.types.Item; -import org.openecomp.sdc.versioning.types.ItemStatus; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) @@ -118,8 +115,8 @@ public class WorkflowManagerImplTest { doReturn(Certified).when(versionStateMapperMock) .workflowVersionStateToVersionStatus(WorkflowVersionState.CERTIFIED); doReturn(Arrays.asList(ITEMS.get(0), ITEMS.get(2))).when(itemManagerMock).list(any()); - doReturn(MAPPED_WORKFLOWS.get(0)).when(workflowMapperMock).itemToWorkflow(ITEMS.get(0)); - doReturn(MAPPED_WORKFLOWS.get(2)).when(workflowMapperMock).itemToWorkflow(ITEMS.get(2)); + doReturn(MAPPED_WORKFLOWS.get(0)).when(workflowMapperMock).fromItem(ITEMS.get(0)); + doReturn(MAPPED_WORKFLOWS.get(2)).when(workflowMapperMock).fromItem(ITEMS.get(2)); RequestSpec requestSpec = createRequestSpec(0, 20, true); Page<Workflow> workflows = @@ -135,48 +132,12 @@ public class WorkflowManagerImplTest { } @Test(expected = EntityNotFoundException.class) - public void shouldThrowExceptionWhenWorkflowDontExistTryingToUpdateStatus() { - doReturn(null).when(itemManagerMock).get(ITEM1_ID); - workflowManager.updateStatus(ITEM1_ID, ArchivingStatus.ARCHIVED); - } - - @Test(expected = WorkflowStatusModificationException.class) - public void shouldThrowExceptionWhenFailingToUpdateStatus() { - Item mockItem = new Item(); - mockItem.setId(ITEM1_ID); - mockItem.setStatus(ItemStatus.ARCHIVED); - doReturn(mockItem).when(itemManagerMock).get(ITEM1_ID); - doThrow(new CoreException(new ErrorCode.ErrorCodeBuilder().build())).when(itemManagerMock).archive(mockItem); - workflowManager.updateStatus(ITEM1_ID, ArchivingStatus.ARCHIVED); - } - - @Test - public void shouldArchiveWorkflow() { - Item mockItem = new Item(); - mockItem.setId(ITEM1_ID); - mockItem.setStatus(ItemStatus.ACTIVE); - doReturn(mockItem).when(itemManagerMock).get(ITEM1_ID); - workflowManager.updateStatus(ITEM1_ID, ArchivingStatus.ARCHIVED); - verify(itemManagerMock).archive(mockItem); - } - - @Test - public void shouldRestoreWorkflow() { - Item mockItem = new Item(); - mockItem.setId(ITEM1_ID); - mockItem.setStatus(ItemStatus.ARCHIVED); - doReturn(mockItem).when(itemManagerMock).get(ITEM1_ID); - workflowManager.updateStatus(ITEM1_ID, ArchivingStatus.ACTIVE); - verify(itemManagerMock).restore(mockItem); - } - - @Test(expected = EntityNotFoundException.class) public void shouldThrowExceptionWhenWorkflowDontExist() { Workflow nonExistingWorkflow = new Workflow(); nonExistingWorkflow.setId(ITEM1_ID); doReturn(null).when(itemManagerMock).get(ITEM1_ID); workflowManager.get(nonExistingWorkflow); - verify(workflowMapperMock, times(3)).itemToWorkflow(any(Item.class)); + verify(workflowMapperMock, times(3)).fromItem(any(Item.class)); } @Test @@ -186,22 +147,15 @@ public class WorkflowManagerImplTest { Workflow workflow = createWorkflow(1, true, ArchivingStatus.ACTIVE); workflowManager.get(workflow); verify(itemManagerMock).get(ITEM1_ID); - verify(workflowMapperMock).itemToWorkflow(retrievedItem); + verify(workflowMapperMock).fromItem(retrievedItem); } @Test public void shouldCreateWorkflowItemFromWorkflow() { Workflow workflowToBeCreated = createWorkflow(1, false, ArchivingStatus.ACTIVE); - Item createdWorkflowItem = createItem(1, false, true, ItemStatus.ACTIVE); - doReturn(createdWorkflowItem).when(workflowMapperMock).workflowToItem(workflowToBeCreated); - doReturn(createdWorkflowItem).when(itemManagerMock).create(createdWorkflowItem); workflowManager.create(workflowToBeCreated); + verify(itemManagerMock).create(any(Item.class)); verify(uniqueValueServiceMock).validateUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, workflowToBeCreated.getName()); - - createdWorkflowItem.setStatus(ItemStatus.ACTIVE); - createdWorkflowItem.setType(WORKFLOW_TYPE); - verify(itemManagerMock).create(createdWorkflowItem); - verify(uniqueValueServiceMock).createUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, workflowToBeCreated.getName()); } @Test @@ -209,9 +163,8 @@ public class WorkflowManagerImplTest { Item workflowItem = createItem(1, true, true, ItemStatus.ACTIVE); doReturn(workflowItem).when(itemManagerMock).get(ITEM1_ID); Workflow workflowToBeUpdated = createWorkflow(1, true, ArchivingStatus.ACTIVE); - doReturn(workflowItem).when(workflowMapperMock).workflowToItem(workflowToBeUpdated); workflowManager.update(workflowToBeUpdated); - verify(itemManagerMock).update(workflowItem); + verify(itemManagerMock).update(eq(ITEM1_ID),any(Item.class)); verify(uniqueValueServiceMock) .updateUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, workflowItem.getName(), workflowToBeUpdated.getName()); @@ -389,7 +342,7 @@ public class WorkflowManagerImplTest { private void mockItemToWorkflowMaps() { for (int i = 0; i < ITEMS.size(); i++) { - doReturn(MAPPED_WORKFLOWS.get(i)).when(workflowMapperMock).itemToWorkflow(ITEMS.get(i)); + doReturn(MAPPED_WORKFLOWS.get(i)).when(workflowMapperMock).fromItem(ITEMS.get(i)); } } diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java index db4cfa32..6648f376 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java @@ -19,13 +19,15 @@ package org.onap.sdc.workflow.services.impl; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; +import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.onap.sdc.workflow.TestUtil.createRetrievedVersion; import static org.onap.sdc.workflow.services.types.WorkflowVersionState.CERTIFIED; import static org.onap.sdc.workflow.services.types.WorkflowVersionState.DRAFT; @@ -36,7 +38,6 @@ import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Optional; - import org.apache.commons.io.IOUtils; import org.junit.Rule; import org.junit.Test; @@ -47,6 +48,15 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; +import org.onap.sdc.common.versioning.persistence.types.InternalItem; +import org.onap.sdc.common.versioning.persistence.types.InternalVersion; +import org.onap.sdc.common.versioning.services.ItemManager; +import org.onap.sdc.common.versioning.services.VersioningManager; +import org.onap.sdc.common.versioning.services.types.ItemStatus; +import org.onap.sdc.common.versioning.services.types.Version; +import org.onap.sdc.common.versioning.services.types.VersionCreationMethod; +import org.onap.sdc.common.versioning.services.types.VersionState; +import org.onap.sdc.common.versioning.services.types.VersionStatus; import org.onap.sdc.workflow.persistence.ArtifactRepository; import org.onap.sdc.workflow.persistence.ParameterRepository; import org.onap.sdc.workflow.persistence.types.ArtifactEntity; @@ -62,14 +72,6 @@ import org.onap.sdc.workflow.services.impl.mappers.VersionMapper; import org.onap.sdc.workflow.services.impl.mappers.VersionStateMapper; import org.onap.sdc.workflow.services.types.WorkflowVersion; import org.onap.sdc.workflow.services.types.WorkflowVersionState; -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.VersionState; -import org.openecomp.sdc.versioning.dao.types.VersionStatus; -import org.openecomp.sdc.versioning.types.Item; -import org.openecomp.sdc.versioning.types.ItemStatus; -import org.openecomp.sdc.versioning.types.VersionCreationMethod; import org.springframework.mock.web.MockMultipartFile; @RunWith(MockitoJUnitRunner.class) @@ -99,14 +101,13 @@ public class WorkflowVersionManagerImplTest { @Test(expected = EntityNotFoundException.class) public void shouldThrowExceptionWhenVersionDontExist() { - Version nonExistingVersion = new Version(VERSION1_ID); - doThrow(new RuntimeException()).when(versioningManagerMock).get(ITEM1_ID, nonExistingVersion); + doThrow(new RuntimeException()).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID); workflowVersionManager.get(ITEM1_ID, VERSION1_ID); } @Test(expected = WorkflowModificationException.class) public void shouldThrowExceptionWhenCreatingVersionForArchivedWorkflow() { - Item mockItem = new Item(); + InternalItem mockItem = new InternalItem(); mockItem.setId(ITEM1_ID); mockItem.setStatus(ItemStatus.ARCHIVED); doReturn(mockItem).when(itemManagerMock).get(ITEM1_ID); @@ -115,7 +116,7 @@ public class WorkflowVersionManagerImplTest { @Test(expected = WorkflowModificationException.class) public void shouldThrowExceptionWhenUpdatingVersionForArchivedWorkflow() { - Item mockItem = new Item(); + InternalItem mockItem = new InternalItem(); mockItem.setId(ITEM1_ID); mockItem.setStatus(ItemStatus.ARCHIVED); doReturn(mockItem).when(itemManagerMock).get(ITEM1_ID); @@ -124,7 +125,7 @@ public class WorkflowVersionManagerImplTest { @Test(expected = WorkflowModificationException.class) public void shouldThrowExceptionWhenUploadingArtifactForArchivedWorkflow() { - Item mockItem = new Item(); + InternalItem mockItem = new InternalItem(); mockItem.setId(ITEM1_ID); mockItem.setStatus(ItemStatus.ARCHIVED); doReturn(mockItem).when(itemManagerMock).get(ITEM1_ID); @@ -134,7 +135,7 @@ public class WorkflowVersionManagerImplTest { @Test(expected = WorkflowModificationException.class) public void shouldThrowExceptionWhenDeletingArtifactForArchivedWorkflow() { - Item mockItem = new Item(); + InternalItem mockItem = new InternalItem(); mockItem.setId(ITEM1_ID); mockItem.setStatus(ItemStatus.ARCHIVED); doReturn(mockItem).when(itemManagerMock).get(ITEM1_ID); @@ -143,65 +144,65 @@ public class WorkflowVersionManagerImplTest { @Test public void shouldReturnWorkflowVersionWhenExist() { - Version version = new Version(VERSION1_ID); WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID); - doReturn(workflowVersion).when(versionMapperMock).versionToWorkflowVersion(any(Version.class)); - doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), any(Version.class)); + doReturn(workflowVersion).when(versionMapperMock).fromVersion(any(Version.class)); + doReturn(new Version()).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID); doReturn(Collections.emptyList()).when(parameterRepositoryMock) .list(eq(ITEM1_ID), eq(VERSION1_ID), any(ParameterRole.class)); workflowVersionManager.get(ITEM1_ID, VERSION1_ID); - verify(versioningManagerMock).get(ITEM1_ID, version); + verify(versioningManagerMock).get(ITEM1_ID, VERSION1_ID); } @Test public void shouldReturnWorkflowVersionList() { - Version version1 = new Version(VERSION1_ID); - Version version2 = new Version(VERSION2_ID); + InternalVersion version1 = createRetrievedVersion(VERSION1_ID, VersionStatus.Certified); + InternalVersion version2 = createRetrievedVersion(VERSION2_ID, VersionStatus.Draft); List<Version> versionList = Arrays.asList(version1, version2); doReturn(versionList).when(versioningManagerMock).list(ITEM1_ID); + WorkflowVersion workflowVersion1 = new WorkflowVersion(); workflowVersion1.setId(VERSION1_ID); workflowVersion1.setName(VERSION1_ID); + doReturn(workflowVersion1).when(versionMapperMock).fromVersion(version1); + WorkflowVersion workflowVersion2 = new WorkflowVersion(); workflowVersion2.setId(VERSION2_ID); workflowVersion2.setName(VERSION2_ID); - doReturn(workflowVersion2).when(versionMapperMock).versionToWorkflowVersion(version2); + doReturn(workflowVersion2).when(versionMapperMock).fromVersion(version2); + doReturn(Collections.emptyList()).when(parameterRepositoryMock) .list(eq(ITEM1_ID), anyString(), eq(ParameterRole.INPUT)); doReturn(Collections.emptyList()).when(parameterRepositoryMock) .list(eq(ITEM1_ID), anyString(), eq(ParameterRole.OUTPUT)); + workflowVersionManager.list(ITEM1_ID, null); verify(versioningManagerMock).list(ITEM1_ID); - verify(versionMapperMock, times(2)).versionToWorkflowVersion(any(Version.class)); + verify(versionMapperMock, times(2)).fromVersion(any(Version.class)); } @Test public void shouldReturnCertifiedWorkflowVersionList() { - Version version1 = new Version(VERSION1_ID); - version1.setStatus(VersionStatus.Certified); - Version version2 = new Version(VERSION2_ID); - version2.setStatus(VersionStatus.Draft); + InternalVersion version1 = createRetrievedVersion(VERSION1_ID, VersionStatus.Certified); + InternalVersion version2 = createRetrievedVersion(VERSION2_ID, VersionStatus.Draft); List<Version> versionList = Arrays.asList(version1, version2); + doReturn(versionList).when(versioningManagerMock).list(ITEM1_ID); WorkflowVersion workflowVersion1 = new WorkflowVersion(); workflowVersion1.setId(VERSION1_ID); workflowVersion1.setName(VERSION1_ID); - WorkflowVersion workflowVersion2 = new WorkflowVersion(); - workflowVersion2.setId(VERSION2_ID); - workflowVersion2.setName(VERSION2_ID); - doReturn(workflowVersion1).when(versionMapperMock).versionToWorkflowVersion(version1); + doReturn(workflowVersion1).when(versionMapperMock).fromVersion(version1); + doReturn(Collections.emptyList()).when(parameterRepositoryMock) .list(eq(ITEM1_ID), anyString(), eq(ParameterRole.INPUT)); doReturn(Collections.emptyList()).when(parameterRepositoryMock) .list(eq(ITEM1_ID), anyString(), eq(ParameterRole.OUTPUT)); doReturn(VersionStatus.Certified).when(versionStateMapperMock) - .workflowVersionStateToVersionStatus( - WorkflowVersionState.CERTIFIED); + .workflowVersionStateToVersionStatus(WorkflowVersionState.CERTIFIED); assertEquals(1, workflowVersionManager.list(ITEM1_ID, Collections.singleton(WorkflowVersionState.CERTIFIED)).size()); verify(versioningManagerMock).list(ITEM1_ID); - verify(versionMapperMock, times(1)).versionToWorkflowVersion(any(Version.class)); + verify(versionMapperMock, times(1)).fromVersion(any(Version.class)); } @@ -209,15 +210,18 @@ public class WorkflowVersionManagerImplTest { public void shouldUpdateWorkflowVersion() { doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID); String updatedDescription = "WorkflowVersion description updated"; - Version retrievedVersion = new Version(VERSION1_ID); + InternalVersion retrievedVersion = new InternalVersion(); + retrievedVersion.setId(VERSION1_ID); retrievedVersion.setName("1.0"); retrievedVersion.setDescription("WorkflowVersion description"); retrievedVersion.setStatus(VersionStatus.Draft); VersionState versionState = new VersionState(); versionState.setDirty(true); retrievedVersion.setState(versionState); - doReturn(retrievedVersion).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + doReturn(retrievedVersion).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID); doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(retrievedVersion.getStatus()); + doReturn(Collections.emptyList()).when(parameterRepositoryMock) + .list(ITEM1_ID, VERSION1_ID, ParameterRole.INPUT); WorkflowVersion inputVersion = new WorkflowVersion(VERSION1_ID); inputVersion.setName("1.0"); @@ -226,27 +230,28 @@ public class WorkflowVersionManagerImplTest { inputVersion.setInputs(Collections.singleton(toBeCreated)); ParameterEntity toBeUpdated = new ParameterEntity("Output1"); inputVersion.setOutputs(Collections.singleton(toBeUpdated)); - doReturn(Collections.emptyList()).when(parameterRepositoryMock) - .list(ITEM1_ID, VERSION1_ID, ParameterRole.INPUT); + ParameterEntity toBeDeleted = new ParameterEntity("Output2"); toBeDeleted.setId("parameter_id_1"); Collection<ParameterEntity> currentOutputs = Arrays.asList(toBeDeleted, toBeUpdated); doReturn(currentOutputs).when(parameterRepositoryMock).list(ITEM1_ID, VERSION1_ID, ParameterRole.OUTPUT); - Version mappedInputVersion = new Version(VERSION1_ID); - mappedInputVersion.setName("1.0"); - mappedInputVersion.setDescription(updatedDescription); - doReturn(mappedInputVersion).when(versionMapperMock).workflowVersionToVersion(inputVersion); + doAnswer(invocationOnMock -> { + WorkflowVersion workflowVersion = invocationOnMock.getArgument(0); + Version version = invocationOnMock.getArgument(1); + version.setDescription(workflowVersion.getDescription()); + return null; + }).when(versionMapperMock).toVersion(inputVersion, retrievedVersion); ArgumentCaptor<Version> versionArgCaptor = ArgumentCaptor.forClass(Version.class); workflowVersionManager.update(ITEM1_ID, inputVersion); - verify(versioningManagerMock).updateVersion(eq(ITEM1_ID), versionArgCaptor.capture()); + verify(versioningManagerMock).update(eq(ITEM1_ID), eq(VERSION1_ID), versionArgCaptor.capture()); Version captorVersion = versionArgCaptor.getValue(); assertEquals("1.0", captorVersion.getName()); assertEquals(updatedDescription, captorVersion.getDescription()); assertEquals(VersionStatus.Draft, captorVersion.getStatus()); - verify(versioningManagerMock).publish(ITEM1_ID, mappedInputVersion, "Update version"); + verify(versioningManagerMock).publish(ITEM1_ID, VERSION1_ID, "Update version"); verify(parameterRepositoryMock).delete(ITEM1_ID, VERSION1_ID, "parameter_id_1"); verify(parameterRepositoryMock).create(ITEM1_ID, VERSION1_ID, ParameterRole.INPUT, toBeCreated); @@ -258,17 +263,18 @@ public class WorkflowVersionManagerImplTest { @Test public void shouldCreateWorkflowVersion() { doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID); - Version version = new Version(VERSION1_ID); - version.setDescription("version desc"); - doReturn(version).when(versioningManagerMock).create(ITEM1_ID, version, VersionCreationMethod.major); + Version version = createRetrievedVersion(VERSION1_ID, VersionStatus.Draft); + doReturn(version).when(versioningManagerMock) + .create(eq(ITEM1_ID), isNull(), any(Version.class), eq(VersionCreationMethod.major)); + WorkflowVersion versionRequest = new WorkflowVersion(); versionRequest.setDescription("version desc"); versionRequest.setInputs(Collections.emptyList()); versionRequest.setOutputs(Collections.emptyList()); WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID); doReturn(workflowVersion).when(workflowVersionManager).get(ITEM1_ID, VERSION1_ID); + workflowVersionManager.create(ITEM1_ID, null, versionRequest); - verify(versioningManagerMock).create(ITEM1_ID, version, VersionCreationMethod.major); } @Test(expected = VersionCreationException.class) @@ -276,8 +282,7 @@ public class WorkflowVersionManagerImplTest { doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID); WorkflowVersion versionRequestDto = new WorkflowVersion(); - Version baseVersion = new Version(VERSION2_ID); - baseVersion.setStatus(VersionStatus.Draft); + Version baseVersion = createRetrievedVersion(VERSION2_ID, VersionStatus.Draft); List<Version> versions = Collections.singletonList(baseVersion); doReturn(versions).when(versioningManagerMock).list(ITEM1_ID); @@ -289,25 +294,24 @@ public class WorkflowVersionManagerImplTest { doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID); WorkflowVersion versionRequestDto = new WorkflowVersion(); versionRequestDto.setInputs(Collections.singleton(new ParameterEntity())); - Version baseVersion = new Version(VERSION2_ID); - baseVersion.setStatus(VersionStatus.Draft); + InternalVersion baseVersion = createRetrievedVersion(VERSION2_ID, VersionStatus.Draft); List<Version> versions = Collections.singletonList(baseVersion); doReturn(versions).when(versioningManagerMock).list(ITEM1_ID); workflowVersionManager.create(ITEM1_ID, VERSION2_ID, versionRequestDto); } + @Test(expected = EntityNotFoundException.class) public void getStateOfNonExisting() { - doThrow(new RuntimeException()).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + doThrow(new RuntimeException()).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID); workflowVersionManager.getState(ITEM1_ID, VERSION1_ID); } @Test public void getState() { - Version version = new Version(VERSION1_ID); - version.setStatus(VersionStatus.Certified); - doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + InternalVersion version = createRetrievedVersion(VERSION1_ID, VersionStatus.Certified); + doReturn(version).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID); doReturn(CERTIFIED).when(versionStateMapperMock).versionStatusToWorkflowVersionState(version.getStatus()); WorkflowVersionState state = workflowVersionManager.getState(ITEM1_ID, VERSION1_ID); @@ -316,15 +320,14 @@ public class WorkflowVersionManagerImplTest { @Test(expected = EntityNotFoundException.class) public void updateStateOfNonExisting() { - doThrow(new RuntimeException()).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + doThrow(new RuntimeException()).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID); workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, CERTIFIED); } @Test(expected = VersionStateModificationException.class) public void updateStateToCurrentState() { - Version version = new Version(VERSION1_ID); - version.setStatus(VersionStatus.Draft); - doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + InternalVersion version = createRetrievedVersion(VERSION1_ID, VersionStatus.Draft); + doReturn(version).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID); doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(version.getStatus()); workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, DRAFT); @@ -332,9 +335,8 @@ public class WorkflowVersionManagerImplTest { @Test(expected = VersionStateModificationMissingArtifactException.class) public void updateStateWhenCertified() { - Version version = new Version(VERSION1_ID); - version.setStatus(VersionStatus.Certified); - doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + InternalVersion version = createRetrievedVersion(VERSION1_ID, VersionStatus.Certified); + doReturn(version).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID); doReturn(CERTIFIED).when(versionStateMapperMock).versionStatusToWorkflowVersionState(version.getStatus()); workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, CERTIFIED); @@ -342,9 +344,8 @@ public class WorkflowVersionManagerImplTest { @Test public void shouldFailUpdateStateWhenNoArtifact() { - Version retrievedVersion = new Version(VERSION1_ID); - retrievedVersion.setStatus(VersionStatus.Draft); - doReturn(retrievedVersion).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + InternalVersion retrievedVersion = createRetrievedVersion(VERSION1_ID, VersionStatus.Draft); + doReturn(retrievedVersion).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID); doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(VersionStatus.Draft); exceptionRule.expect(VersionStateModificationMissingArtifactException.class); @@ -353,29 +354,28 @@ public class WorkflowVersionManagerImplTest { ITEM1_ID, VERSION1_ID, DRAFT, CERTIFIED)); workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, CERTIFIED); - verify(versioningManagerMock).submit(eq(ITEM1_ID), eqVersion(VERSION1_ID), anyString()); + verify(versioningManagerMock).updateStatus(ITEM1_ID, VERSION1_ID, VersionStatus.Certified, anyString()); } @Test public void shouldSuccessUpdateStateWhenArtifactExist() { - Version retrievedVersion = new Version(VERSION1_ID); - retrievedVersion.setStatus(VersionStatus.Draft); - doReturn(retrievedVersion).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + InternalVersion retrievedVersion = createRetrievedVersion(VERSION1_ID, VersionStatus.Draft); + doReturn(retrievedVersion).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID); doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(VersionStatus.Draft); doReturn(true).when(artifactRepositoryMock).isExist(ITEM1_ID, VERSION1_ID); workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, CERTIFIED); - verify(versioningManagerMock).submit(eq(ITEM1_ID), eqVersion(VERSION1_ID), anyString()); + verify(versioningManagerMock) + .updateStatus(eq(ITEM1_ID), eq(VERSION1_ID), eq(VersionStatus.Certified), anyString()); } @Test public void shouldUploadArtifact() { doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID); - Version version = new Version(VERSION1_ID); - version.setStatus(VersionStatus.Draft); + InternalVersion version = createRetrievedVersion(VERSION1_ID, VersionStatus.Draft); VersionState versionState = new VersionState(); versionState.setDirty(false); version.setState(versionState); - doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + doReturn(version).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID); doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(version.getStatus()); MockMultipartFile mockFile = new MockMultipartFile("data", "filename.txt", "text/plain", "some xml".getBytes()); @@ -386,7 +386,7 @@ public class WorkflowVersionManagerImplTest { @Test(expected = EntityNotFoundException.class) public void shouldThrowExceptionWhenArtifactNotFound() { - doReturn(new Version(VERSION1_ID)).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + doReturn(new Version()).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID); doReturn(Optional.empty()).when(artifactRepositoryMock).get(ITEM1_ID, VERSION1_ID); workflowVersionManager.getArtifact(ITEM1_ID, VERSION1_ID); @@ -394,7 +394,7 @@ public class WorkflowVersionManagerImplTest { @Test public void shouldReturnArtifact() throws IOException { - doReturn(new Version(VERSION1_ID)).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + doReturn(new Version()).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID); InputStream inputStreamMock = IOUtils.toInputStream("some test data for my input stream", "UTF-8"); ArtifactEntity artifactMock = new ArtifactEntity("fileName.txt", inputStreamMock); @@ -406,40 +406,36 @@ public class WorkflowVersionManagerImplTest { @Test(expected = VersionModificationException.class) public void shouldThrowExceptionInDeleteArtifactWhenVersionIsCertified() { doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID); - Version version = new Version(VERSION1_ID); - doReturn(version).when(versioningManagerMock).get(ITEM1_ID, version); + Version version = new Version(); + doReturn(version).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID); WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID); workflowVersion.setState(WorkflowVersionState.CERTIFIED); - doReturn(workflowVersion).when(versionMapperMock).versionToWorkflowVersion(version); + doReturn(workflowVersion).when(versionMapperMock).fromVersion(version); workflowVersionManager.deleteArtifact(ITEM1_ID, VERSION1_ID); } @Test public void shouldNotDeleteArtifactIfNotExist() { doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID); - Version version = new Version(VERSION1_ID); - doReturn(version).when(versioningManagerMock).get(ITEM1_ID, version); + Version version = new Version(); + doReturn(version).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID); WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID); - doReturn(workflowVersion).when(versionMapperMock).versionToWorkflowVersion(version); + doReturn(workflowVersion).when(versionMapperMock).fromVersion(version); workflowVersionManager.deleteArtifact(ITEM1_ID, VERSION1_ID); verify(artifactRepositoryMock, times(0)).delete(ITEM1_ID, VERSION1_ID); - verify(versioningManagerMock, times(0)).publish(ITEM1_ID, version, "Delete Artifact"); + verify(versioningManagerMock, times(0)).publish(ITEM1_ID, VERSION1_ID, "Delete Artifact"); } @Test public void shouldDeleteArtifactIfExist() { doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID); - Version version = new Version(VERSION1_ID); - doReturn(version).when(versioningManagerMock).get(ITEM1_ID, version); + Version version = new Version(); + doReturn(version).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID); WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID); doReturn(true).when(artifactRepositoryMock).isExist(ITEM1_ID, VERSION1_ID); - doReturn(workflowVersion).when(versionMapperMock).versionToWorkflowVersion(version); + doReturn(workflowVersion).when(versionMapperMock).fromVersion(version); workflowVersionManager.deleteArtifact(ITEM1_ID, VERSION1_ID); verify(artifactRepositoryMock, times(1)).delete(ITEM1_ID, VERSION1_ID); - verify(versioningManagerMock, times(1)).publish(ITEM1_ID, version, "Delete Artifact"); - } - - private static Version eqVersion(String versionId) { - return argThat(version -> versionId.equals(version.getId())); + verify(versioningManagerMock, times(1)).publish(ITEM1_ID, VERSION1_ID, "Delete Artifact"); } } diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapperTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapperTest.java index 0bf4c1f0..8bffc3e1 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapperTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapperTest.java @@ -21,10 +21,11 @@ import static org.junit.Assert.assertEquals; import java.util.Date; import org.junit.Test; import org.junit.runner.RunWith; +import org.onap.sdc.common.versioning.persistence.types.InternalVersion; +import org.onap.sdc.common.versioning.services.types.Version; +import org.onap.sdc.common.versioning.services.types.VersionStatus; import org.onap.sdc.workflow.services.types.WorkflowVersion; import org.onap.sdc.workflow.services.types.WorkflowVersionState; -import org.openecomp.sdc.versioning.dao.types.Version; -import org.openecomp.sdc.versioning.dao.types.VersionStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -42,11 +43,10 @@ public class VersionMapperTest { @Autowired VersionMapper versionMapper; - @Test public void shouldMapVersionToWorkflowVersion() { Version version = createVersion(); - WorkflowVersion mappedWorkflowVersion = versionMapper.versionToWorkflowVersion(version); + WorkflowVersion mappedWorkflowVersion = versionMapper.fromVersion(version); assertEquals(mappedWorkflowVersion.getId(), version.getId()); assertEquals(mappedWorkflowVersion.getBaseId(), version.getBaseId()); assertEquals(mappedWorkflowVersion.getDescription(), version.getDescription()); @@ -58,18 +58,15 @@ public class VersionMapperTest { @Test public void shouldMapWorkflowVersionToVersion() { WorkflowVersion workflowVersion = createWorkflowVersion(); - Version mappedVersion = versionMapper.workflowVersionToVersion(workflowVersion); - assertEquals(mappedVersion.getId(), workflowVersion.getId()); - assertEquals(mappedVersion.getBaseId(), workflowVersion.getBaseId()); + Version mappedVersion = new Version(); + versionMapper.toVersion(workflowVersion, mappedVersion); assertEquals(mappedVersion.getDescription(), workflowVersion.getDescription()); - assertEquals(mappedVersion.getName(), workflowVersion.getName()); - assertEquals(mappedVersion.getCreationTime(), workflowVersion.getCreationTime()); - assertEquals(mappedVersion.getModificationTime(), workflowVersion.getModificationTime()); } private Version createVersion() { - Version version = new Version("version_id"); + InternalVersion version = new InternalVersion(); + version.setId("version_id"); version.setBaseId("base_version_id"); version.setName("1.0"); version.setCreationTime(new Date()); diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapperTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapperTest.java index ba5c8730..c0804eb8 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapperTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapperTest.java @@ -21,7 +21,7 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.sdc.workflow.services.types.WorkflowVersionState; -import org.openecomp.sdc.versioning.dao.types.VersionStatus; +import org.onap.sdc.common.versioning.services.types.VersionStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -62,13 +62,6 @@ public class VersionStateMapperTest { } @Test - public void shouldMapLockedVersionStatusToWorkflowVersionStatus() { - WorkflowVersionState mappedVersionStatus = - versionStateMapper.versionStatusToWorkflowVersionState(VersionStatus.Locked); - assertEquals(WorkflowVersionState.DRAFT, mappedVersionStatus); - } - - @Test public void shouldMapDeprecatedVersionStatusToWorkflowVersionStatus() { WorkflowVersionState mappedVersionStatus = versionStateMapper.versionStatusToWorkflowVersionState(VersionStatus.Deprecated); diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapperTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapperTest.java index 723a2eff..ef84190a 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapperTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapperTest.java @@ -23,10 +23,11 @@ import static org.onap.sdc.workflow.TestUtil.createWorkflow; import org.junit.Test; import org.junit.runner.RunWith; -import org.onap.sdc.workflow.services.types.Workflow; +import org.onap.sdc.common.versioning.services.types.Item; +import org.onap.sdc.common.versioning.services.types.ItemStatus; +import org.onap.sdc.workflow.services.impl.ItemType; import org.onap.sdc.workflow.services.types.ArchivingStatus; -import org.openecomp.sdc.versioning.types.Item; -import org.openecomp.sdc.versioning.types.ItemStatus; +import org.onap.sdc.workflow.services.types.Workflow; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -48,7 +49,7 @@ public class WorkflowMapperTest { public void shouldMapItemToWorkflow() { Item item = createItem(1, false, true, ItemStatus.ACTIVE); - Workflow mappedWorkflow = workflowMapper.itemToWorkflow(item); + Workflow mappedWorkflow = workflowMapper.fromItem(item); assertEquals(mappedWorkflow.getId(), item.getId()); assertEquals(mappedWorkflow.getDescription(), item.getDescription()); assertEquals(mappedWorkflow.getName(), item.getName()); @@ -59,11 +60,11 @@ public class WorkflowMapperTest { public void shouldMapWorkflowToItem() { Workflow workflow = createWorkflow(1, true, ArchivingStatus.ARCHIVED); - Item mappedItem = workflowMapper.workflowToItem(workflow); - assertEquals(mappedItem.getId(), workflow.getId()); - assertEquals(mappedItem.getDescription(), workflow.getDescription()); - assertEquals(mappedItem.getName(), workflow.getName()); - assertEquals(mappedItem.getStatus().name(), workflow.getArchiving().name()); + Item mappedItem = new Item(); + workflowMapper.toItem(workflow, mappedItem); + assertEquals(ItemType.WORKFLOW.name(), mappedItem.getType()); + assertEquals(workflow.getDescription(), mappedItem.getDescription()); + assertEquals(workflow.getName(), mappedItem.getName()); } } |