3 * Copyright (c) 2018 Huawei Intellectual Property.
7 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
19 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS,
23 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
27 * limitations under the License.
30 package org.openecomp.sdc.asdctool.impl.internal.tool;
32 import fj.data.Either;
33 import org.janusgraph.core.JanusGraphVertex;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.ArgumentMatchers;
37 import org.mockito.InjectMocks;
38 import org.mockito.Mock;
39 import org.mockito.Mockito;
40 import org.mockito.junit.MockitoJUnitRunner;
41 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
42 import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
43 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
44 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
45 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
46 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.TopologyTemplateOperation;
48 import java.io.ByteArrayInputStream;
49 import java.io.InputStream;
50 import java.util.HashMap;
52 import java.util.Scanner;
54 import static org.mockito.Mockito.when;
56 @RunWith(MockitoJUnitRunner.class)
57 public class DeleteComponentHandlerTest {
59 private DeleteComponentHandler test;
62 private JanusGraphDao janusGraphDao;
65 private TopologyTemplateOperation topologyTemplateOperation;
68 TopologyTemplate toscaElement;
71 public void testDeleteComponent() {
74 InputStream in = new ByteArrayInputStream(input.getBytes());
75 Scanner scanner = new Scanner(in);
77 GraphVertex loc = new GraphVertex();
78 JanusGraphVertex vertex = Mockito.mock(JanusGraphVertex.class);
79 loc.setVertex(vertex);
81 Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
82 metadataProperties.put(GraphPropertyEnum.USERID, loc.getUniqueId());
83 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
84 metadataProperties.put(GraphPropertyEnum.NAME, "user1");
85 loc.setMetadataProperties(metadataProperties);
87 when(janusGraphDao.getVertexById(id)).thenReturn(Either.left(loc));
88 when(topologyTemplateOperation.deleteToscaElement(ArgumentMatchers.any(GraphVertex.class))).thenReturn(Either.left(toscaElement));
90 test.deleteComponent(id,scanner);