Upgrade SDC from Titan to Janus Graph
[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 org.janusgraph.core.JanusGraphVertex;
33 import fj.data.Either;
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 import java.io.ByteArrayInputStream;
48 import java.io.InputStream;
49 import java.util.HashMap;
50 import java.util.Map;
51 import java.util.Scanner;
52
53 import static org.mockito.Mockito.when;
54
55 @RunWith(MockitoJUnitRunner.class)
56 public class DeleteComponentHandlerTest {
57     @InjectMocks
58     private DeleteComponentHandler test;
59
60     @Mock
61     private JanusGraphDao janusGraphDao;
62
63     @Mock
64     private TopologyTemplateOperation topologyTemplateOperation;
65
66     @Mock
67     TopologyTemplate toscaElement;
68
69     @Test
70     public void testDeleteComponent() {
71
72         String input = "yes";
73         InputStream in = new ByteArrayInputStream(input.getBytes());
74         Scanner scanner = new Scanner(in);
75         String id = "start";
76         GraphVertex loc = new GraphVertex();
77         JanusGraphVertex vertex = Mockito.mock(JanusGraphVertex.class);
78         loc.setVertex(vertex);
79
80         Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
81         metadataProperties.put(GraphPropertyEnum.USERID, loc.getUniqueId());
82         metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
83         metadataProperties.put(GraphPropertyEnum.NAME, "user1");
84         loc.setMetadataProperties(metadataProperties);
85
86         when(janusGraphDao.getVertexById(id)).thenReturn(Either.left(loc));
87         when(topologyTemplateOperation.deleteToscaElement(ArgumentMatchers.any(GraphVertex.class))).thenReturn(Either.left(toscaElement));
88
89         test.deleteComponent(id,scanner);
90     }
91 }