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.be.model;
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.LinkedList;
26 import java.util.List;
28 import org.junit.jupiter.api.Assertions;
29 import org.junit.jupiter.api.Test;
30 import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition;
31 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
33 class GroupInstanceTest {
35 private GroupInstance createTestSubject() {
36 return new GroupInstance();
40 void testCtor() throws Exception {
41 Assertions.assertNotNull(new GroupInstance(new GroupInstanceDataDefinition()));
45 void testConvertToGroupInstancesProperties() throws Exception {
46 final GroupInstance testSubject = createTestSubject();
47 List<GroupInstanceProperty> result;
49 result = testSubject.convertToGroupInstancesProperties();
50 Assertions.assertNull(result);
52 final List<PropertyDataDefinition> properties = new LinkedList<>();
53 properties.add(new PropertyDataDefinition());
54 testSubject.setProperties(properties);
55 result = testSubject.convertToGroupInstancesProperties();
56 Assertions.assertNotNull(result);
57 Assertions.assertFalse(result.isEmpty());
61 void testConvertFromGroupInstancesProperties() throws Exception {
62 final GroupInstance testSubject = createTestSubject();
63 List<GroupInstanceProperty> groupInstancesProperties = null;
65 groupInstancesProperties = null;
66 testSubject.convertFromGroupInstancesProperties(groupInstancesProperties);
67 List<PropertyDataDefinition> properties = testSubject.getProperties();
68 Assertions.assertNull(properties);
70 groupInstancesProperties = new LinkedList<>();
71 groupInstancesProperties.add(new GroupInstanceProperty());
72 testSubject.convertFromGroupInstancesProperties(groupInstancesProperties);
73 properties = testSubject.getProperties();
74 Assertions.assertNotNull(properties);
75 Assertions.assertFalse(properties.isEmpty());
79 void testAlignArtifactsUuid() throws Exception {
80 final GroupInstance testSubject = createTestSubject();
81 Map<String, ArtifactDefinition> deploymentArtifacts = null;
83 testSubject.alignArtifactsUuid(deploymentArtifacts);
84 Assertions.assertNull(testSubject.getArtifacts());
86 deploymentArtifacts = new HashMap<>();
88 final List<String> artifacts = new ArrayList<>();
89 artifacts.add("mock1");
90 testSubject.setArtifacts(artifacts);
92 final List<String> artifactUuids = new ArrayList<>();
93 artifactUuids.add("mock1");
94 testSubject.setArtifactsUuid(artifactUuids);
95 final var artifactDefinition = new ArtifactDefinition();
96 artifactDefinition.setArtifactUUID("mock1");
97 deploymentArtifacts.put("mock1", artifactDefinition);
98 testSubject.alignArtifactsUuid(deploymentArtifacts);
99 List<String> groupInstanceArtifactsUuid = testSubject.getGroupInstanceArtifactsUuid();
100 Assertions.assertNotNull(groupInstanceArtifactsUuid);
101 Assertions.assertTrue(groupInstanceArtifactsUuid.isEmpty());
103 artifactDefinition.setArtifactUUID("mock2");
104 artifactDefinition.setArtifactType("HEAT_ENV");
105 deploymentArtifacts.put("mock2", artifactDefinition);
106 testSubject.alignArtifactsUuid(deploymentArtifacts);
107 groupInstanceArtifactsUuid = testSubject.getGroupInstanceArtifactsUuid();
108 Assertions.assertNotNull(groupInstanceArtifactsUuid);
109 Assertions.assertFalse(groupInstanceArtifactsUuid.isEmpty());
110 List<String> artifactsUuid = testSubject.getArtifactsUuid();
111 Assertions.assertNotNull(artifactsUuid);
112 Assertions.assertTrue(artifactsUuid.isEmpty());
114 testSubject.setArtifactsUuid(null);
115 testSubject.alignArtifactsUuid(deploymentArtifacts);
116 artifactsUuid = testSubject.getArtifactsUuid();
117 Assertions.assertNotNull(artifactsUuid);
118 Assertions.assertTrue(artifactsUuid.isEmpty());
120 List<String> groupInstanceArtifacts = new ArrayList<>();
121 groupInstanceArtifacts.add("mock1");
122 testSubject.setGroupInstanceArtifacts(groupInstanceArtifacts);
123 testSubject.setGroupInstanceArtifactsUuid(null);
124 testSubject.alignArtifactsUuid(deploymentArtifacts);
125 groupInstanceArtifactsUuid = testSubject.getGroupInstanceArtifactsUuid();
126 Assertions.assertNotNull(groupInstanceArtifactsUuid);
127 Assertions.assertFalse(groupInstanceArtifactsUuid.isEmpty());
129 testSubject.setGroupInstanceArtifactsUuid(groupInstanceArtifacts);
130 testSubject.alignArtifactsUuid(deploymentArtifacts);
131 groupInstanceArtifactsUuid = testSubject.getGroupInstanceArtifactsUuid();
132 Assertions.assertNotNull(groupInstanceArtifactsUuid);
133 Assertions.assertFalse(groupInstanceArtifactsUuid.isEmpty());