Catalog alignment
[sdc.git] / asdctool / src / test / java / org / openecomp / sdc / asdctool / impl / internal / tool / DeleteComponentHandlerTest.java
1 /*
2
3  * Copyright (c) 2018 Huawei Intellectual Property.
4
5  *
6
7  * Licensed under the Apache License, Version 2.0 (the "License");
8
9  * you may not use this file except in compliance with the License.
10
11  * You may obtain a copy of the License at
12
13  *
14
15  *     http://www.apache.org/licenses/LICENSE-2.0
16
17  *
18
19  * Unless required by applicable law or agreed to in writing, software
20
21  * distributed under the License is distributed on an "AS IS" BASIS,
22
23  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
25  * See the License for the specific language governing permissions and
26
27  * limitations under the License.
28
29  */
30 package org.openecomp.sdc.asdctool.impl.internal.tool;
31
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;
47
48 import java.io.ByteArrayInputStream;
49 import java.io.InputStream;
50 import java.util.HashMap;
51 import java.util.Map;
52 import java.util.Scanner;
53
54 import static org.mockito.Mockito.when;
55
56 @RunWith(MockitoJUnitRunner.class)
57 public class DeleteComponentHandlerTest {
58     @InjectMocks
59     private DeleteComponentHandler test;
60
61     @Mock
62     private JanusGraphDao janusGraphDao;
63
64     @Mock
65     private TopologyTemplateOperation topologyTemplateOperation;
66
67     @Mock
68     TopologyTemplate toscaElement;
69
70     @Test
71     public void testDeleteComponent() {
72
73         String input = "yes";
74         InputStream in = new ByteArrayInputStream(input.getBytes());
75         Scanner scanner = new Scanner(in);
76         String id = "start";
77         GraphVertex loc = new GraphVertex();
78         JanusGraphVertex vertex = Mockito.mock(JanusGraphVertex.class);
79         loc.setVertex(vertex);
80
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);
86
87         when(janusGraphDao.getVertexById(id)).thenReturn(Either.left(loc));
88         when(topologyTemplateOperation.deleteToscaElement(ArgumentMatchers.any(GraphVertex.class))).thenReturn(Either.left(toscaElement));
89
90         test.deleteComponent(id,scanner);
91     }
92 }