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.utils.VertexResult;
31 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
32 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
33 import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition;
34 import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
35 import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
36 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
37 import org.openecomp.sdc.be.model.ComponentParametersView;
38 import org.openecomp.sdc.be.model.LifecycleStateEnum;
39 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
40 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.TopologyTemplateOperation;
42 import java.util.HashMap;
45 import static org.hamcrest.Matchers.is;
46 import static org.junit.Assert.assertThat;
47 import static org.mockito.Mockito.when;
49 @RunWith(MockitoJUnitRunner.class)
50 public class ModuleJsonTaskTest {
53 private ModuleJsonTask test;
55 private TopologyTemplateOperation topologyTemplateOperation;
58 public void testValidate() {
59 GraphVertex vertex = new GraphVertex();
60 vertex.setUniqueId("uniqueId");
61 Map<GraphPropertyEnum, Object> hasProps1 = new HashMap<>();
62 hasProps1.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
63 vertex.setMetadataProperties(hasProps1);
65 Map<String, ArtifactDataDefinition> mapDataDefinition = new HashMap<>();
66 ArtifactDataDefinition artifactDataDefinition = new ArtifactDataDefinition();
67 artifactDataDefinition.setArtifactName("one_modules.json");
68 mapDataDefinition.put("one", artifactDataDefinition);
69 MapGroupsDataDefinition mapGroupsDataDefinition = new MapGroupsDataDefinition();
70 Map<String, GroupInstanceDataDefinition> mapToscaDataDefinition = new HashMap<>();
71 mapToscaDataDefinition.put("one", new GroupInstanceDataDefinition());
72 mapGroupsDataDefinition.setMapToscaDataDefinition(mapToscaDataDefinition);
74 Map<String, MapGroupsDataDefinition> instGroups = new HashMap<>();
75 instGroups.put("one", mapGroupsDataDefinition);
77 Map<String, MapArtifactDataDefinition> instDeploymentArtifacts = new HashMap<>();
78 MapArtifactDataDefinition mapArtifactDataDefinition = new MapArtifactDataDefinition();
80 mapArtifactDataDefinition.setMapToscaDataDefinition(mapDataDefinition);
81 instDeploymentArtifacts.put("one", mapArtifactDataDefinition);
83 TopologyTemplate topologyTemplate = new TopologyTemplate();
84 topologyTemplate.setInstGroups(instGroups);
85 topologyTemplate.setInstDeploymentArtifacts(instDeploymentArtifacts);
86 when(topologyTemplateOperation.getToscaElement(ArgumentMatchers.eq(vertex.getUniqueId()),
87 ArgumentMatchers.any(ComponentParametersView.class))).thenReturn(Either.left(topologyTemplate));
89 // Initially no outputFilePath was passed to this function (hence it is set to null)
90 // TODO: Fix this null and see if the argument is used by this function
92 VertexResult actual = test.validate(vertex, null);
93 assertThat(actual.getStatus(), is(true));
94 } catch (Exception e) {
95 // TODO: Fix this test, as currently, any exception is ignored
96 // This will be addressed in another change