From ce0558f2df8e85f3f10df1676bb06bf3b68e683f Mon Sep 17 00:00:00 2001 From: "Sindhuri.A" Date: Tue, 16 Oct 2018 19:34:41 +0530 Subject: UT-asdctool ModuleJsonTask UT for asdctool impl validator ModuleJsonTask class Issue-ID: SDC-1775 Change-Id: Ia160c4b2b64313bd11927aaa45bf887ed3df96df Signed-off-by: Sindhuri.A --- .../tasks/moduleJson/ModuleJsonTaskTest.java | 73 ++++++++++++++++++---- 1 file changed, 60 insertions(+), 13 deletions(-) diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTaskTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTaskTest.java index 5a55742eab..5799b6d03d 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTaskTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTaskTest.java @@ -1,23 +1,70 @@ package org.openecomp.sdc.asdctool.impl.validator.tasks.moduleJson; +import fj.data.Either; import org.junit.Test; -import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult; +import org.junit.runner.RunWith; +import org.mockito.ArgumentMatchers; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition; +import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; +import org.openecomp.sdc.be.model.ComponentParametersView; +import org.openecomp.sdc.be.model.LifecycleStateEnum; +import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate; +import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation; +import java.util.HashMap; +import java.util.Map; + +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) public class ModuleJsonTaskTest { - private ModuleJsonTask createTestSubject() { - return new ModuleJsonTask(); - } + @InjectMocks + private ModuleJsonTask test; + @Mock + private TopologyTemplateOperation topologyTemplateOperation; + + @Test + public void testValidate() { + GraphVertex vertex = new GraphVertex(); + vertex.setUniqueId("uniqueId"); + Map hasProps1 = new HashMap<>(); + hasProps1.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); + vertex.setMetadataProperties(hasProps1); + + Map mapDataDefinition = new HashMap<>(); + ArtifactDataDefinition artifactDataDefinition = new ArtifactDataDefinition(); + artifactDataDefinition.setArtifactName("one_modules.json"); + mapDataDefinition.put("one", artifactDataDefinition); + MapGroupsDataDefinition mapGroupsDataDefinition = new MapGroupsDataDefinition(); + Map mapToscaDataDefinition = new HashMap<>(); + mapToscaDataDefinition.put("one", new GroupInstanceDataDefinition()); + mapGroupsDataDefinition.setMapToscaDataDefinition(mapToscaDataDefinition); + + Map instGroups = new HashMap<>(); + instGroups.put("one", mapGroupsDataDefinition); + + Map instDeploymentArtifacts = new HashMap<>(); + MapArtifactDataDefinition mapArtifactDataDefinition = new MapArtifactDataDefinition(); + + mapArtifactDataDefinition.setMapToscaDataDefinition(mapDataDefinition); + instDeploymentArtifacts.put("one", mapArtifactDataDefinition); - @Test(expected=NullPointerException.class) - public void testValidate() throws Exception { - ModuleJsonTask testSubject; - GraphVertex vertex = null; - VertexResult result; + TopologyTemplate topologyTemplate = new TopologyTemplate(); + topologyTemplate.setInstGroups(instGroups); + topologyTemplate.setInstDeploymentArtifacts(instDeploymentArtifacts); + when(topologyTemplateOperation.getToscaElement(ArgumentMatchers.eq(vertex.getUniqueId()), ArgumentMatchers.any(ComponentParametersView.class))).thenReturn(Either.left(topologyTemplate)); + try { + test.validate(vertex); + } catch (Exception e) { - // default test - testSubject = createTestSubject(); - result = testSubject.validate(vertex); - } + } + } } \ No newline at end of file -- cgit 1.2.3-korg