Upgrade SDC from Titan to Janus Graph
[sdc.git] / asdctool / src / test / java / org / openecomp / sdc / asdctool / impl / internal / tool / CsarGeneratorTest.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
31 package org.openecomp.sdc.asdctool.impl.internal.tool;
32
33 import fj.data.Either;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.InjectMocks;
37 import org.mockito.Mock;
38 import org.mockito.junit.MockitoJUnitRunner;
39 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
40 import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
41 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
42 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
43 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
44 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
45 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
46 import org.openecomp.sdc.be.model.Component;
47 import org.openecomp.sdc.be.model.LifecycleStateEnum;
48 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
49 import java.io.ByteArrayInputStream;
50 import java.io.InputStream;
51 import java.util.*;
52 import static org.mockito.ArgumentMatchers.any;
53 import static org.mockito.Mockito.when;
54
55 @RunWith(MockitoJUnitRunner.class)
56 public class CsarGeneratorTest {
57     @InjectMocks
58     private CsarGenerator test;
59
60     @Mock
61     private JanusGraphDao janusGraphDao;
62
63     @Mock
64     private Component component;
65
66     @Mock
67     ToscaOperationFacade toscaOperationFacade;
68
69     @Test
70     public void testGenerateCsar() {
71         String uuid = "yes";
72         InputStream in = new ByteArrayInputStream(uuid.getBytes());
73         Scanner scanner = new Scanner(in);
74         String uniqueId = "123";
75         List<GraphVertex> list = new ArrayList<>();
76         GraphVertex graphVertex = new GraphVertex();
77         graphVertex.setUniqueId(uniqueId);
78         list.add(graphVertex);
79
80         Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class);
81         props.put(GraphPropertyEnum.UUID, uuid);
82         props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
83         props.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
84         graphVertex.setMetadataProperties(props);
85
86         when(janusGraphDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, props)).thenReturn(Either.left(list));
87         when(toscaOperationFacade.getToscaFullElement(any(String.class))).thenReturn(Either.left(component));
88         when(janusGraphDao
89             .getChildVertex(graphVertex, EdgeLabelEnum.TOSCA_ARTIFACTS, JsonParseFlagEnum.ParseJson)).thenReturn(Either.left(graphVertex));
90
91         test.generateCsar(uuid,scanner);
92     }
93 }