summaryrefslogtreecommitdiffstats
path: root/catalog-model/src
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model/src')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupInstance.java54
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/GroupInstanceTest.java210
2 files changed, 136 insertions, 128 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupInstance.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupInstance.java
index 386febdf86..331b407328 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupInstance.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupInstance.java
@@ -40,7 +40,7 @@ public class GroupInstance extends GroupInstanceDataDefinition {
super();
}
- public GroupInstance(GroupInstanceDataDefinition r) {
+ public GroupInstance(final GroupInstanceDataDefinition r) {
super(r);
}
@@ -50,12 +50,11 @@ public class GroupInstance extends GroupInstanceDataDefinition {
* @return
*/
public List<GroupInstanceProperty> convertToGroupInstancesProperties() {
- List<GroupInstanceProperty> groupInstancesProperties = null;
- List<PropertyDataDefinition> propertiesList = super.getProperties();
- if (propertiesList != null && !propertiesList.isEmpty()) {
- groupInstancesProperties = propertiesList.stream().map(GroupInstanceProperty::new).collect(Collectors.toList());
+ final List<PropertyDataDefinition> propertiesList = super.getProperties();
+ if (CollectionUtils.isNotEmpty(propertiesList)) {
+ return propertiesList.stream().map(GroupInstanceProperty::new).collect(Collectors.toList());
}
- return groupInstancesProperties;
+ return null;
}
/**
@@ -64,23 +63,22 @@ public class GroupInstance extends GroupInstanceDataDefinition {
*
* @param groupInstancesProperties
*/
- public void convertFromGroupInstancesProperties(List<GroupInstanceProperty> groupInstancesProperties) {
+ public void convertFromGroupInstancesProperties(final List<GroupInstanceProperty> groupInstancesProperties) {
if (groupInstancesProperties != null && !groupInstancesProperties.isEmpty()) {
- List<PropertyDataDefinition> propList = groupInstancesProperties.stream().map(PropertyDataDefinition::new).collect(Collectors.toList());
- super.setProperties(propList);
+ super.setProperties(groupInstancesProperties.stream().map(PropertyDataDefinition::new).collect(Collectors.toList()));
}
}
private void removeArtifactsDuplicates() {
- List<String> artifacts = getArtifacts();
- Set<String> artifactsSet = new HashSet<>();
+ final List<String> artifacts = getArtifacts();
+ final Set<String> artifactsSet = new HashSet<>();
if (artifacts != null && !artifacts.isEmpty()) {
artifactsSet.addAll(artifacts);
artifacts.clear();
artifacts.addAll(artifactsSet);
}
- List<String> giArtifacts = getGroupInstanceArtifacts();
- Set<String> giArtifactsSet = new HashSet<>();
+ final List<String> giArtifacts = getGroupInstanceArtifacts();
+ final Set<String> giArtifactsSet = new HashSet<>();
if (giArtifacts != null && !giArtifacts.isEmpty()) {
giArtifactsSet.addAll(giArtifacts);
giArtifacts.clear();
@@ -89,16 +87,16 @@ public class GroupInstance extends GroupInstanceDataDefinition {
}
private void clearArtifactsUuid() {
- List<String> artifactsUuid = getArtifactsUuid();
+ final List<String> artifactsUuid = getArtifactsUuid();
if (CollectionUtils.isNotEmpty(artifactsUuid)) {
artifactsUuid.clear();
} else if (artifactsUuid == null) {
setArtifactsUuid(new ArrayList<>());
}
- List<String> giartifactsUuid = this.getGroupInstanceArtifactsUuid();
- if (CollectionUtils.isNotEmpty(giartifactsUuid)) {
- giartifactsUuid.clear();
- } else if (giartifactsUuid == null) {
+ final List<String> groupInstanceArtifactsUuid = this.getGroupInstanceArtifactsUuid();
+ if (CollectionUtils.isNotEmpty(groupInstanceArtifactsUuid)) {
+ groupInstanceArtifactsUuid.clear();
+ } else if (groupInstanceArtifactsUuid == null) {
setGroupInstanceArtifactsUuid(new ArrayList<>());
}
}
@@ -108,19 +106,19 @@ public class GroupInstance extends GroupInstanceDataDefinition {
*
* @param deploymentArtifacts
*/
- public void alignArtifactsUuid(Map<String, ArtifactDefinition> deploymentArtifacts) {
- List<String> artifactIds = getArtifacts();
+ public void alignArtifactsUuid(final Map<String, ArtifactDefinition> deploymentArtifacts) {
+ final List<String> artifactIds = getArtifacts();
log.debug("the artifacts Id's are: {}, and the deployment artifacts Id's are: {}", artifactIds, deploymentArtifacts);
if (CollectionUtils.isNotEmpty(artifactIds) && deploymentArtifacts != null) {
removeArtifactsDuplicates();
clearArtifactsUuid();
- List<String> artifactUuids = getArtifactsUuid();
- List<String> giArtifactUuids = getGroupInstanceArtifactsUuid();
- for (String artifactId : artifactIds) {
- String label = artifactId.substring(artifactId.lastIndexOf('.') + 1);
- ArtifactDefinition artifact = deploymentArtifacts.get(label);
+ final List<String> artifactUuids = getArtifactsUuid();
+ final List<String> giArtifactUuids = getGroupInstanceArtifactsUuid();
+ for (final String artifactId : artifactIds) {
+ final var label = artifactId.substring(artifactId.lastIndexOf('.') + 1);
+ final ArtifactDefinition artifact = deploymentArtifacts.get(label);
log.debug("current artifact id: {}, current artifact definition: {}", artifactId, artifact);
- ArtifactTypeEnum artifactType = ArtifactTypeEnum.parse(artifact.getArtifactType());
+ final var artifactType = ArtifactTypeEnum.parse(artifact.getArtifactType());
if (artifactType != ArtifactTypeEnum.HEAT_ENV) {
addArtifactsIdToCollection(artifactUuids, artifact);
} else {
@@ -130,8 +128,8 @@ public class GroupInstance extends GroupInstanceDataDefinition {
}
}
- private void addArtifactsIdToCollection(List<String> artifactUuids, ArtifactDefinition artifact) {
- if (!artifactUuids.contains(artifact.getArtifactUUID()) && StringUtils.isNotEmpty(artifact.getArtifactUUID())) {
+ private void addArtifactsIdToCollection(final List<String> artifactUuids, final ArtifactDefinition artifact) {
+ if (StringUtils.isNotEmpty(artifact.getArtifactUUID()) && !artifactUuids.contains(artifact.getArtifactUUID())) {
artifactUuids.add(artifact.getArtifactUUID());
}
}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/GroupInstanceTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/GroupInstanceTest.java
index 8c306883bf..cda3bcfbef 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/GroupInstanceTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/GroupInstanceTest.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,107 +20,117 @@
package org.openecomp.sdc.be.model;
-import mockit.Deencapsulation;
-import org.junit.Test;
-import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
-
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+
+class GroupInstanceTest {
+
+ private GroupInstance createTestSubject() {
+ return new GroupInstance();
+ }
+
+ @Test
+ void testCtor() throws Exception {
+ Assertions.assertNotNull(new GroupInstance(new GroupInstanceDataDefinition()));
+ }
+
+ @Test
+ void testConvertToGroupInstancesProperties() throws Exception {
+ final GroupInstance testSubject = createTestSubject();
+ List<GroupInstanceProperty> result;
+
+ result = testSubject.convertToGroupInstancesProperties();
+ Assertions.assertNull(result);
+
+ final List<PropertyDataDefinition> properties = new LinkedList<>();
+ properties.add(new PropertyDataDefinition());
+ testSubject.setProperties(properties);
+ result = testSubject.convertToGroupInstancesProperties();
+ Assertions.assertNotNull(result);
+ Assertions.assertFalse(result.isEmpty());
+ }
+
+ @Test
+ void testConvertFromGroupInstancesProperties() throws Exception {
+ final GroupInstance testSubject = createTestSubject();
+ List<GroupInstanceProperty> groupInstancesProperties = null;
+
+ groupInstancesProperties = null;
+ testSubject.convertFromGroupInstancesProperties(groupInstancesProperties);
+ List<PropertyDataDefinition> properties = testSubject.getProperties();
+ Assertions.assertNull(properties);
+
+ groupInstancesProperties = new LinkedList<>();
+ groupInstancesProperties.add(new GroupInstanceProperty());
+ testSubject.convertFromGroupInstancesProperties(groupInstancesProperties);
+ properties = testSubject.getProperties();
+ Assertions.assertNotNull(properties);
+ Assertions.assertFalse(properties.isEmpty());
+ }
+
+ @Test
+ void testAlignArtifactsUuid() throws Exception {
+ final GroupInstance testSubject = createTestSubject();
+ Map<String, ArtifactDefinition> deploymentArtifacts = null;
+
+ testSubject.alignArtifactsUuid(deploymentArtifacts);
+ Assertions.assertNull(testSubject.getArtifacts());
+
+ deploymentArtifacts = new HashMap<>();
+
+ final List<String> artifacts = new ArrayList<>();
+ artifacts.add("mock1");
+ testSubject.setArtifacts(artifacts);
+
+ final List<String> artifactUuids = new ArrayList<>();
+ artifactUuids.add("mock1");
+ testSubject.setArtifactsUuid(artifactUuids);
+ final var artifactDefinition = new ArtifactDefinition();
+ artifactDefinition.setArtifactUUID("mock1");
+ deploymentArtifacts.put("mock1", artifactDefinition);
+ testSubject.alignArtifactsUuid(deploymentArtifacts);
+ List<String> groupInstanceArtifactsUuid = testSubject.getGroupInstanceArtifactsUuid();
+ Assertions.assertNotNull(groupInstanceArtifactsUuid);
+ Assertions.assertTrue(groupInstanceArtifactsUuid.isEmpty());
+
+ artifactDefinition.setArtifactUUID("mock2");
+ artifactDefinition.setArtifactType("HEAT_ENV");
+ deploymentArtifacts.put("mock2", artifactDefinition);
+ testSubject.alignArtifactsUuid(deploymentArtifacts);
+ groupInstanceArtifactsUuid = testSubject.getGroupInstanceArtifactsUuid();
+ Assertions.assertNotNull(groupInstanceArtifactsUuid);
+ Assertions.assertFalse(groupInstanceArtifactsUuid.isEmpty());
+ List<String> artifactsUuid = testSubject.getArtifactsUuid();
+ Assertions.assertNotNull(artifactsUuid);
+ Assertions.assertTrue(artifactsUuid.isEmpty());
+
+ testSubject.setArtifactsUuid(null);
+ testSubject.alignArtifactsUuid(deploymentArtifacts);
+ artifactsUuid = testSubject.getArtifactsUuid();
+ Assertions.assertNotNull(artifactsUuid);
+ Assertions.assertTrue(artifactsUuid.isEmpty());
+
+ List<String> groupInstanceArtifacts = new ArrayList<>();
+ groupInstanceArtifacts.add("mock1");
+ testSubject.setGroupInstanceArtifacts(groupInstanceArtifacts);
+ testSubject.setGroupInstanceArtifactsUuid(null);
+ testSubject.alignArtifactsUuid(deploymentArtifacts);
+ groupInstanceArtifactsUuid = testSubject.getGroupInstanceArtifactsUuid();
+ Assertions.assertNotNull(groupInstanceArtifactsUuid);
+ Assertions.assertFalse(groupInstanceArtifactsUuid.isEmpty());
+
+ testSubject.setGroupInstanceArtifactsUuid(groupInstanceArtifacts);
+ testSubject.alignArtifactsUuid(deploymentArtifacts);
+ groupInstanceArtifactsUuid = testSubject.getGroupInstanceArtifactsUuid();
+ Assertions.assertNotNull(groupInstanceArtifactsUuid);
+ Assertions.assertFalse(groupInstanceArtifactsUuid.isEmpty());
+ }
-public class GroupInstanceTest {
-
- private GroupInstance createTestSubject() {
- return new GroupInstance();
- }
-
- @Test
- public void testCtor() throws Exception {
- new GroupInstance(new GroupInstanceDataDefinition());
- }
-
- @Test
- public void testConvertToGroupInstancesProperties() throws Exception {
- GroupInstance testSubject;
- List<GroupInstanceProperty> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.convertToGroupInstancesProperties();
- List<PropertyDataDefinition> properties = new LinkedList<>();
- properties.add(new PropertyDataDefinition());
- testSubject.setProperties(properties);
- result = testSubject.convertToGroupInstancesProperties();
- }
-
- @Test
- public void testConvertFromGroupInstancesProperties() throws Exception {
- GroupInstance testSubject;
- List<GroupInstanceProperty> groupInstancesProperties = null;
-
- // test 1
- testSubject = createTestSubject();
- groupInstancesProperties = null;
- testSubject.convertFromGroupInstancesProperties(groupInstancesProperties);
- groupInstancesProperties = new LinkedList<>();
- groupInstancesProperties.add(new GroupInstanceProperty());
- testSubject.convertFromGroupInstancesProperties(groupInstancesProperties);
- }
-
- @Test
- public void testRemoveArtifactsDuplicates() throws Exception {
- GroupInstance testSubject;
-
- // default test
- testSubject = createTestSubject();
- Deencapsulation.invoke(testSubject, "removeArtifactsDuplicates");
- LinkedList<String> artifacts = new LinkedList<>();
- artifacts.add("mock");
- testSubject.setArtifacts(artifacts);
- LinkedList<String> groupInstanceArtifacts = new LinkedList<>();
- groupInstanceArtifacts.add("mock");
- testSubject.setGroupInstanceArtifacts(groupInstanceArtifacts);
- Deencapsulation.invoke(testSubject, "removeArtifactsDuplicates");
- }
-
- @Test
- public void testClearArtifactsUuid() throws Exception {
- GroupInstance testSubject;
-
- // default test
- testSubject = createTestSubject();
- Deencapsulation.invoke(testSubject, "clearArtifactsUuid");
- }
-
- @Test
- public void testAlignArtifactsUuid() throws Exception {
- GroupInstance testSubject;
- Map<String, ArtifactDefinition> deploymentArtifacts = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.alignArtifactsUuid(deploymentArtifacts);
- LinkedList<String> artifacts = new LinkedList<>();
- artifacts.add("mock");
- testSubject.setArtifacts(artifacts);
- testSubject.alignArtifactsUuid(deploymentArtifacts);
- deploymentArtifacts = new HashMap<>();
- deploymentArtifacts.put("mock", new ArtifactDefinition());
- testSubject.alignArtifactsUuid(deploymentArtifacts);
- }
-
- @Test
- public void testAddArtifactsIdToCollection() throws Exception {
- GroupInstance testSubject;
- List<String> artifactUuids = new LinkedList<>();
- ArtifactDefinition artifact = new ArtifactDefinition();
-
- // default test
- testSubject = createTestSubject();
- Deencapsulation.invoke(testSubject, "addArtifactsIdToCollection", artifactUuids, artifact);
- artifact.setArtifactUUID("mock");
- Deencapsulation.invoke(testSubject, "addArtifactsIdToCollection", artifactUuids, artifact);
- }
}