UT-asdctool DeleteComponentHandler 19/68019/6
authorSindhuri.A <arcot.sindhuri@huawei.com>
Thu, 20 Sep 2018 08:53:06 +0000 (14:23 +0530)
committerMichael Lando <ml636r@att.com>
Tue, 25 Sep 2018 21:00:17 +0000 (21:00 +0000)
UT for asdctool DeleteComponentHandler class

Issue-ID: SDC-1775

Change-Id: Ifc574602d0451ad561a4d362f9d6bd0e4d17ff75
Signed-off-by: Sindhuri.A <arcot.sindhuri@huawei.com>
asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/internal/tool/DeleteComponentHandlerTest.java [new file with mode: 0644]

diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/internal/tool/DeleteComponentHandlerTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/internal/tool/DeleteComponentHandlerTest.java
new file mode 100644 (file)
index 0000000..315f615
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+
+ * Copyright (c) 2018 Huawei Intellectual Property.
+
+ *
+
+ * 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.sdc.asdctool.impl.internal.tool;
+
+import com.thinkaurelius.titan.core.TitanVertex;
+import fj.data.Either;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
+import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
+import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
+import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Scanner;
+
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class DeleteComponentHandlerTest {
+    @InjectMocks
+    private DeleteComponentHandler test;
+
+    @Mock
+    private TitanDao titanDao;
+
+    @Mock
+    private TopologyTemplateOperation topologyTemplateOperation;
+
+    @Mock
+    TopologyTemplate toscaElement;
+
+    @Test
+    public void testDeleteComponent() {
+
+        String input = "yes";
+        InputStream in = new ByteArrayInputStream(input.getBytes());
+        Scanner scanner = new Scanner(in);
+        String id = "start";
+        GraphVertex loc = new GraphVertex();
+        TitanVertex vertex = Mockito.mock(TitanVertex.class);
+        loc.setVertex(vertex);
+
+        Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
+        metadataProperties.put(GraphPropertyEnum.USERID, loc.getUniqueId());
+        metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
+        metadataProperties.put(GraphPropertyEnum.NAME, "user1");
+        loc.setMetadataProperties(metadataProperties);
+
+        when(titanDao.getVertexById(id)).thenReturn(Either.left(loc));
+        when(topologyTemplateOperation.deleteToscaElement(ArgumentMatchers.any(GraphVertex.class))).thenReturn(Either.left(toscaElement));
+
+        test.deleteComponent(id,scanner);
+    }
+}