Added oparent to sdc main
[sdc.git] / asdctool / src / test / java / org / openecomp / sdc / asdctool / impl / validator / tasks / moduleJson / ModuleJsonTaskTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.asdctool.impl.validator.tasks.moduleJson;
22
23 import fj.data.Either;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.mockito.ArgumentMatchers;
27 import org.mockito.InjectMocks;
28 import org.mockito.Mock;
29 import org.mockito.junit.MockitoJUnitRunner;
30 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
31 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
32 import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition;
33 import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
34 import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
35 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
36 import org.openecomp.sdc.be.model.ComponentParametersView;
37 import org.openecomp.sdc.be.model.LifecycleStateEnum;
38 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
39 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.TopologyTemplateOperation;
40
41 import java.util.HashMap;
42 import java.util.Map;
43
44 import static org.mockito.Mockito.when;
45
46 @RunWith(MockitoJUnitRunner.class)
47 public class ModuleJsonTaskTest {
48
49     @InjectMocks
50     private ModuleJsonTask test;
51     @Mock
52     private TopologyTemplateOperation topologyTemplateOperation;
53
54     @Test
55     public void testValidate() {
56         GraphVertex vertex = new GraphVertex();
57         vertex.setUniqueId("uniqueId");
58         Map<GraphPropertyEnum, Object> hasProps1 = new HashMap<>();
59         hasProps1.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
60         vertex.setMetadataProperties(hasProps1);
61
62         Map<String, ArtifactDataDefinition> mapDataDefinition = new HashMap<>();
63         ArtifactDataDefinition artifactDataDefinition = new ArtifactDataDefinition();
64         artifactDataDefinition.setArtifactName("one_modules.json");
65         mapDataDefinition.put("one", artifactDataDefinition);
66         MapGroupsDataDefinition mapGroupsDataDefinition = new MapGroupsDataDefinition();
67         Map<String, GroupInstanceDataDefinition> mapToscaDataDefinition = new HashMap<>();
68         mapToscaDataDefinition.put("one", new GroupInstanceDataDefinition());
69         mapGroupsDataDefinition.setMapToscaDataDefinition(mapToscaDataDefinition);
70
71         Map<String, MapGroupsDataDefinition> instGroups = new HashMap<>();
72         instGroups.put("one", mapGroupsDataDefinition);
73
74         Map<String, MapArtifactDataDefinition> instDeploymentArtifacts = new HashMap<>();
75         MapArtifactDataDefinition mapArtifactDataDefinition = new MapArtifactDataDefinition();
76
77         mapArtifactDataDefinition.setMapToscaDataDefinition(mapDataDefinition);
78         instDeploymentArtifacts.put("one", mapArtifactDataDefinition);
79
80         TopologyTemplate topologyTemplate = new TopologyTemplate();
81         topologyTemplate.setInstGroups(instGroups);
82         topologyTemplate.setInstDeploymentArtifacts(instDeploymentArtifacts);
83         when(topologyTemplateOperation.getToscaElement(ArgumentMatchers.eq(vertex.getUniqueId()), ArgumentMatchers.any(ComponentParametersView.class))).thenReturn(Either.left(topologyTemplate));
84         try {
85             test.validate(vertex);
86         } catch (Exception e) {
87
88         }
89     }
90 }