2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.asdctool.impl.validator.tasks.moduleJson;
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.asdctool.impl.validator.report.Report;
31 import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult;
32 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
33 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
34 import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition;
35 import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
36 import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
37 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
38 import org.openecomp.sdc.be.model.ComponentParametersView;
39 import org.openecomp.sdc.be.model.LifecycleStateEnum;
40 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
41 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.TopologyTemplateOperation;
43 import java.util.HashMap;
46 import static org.hamcrest.Matchers.is;
47 import static org.junit.Assert.assertThat;
48 import static org.mockito.Mockito.when;
50 @RunWith(MockitoJUnitRunner.class)
51 public class ModuleJsonTaskTest {
54 private ModuleJsonTask test;
56 private TopologyTemplateOperation topologyTemplateOperation;
59 public void testValidate() {
60 GraphVertex vertex = new GraphVertex();
61 vertex.setUniqueId("uniqueId");
62 Map<GraphPropertyEnum, Object> hasProps1 = new HashMap<>();
63 hasProps1.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
64 vertex.setMetadataProperties(hasProps1);
66 Map<String, ArtifactDataDefinition> mapDataDefinition = new HashMap<>();
67 ArtifactDataDefinition artifactDataDefinition = new ArtifactDataDefinition();
68 artifactDataDefinition.setArtifactName("one_modules.json");
69 mapDataDefinition.put("one", artifactDataDefinition);
70 MapGroupsDataDefinition mapGroupsDataDefinition = new MapGroupsDataDefinition();
71 Map<String, GroupInstanceDataDefinition> mapToscaDataDefinition = new HashMap<>();
72 mapToscaDataDefinition.put("one", new GroupInstanceDataDefinition());
73 mapGroupsDataDefinition.setMapToscaDataDefinition(mapToscaDataDefinition);
75 Map<String, MapGroupsDataDefinition> instGroups = new HashMap<>();
76 instGroups.put("one", mapGroupsDataDefinition);
78 Map<String, MapArtifactDataDefinition> instDeploymentArtifacts = new HashMap<>();
79 MapArtifactDataDefinition mapArtifactDataDefinition = new MapArtifactDataDefinition();
81 mapArtifactDataDefinition.setMapToscaDataDefinition(mapDataDefinition);
82 instDeploymentArtifacts.put("one", mapArtifactDataDefinition);
84 TopologyTemplate topologyTemplate = new TopologyTemplate();
85 topologyTemplate.setInstGroups(instGroups);
86 topologyTemplate.setInstDeploymentArtifacts(instDeploymentArtifacts);
87 when(topologyTemplateOperation.getToscaElement(ArgumentMatchers.eq(vertex.getUniqueId()),
88 ArgumentMatchers.any(ComponentParametersView.class))).thenReturn(Either.left(topologyTemplate));
90 // Initially no outputFilePath was passed to this function (hence it is set to null)
91 // TODO: Fix this null and see if the argument is used by this function
93 Report report = Report.make();
94 VertexResult actual = test.validate(report, vertex, null);
95 assertThat(actual.getStatus(), is(true));
96 } catch (Exception e) {
97 // TODO: Fix this test, as currently, any exception is ignored
98 // This will be addressed in another change