From 901ca72302b79cdbd1ad85e6aadff6a789c6e803 Mon Sep 17 00:00:00 2001 From: "Sindhuri.A" Date: Thu, 20 Sep 2018 14:23:06 +0530 Subject: UT-asdctool DeleteComponentHandler UT for asdctool DeleteComponentHandler class Issue-ID: SDC-1775 Change-Id: Ifc574602d0451ad561a4d362f9d6bd0e4d17ff75 Signed-off-by: Sindhuri.A --- .../internal/tool/DeleteComponentHandlerTest.java | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/internal/tool/DeleteComponentHandlerTest.java 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 index 0000000000..315f615fb4 --- /dev/null +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/internal/tool/DeleteComponentHandlerTest.java @@ -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 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); + } +} -- cgit 1.2.3-korg