Remove usage of outdated library JMockit (catalog-model)
[sdc.git] / catalog-model / src / test / java / org / openecomp / sdc / be / model / GroupInstanceTest.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.be.model;
22
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.LinkedList;
26 import java.util.List;
27 import java.util.Map;
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;
32
33 class GroupInstanceTest {
34
35     private GroupInstance createTestSubject() {
36         return new GroupInstance();
37     }
38
39     @Test
40     void testCtor() throws Exception {
41         Assertions.assertNotNull(new GroupInstance(new GroupInstanceDataDefinition()));
42     }
43
44     @Test
45     void testConvertToGroupInstancesProperties() throws Exception {
46         final GroupInstance testSubject = createTestSubject();
47         List<GroupInstanceProperty> result;
48
49         result = testSubject.convertToGroupInstancesProperties();
50         Assertions.assertNull(result);
51
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());
58     }
59
60     @Test
61     void testConvertFromGroupInstancesProperties() throws Exception {
62         final GroupInstance testSubject = createTestSubject();
63         List<GroupInstanceProperty> groupInstancesProperties = null;
64
65         groupInstancesProperties = null;
66         testSubject.convertFromGroupInstancesProperties(groupInstancesProperties);
67         List<PropertyDataDefinition> properties = testSubject.getProperties();
68         Assertions.assertNull(properties);
69
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());
76     }
77
78     @Test
79     void testAlignArtifactsUuid() throws Exception {
80         final GroupInstance testSubject = createTestSubject();
81         Map<String, ArtifactDefinition> deploymentArtifacts = null;
82
83         testSubject.alignArtifactsUuid(deploymentArtifacts);
84         Assertions.assertNull(testSubject.getArtifacts());
85
86         deploymentArtifacts = new HashMap<>();
87
88         final List<String> artifacts = new ArrayList<>();
89         artifacts.add("mock1");
90         testSubject.setArtifacts(artifacts);
91
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());
102
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());
113
114         testSubject.setArtifactsUuid(null);
115         testSubject.alignArtifactsUuid(deploymentArtifacts);
116         artifactsUuid = testSubject.getArtifactsUuid();
117         Assertions.assertNotNull(artifactsUuid);
118         Assertions.assertTrue(artifactsUuid.isEmpty());
119
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());
128
129         testSubject.setGroupInstanceArtifactsUuid(groupInstanceArtifacts);
130         testSubject.alignArtifactsUuid(deploymentArtifacts);
131         groupInstanceArtifactsUuid = testSubject.getGroupInstanceArtifactsUuid();
132         Assertions.assertNotNull(groupInstanceArtifactsUuid);
133         Assertions.assertFalse(groupInstanceArtifactsUuid.isEmpty());
134     }
135
136 }