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.
31 package org.openecomp.sdc.asdctool.impl.internal.tool;
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;
52 import static org.mockito.ArgumentMatchers.any;
53 import static org.mockito.Mockito.when;
55 @RunWith(MockitoJUnitRunner.class)
56 public class CsarGeneratorTest {
58 private CsarGenerator test;
61 private JanusGraphDao janusGraphDao;
64 private Component component;
67 ToscaOperationFacade toscaOperationFacade;
70 public void testGenerateCsar() {
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);
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);
86 when(janusGraphDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, props)).thenReturn(Either.left(list));
87 when(toscaOperationFacade.getToscaFullElement(any(String.class))).thenReturn(Either.left(component));
89 .getChildVertex(graphVertex, EdgeLabelEnum.TOSCA_ARTIFACTS, JsonParseFlagEnum.ParseJson)).thenReturn(Either.left(graphVertex));
91 test.generateCsar(uuid,scanner);