summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/test')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java46
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java9
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java5
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java200
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java5
-rw-r--r--catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml15
6 files changed, 203 insertions, 77 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java
index 82b49fffa7..b8bb4a775b 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java
@@ -18,6 +18,8 @@ package org.openecomp.sdc.be.components.impl;
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Optional;
import org.apache.commons.collections.CollectionUtils;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -76,11 +78,14 @@ import java.util.Map;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
@@ -177,6 +182,47 @@ public class PolicyBusinessLogicTest {
PolicyDefinition response = businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
assertTrue(!response.isEmpty());
}
+
+ @Test
+ public void createPolicyFromCsarDefinitionTest() {
+ String prop1 = "Prop_1";
+ String prop2 = "Prop_2";
+ Map<String, PolicyDefinition> policies = new HashMap<>();
+ PolicyDefinition policy = buildPolicy(POLICY_NAME);
+ Map<PolicyTargetType, List<String>> targets = getTargets();
+ PropertyDataDefinition[] properties = getProperties(prop1, prop2);
+ policy.setTargets(targets);
+ policy.setProperties(Arrays.asList(properties));
+ policies.put(POLICY_NAME, policy);
+
+ List<ComponentInstance> instanceList = new ArrayList<>();
+ ComponentInstance componentInstance = new ComponentInstance();
+ componentInstance.setUniqueId(UNIQUE_ID_EXSISTS);
+ componentInstance.setName(UNIQUE_ID_EXSISTS);
+ instanceList.add(componentInstance);
+
+ Resource newResource = buildResource();
+ newResource.setPolicies(policies);
+ newResource.setComponentInstances(instanceList);
+
+ when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME))).thenReturn(getPolicyTypeSuccessEither);
+ when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(Either.left(policy));
+ when(toscaOperationFacade.getToscaFullElement(eq(COMPONENT_ID))).thenReturn(Either.left(newResource));
+ when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(Either.left(policy));
+ when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+ when(propertyOperation.validateAndUpdatePropertyValue(eq(null), eq(prop1), anyBoolean(), eq(null), anyMap())).thenReturn(Either.left(prop1));
+ when(propertyOperation.validateAndUpdatePropertyValue(eq(null), eq(prop2), anyBoolean(), eq(null), anyMap())).thenReturn(Either.left(prop2));
+
+ Map<String, PolicyDefinition> createdPolicy = businessLogic.createPoliciesFromParsedCsar(newResource, policies);
+
+ assertFalse(createdPolicy.isEmpty());
+ PolicyDefinition newPolicy = createdPolicy.get(POLICY_NAME);
+ assertNotNull(newPolicy);
+ assertNotNull(newPolicy.getTargets());
+ assertNotNull(newPolicy.getProperties());
+ assertEquals(2, newPolicy.getProperties().size());
+ assertEquals(1, newPolicy.getTargets().size());
+ }
@Test
public void createPolicyUserFailureTest(){
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java
index 44d1e06477..2baafdc9cb 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java
@@ -22,6 +22,7 @@
package org.openecomp.sdc.be.components.impl;
import com.google.common.collect.ImmutableMap;
+import fj.data.Either;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -122,4 +123,12 @@ public class PolicyTypeBusinessLogicTest {
}
}
+ @Test
+ public void getLatestPolicyTypeByTypeTest() {
+ PolicyTypeDefinition policyTypeDefinition = new PolicyTypeBuilder().setType("org.openecomp.policies.placement.Antilocate").build();
+ when(policyTypeOperation.getLatestPolicyTypeByType("org.openecomp.policies.placement.Antilocate")).thenReturn(
+ Either.left(policyTypeDefinition));
+ assertThat(policyTypeOperation.getLatestPolicyTypeByType("org.openecomp.policies.placement.Antilocate"))
+ .isEqualTo(Either.left(testInstance.getLatestPolicyTypeByType("org.openecomp.policies.placement.Antilocate")));
+ }
} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
index 69b3f1d660..2401c7e772 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
@@ -198,7 +198,7 @@ public class ResourceBusinessLogicTest {
MergeInstanceUtils mergeInstanceUtils = Mockito.mock(MergeInstanceUtils.class);
UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
ToscaExportHandler toscaExportHandler = Mockito.mock(ToscaExportHandler.class);
-
+ PolicyBusinessLogic policyBusinessLogic = Mockito.mock(PolicyBusinessLogic.class);
@InjectMocks
@@ -318,7 +318,8 @@ public class ResourceBusinessLogicTest {
resourceImportManager, inputsBusinessLogic, compositionBusinessLogic, resourceDataMergeBusinessLogic,
csarArtifactsAndGroupsBusinessLogic, mergeInstanceUtils, uiComponentDataConverter, csarBusinessLogic,
artifactToscaOperation, propertyBusinessLogic, componentContactIdValidator, componentNameValidator,
- componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator);
+ componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator,
+ componentDescriptionValidator, policyBusinessLogic);
bl.setElementDao(mockElementDao);
bl.setUserAdmin(mockUserAdmin);
bl.setCapabilityTypeOperation(capabilityTypeOperation);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java
index b63e6ffeb8..1d7a1c5eed 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java
@@ -35,6 +35,7 @@ import org.openecomp.sdc.be.components.csar.CsarInfo;
import org.openecomp.sdc.be.components.csar.YamlTemplateParsingHandler;
import org.openecomp.sdc.be.components.impl.AnnotationBusinessLogic;
import org.openecomp.sdc.be.components.impl.GroupTypeBusinessLogic;
+import org.openecomp.sdc.be.components.impl.PolicyTypeBusinessLogic;
import org.openecomp.sdc.be.components.validation.AnnotationValidator;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
@@ -43,6 +44,8 @@ import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.GroupProperty;
import org.openecomp.sdc.be.model.GroupTypeDefinition;
import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.PolicyTypeDefinition;
import org.openecomp.sdc.be.model.UploadArtifactInfo;
import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
import org.openecomp.sdc.be.model.User;
@@ -58,6 +61,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
+import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
@@ -78,6 +82,8 @@ public class YamlTemplateParsingHandlerTest {
private JanusGraphDao janusGraphDao;
@Mock
private User user;
+ @Mock
+ private PolicyTypeBusinessLogic policyTypeBusinessLogic;
private YamlTemplateParsingHandler handler;
@@ -87,9 +93,13 @@ public class YamlTemplateParsingHandlerTest {
private final static String VFC_GROUP_TYPE = "org.openecomp.groups.VfcInstanceGroup";
private final static String HEAT_GROUP_TYPE = "org.openecomp.groups.heat.HeatStack";
private final static String ROOT_GROUP_TYPE = "tosca.groups.Root";
+ private final static String OPENECOMP_ANTILOCATE_POLICY_TYPE = "org.openecomp.policies.placement.Antilocate";
+ private final static String ROOT_POLICIES_TYPE = "tosca.policies.Root";
private final static GroupTypeDefinition VfcInstanceGroupType = buildVfcInstanceGroupType();
private final static GroupTypeDefinition heatGroupType = buildHeatStackGroupType();
private final static GroupTypeDefinition rootGroupType = buildRootGroupType();
+ private static final PolicyTypeDefinition OPENECOMP_POLICY_TYPE = buildOpenecompPolicyType();
+ private final static String OPENECOMP_POLICY_NAME = "vepdg_server_group_policy";
private final static String CAPABILITY_TYPE = "org.openecomp.capabilities.VLANAssignment";
private final static String CAPABILITY_NAME = "vlan_assignment";
private static final String CSAR_FILE_PATH = "csars/with_groups.csar";
@@ -122,8 +132,10 @@ public class YamlTemplateParsingHandlerTest {
AnnotationBusinessLogic annotationBusinessLogic = new AnnotationBusinessLogic(annotationTypeOperations,
annotationValidator);
- handler = new YamlTemplateParsingHandler(janusGraphDao, groupTypeBusinessLogic, annotationBusinessLogic);
+ handler = new YamlTemplateParsingHandler(janusGraphDao, groupTypeBusinessLogic, annotationBusinessLogic, policyTypeBusinessLogic);
+ ReflectionTestUtils.setField(handler, "policyTypeBusinessLogic", policyTypeBusinessLogic);
stubGetGroupType();
+ stubGetPolicyType();
}
@Test
@@ -148,6 +160,79 @@ public class YamlTemplateParsingHandlerTest {
validateParsedYamlWithCapability(parsedYaml);
}
+ @Test
+ public void testSetArtifacts() {
+ UploadComponentInstanceInfo nodeTemplateInfo = new UploadComponentInstanceInfo();
+ Map<String, Object> nodeTemplateJsonMap = new HashMap<>();
+ Map<String, String> nodeMap = new HashMap<>();
+ nodeMap.put("name","test_name");
+ nodeMap.put("type","test_type");
+ nodeTemplateJsonMap.put(ARTIFACTS.getElementName(), nodeMap);
+ Deencapsulation.invoke(testSubject, "setArtifacts", nodeTemplateInfo, nodeTemplateJsonMap);
+ assertNotNull(nodeTemplateInfo.getArtifacts());
+ }
+
+ @Test
+ public void testCreateArtifactsModuleFromYaml() {
+ Map<String, Map<String, Map<String, String>>> nodeTemplateJsonMap = new HashMap<>();
+ Map<String, Map<String,String>> map0 = new HashMap<>();
+ Map<String, String> map1 = new HashMap<>();
+ map1.put("file", "test_file");
+ map1.put("type", "test_type");
+ map0.put("test_art", map1);
+ nodeTemplateJsonMap.put(ARTIFACTS.getElementName(), map0);
+ Map<String, Map<String, UploadArtifactInfo>> result;
+ result = Deencapsulation.invoke(testSubject, "createArtifactsModuleFromYaml", nodeTemplateJsonMap);
+ Assert.assertTrue(MapUtils.isNotEmpty(result));
+ Assert.assertTrue(MapUtils.isNotEmpty(result.get(ARTIFACTS.getElementName())));
+ Assert.assertEquals("test_file", result.get(ARTIFACTS.getElementName()).get("test_art").getFile());
+ Assert.assertEquals("test_type", result.get(ARTIFACTS.getElementName()).get("test_art").getType());
+ }
+
+ @Test
+ public void testAddModuleNodeTemplateArtifacts() {
+ Map<String, Map<String, UploadArtifactInfo>> result = new HashMap<>();
+ Map<String, String> map1 = new HashMap<>();
+ map1.put("file", "test_file");
+ map1.put("type", "test_type");
+ Deencapsulation.invoke(testSubject, "addModuleNodeTemplateArtifacts", result, map1, "test_art");
+ Assert.assertTrue(MapUtils.isNotEmpty(result));
+ Assert.assertTrue(MapUtils.isNotEmpty(result.get(ARTIFACTS.getElementName())));
+ Assert.assertEquals("test_file", result.get(ARTIFACTS.getElementName()).get("test_art").getFile());
+ Assert.assertEquals("test_type", result.get(ARTIFACTS.getElementName()).get("test_art").getType());
+ }
+
+ @Test
+ public void testBuildModuleNodeTemplateArtifact() {
+ Map<String, String> map1 = new HashMap<>();
+ map1.put("file", "test_file");
+ map1.put("type", "test_type");
+ UploadArtifactInfo result;
+ result = Deencapsulation.invoke(testSubject, "buildModuleNodeTemplateArtifact", map1);
+ assertNotNull(result);
+ Assert.assertEquals("test_file", result.getFile());
+ Assert.assertEquals("test_type", result.getType());
+ }
+
+ @Test
+ public void testFillArtifact() {
+ Map<String, String> map1 = new HashMap<>();
+ map1.put("file", "test_file");
+ map1.put("type", "test_type");
+ UploadArtifactInfo result = new UploadArtifactInfo();
+ Deencapsulation.invoke(testSubject, "fillArtifact", result, map1);
+ assertNotNull(result);
+ Assert.assertEquals("test_file", result.getFile());
+ Assert.assertEquals("test_type", result.getType());
+ }
+
+ @Test
+ public void parseResourceWithPoliciesDefined() {
+ ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
+ new HashMap<>(), "");
+ validateParsedYamlWithPolicies(parsedYaml);
+ }
+
private void validateParsedYaml(ParsedToscaYamlInfo parsedYaml, String group, List<String> expectedProp) {
assertThat(parsedYaml).isNotNull();
assertThat(parsedYaml.getGroups()).isNotNull().containsKey(group);
@@ -155,15 +240,15 @@ public class YamlTemplateParsingHandlerTest {
assertThat(parsedYaml.getGroups().get(group).getProperties()).isNotNull();
assertThat(parsedYaml.getGroups().get(group).getProperties()
- .stream()
- .map(PropertyDataDefinition::getName)
- .collect(Collectors.toList()))
+ .stream()
+ .map(PropertyDataDefinition::getName)
+ .collect(Collectors.toList()))
.containsAll(expectedProp);
assertThat(parsedYaml.getGroups().get(group).getMembers()).isNotNull();
}
- private void validateParsedYamlWithCapability(ParsedToscaYamlInfo parsedYaml) {
+ private void validateParsedYamlWithCapability(ParsedToscaYamlInfo parsedYaml) {
final List<String> expectedProp = Lists.newArrayList("vfc_parent_port_role",
"network_collection_function", "vfc_instance_group_function", "subinterface_role");
@@ -171,23 +256,23 @@ public class YamlTemplateParsingHandlerTest {
validateParsedYaml(parsedYaml, MAIN_GROUP_NAME, expectedProp);
assertThat(parsedYaml.getGroups().get(MAIN_GROUP_NAME).getCapabilities()
- .get(CAPABILITY_TYPE)
- .get(0).getProperties().get(0).getValue()).isEqualTo("success");
+ .get(CAPABILITY_TYPE)
+ .get(0).getProperties().get(0).getValue()).isEqualTo("success");
assertThat(parsedYaml.getGroups().get(MAIN_GROUP_NAME).getCapabilities()).isNotNull();
- }
+ }
- private void stubGetGroupType() {
- when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(VFC_GROUP_TYPE))).thenReturn(VfcInstanceGroupType);
- when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE))).thenReturn(heatGroupType);
+ private void stubGetGroupType() {
+ when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(VFC_GROUP_TYPE))).thenReturn(VfcInstanceGroupType);
+ when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE))).thenReturn(heatGroupType);
when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(ROOT_GROUP_TYPE))).thenReturn(rootGroupType);
}
private static GroupTypeDefinition buildRootGroupType() {
return createGroupTypeDefinition(ROOT_GROUP_TYPE, null,
"The TOSCA Group Type all other TOSCA Group Types derive from");
- }
+ }
- private static GroupTypeDefinition buildHeatStackGroupType() {
+ private static GroupTypeDefinition buildHeatStackGroupType() {
GroupTypeDefinition groupType = createGroupTypeDefinition(HEAT_GROUP_TYPE, "tosca.groups.Root",
"Grouped all heat resources which are in the same heat stack");
@@ -199,9 +284,9 @@ public class YamlTemplateParsingHandlerTest {
groupType.setProperties(Lists.newArrayList(property1, property2));
return groupType;
- }
+ }
- private static GroupTypeDefinition buildVfcInstanceGroupType() {
+ private static GroupTypeDefinition buildVfcInstanceGroupType() {
GroupTypeDefinition groupType = createGroupTypeDefinition(VFC_GROUP_TYPE, "tosca.groups.Root",
"Groups of VFCs with same parent port role");
@@ -250,7 +335,7 @@ public class YamlTemplateParsingHandlerTest {
return property;
}
private static GroupProperty createGroupProperty(String name, String description,
- String status){
+ String status){
GroupProperty property = new GroupProperty();
if (name != null)
property.setName(name);
@@ -268,69 +353,38 @@ public class YamlTemplateParsingHandlerTest {
return property;
}
- @Test
- public void testSetArtifacts() {
- UploadComponentInstanceInfo nodeTemplateInfo = new UploadComponentInstanceInfo();
- Map<String, Object> nodeTemplateJsonMap = new HashMap<>();
- Map<String, String> nodeMap = new HashMap<>();
- nodeMap.put("name","test_name");
- nodeMap.put("type","test_type");
- nodeTemplateJsonMap.put(ARTIFACTS.getElementName(), nodeMap);
- Deencapsulation.invoke(testSubject, "setArtifacts", nodeTemplateInfo, nodeTemplateJsonMap);
- assertNotNull(nodeTemplateInfo.getArtifacts());
- }
- @Test
- public void testCreateArtifactsModuleFromYaml() {
- Map<String, Map<String, Map<String, String>>> nodeTemplateJsonMap = new HashMap<>();
- Map<String, Map<String,String>> map0 = new HashMap<>();
- Map<String, String> map1 = new HashMap<>();
- map1.put("file", "test_file");
- map1.put("type", "test_type");
- map0.put("test_art", map1);
- nodeTemplateJsonMap.put(ARTIFACTS.getElementName(), map0);
- Map<String, Map<String, UploadArtifactInfo>> result;
- result = Deencapsulation.invoke(testSubject, "createArtifactsModuleFromYaml", nodeTemplateJsonMap);
- Assert.assertTrue(MapUtils.isNotEmpty(result));
- Assert.assertTrue(MapUtils.isNotEmpty(result.get(ARTIFACTS.getElementName())));
- Assert.assertEquals("test_file", result.get(ARTIFACTS.getElementName()).get("test_art").getFile());
- Assert.assertEquals("test_type", result.get(ARTIFACTS.getElementName()).get("test_art").getType());
+ private void validateParsedYamlWithPolicies(ParsedToscaYamlInfo parsedYaml) {
+ // validate policies
+ assertThat(parsedYaml.getPolicies()).isNotNull();
+ assertThat(parsedYaml.getPolicies()).containsKey(OPENECOMP_POLICY_NAME);
+ assertThat(parsedYaml.getPolicies().get(OPENECOMP_POLICY_NAME)).isInstanceOf(PolicyDefinition.class);
}
- @Test
- public void testAddModuleNodeTemplateArtifacts() {
- Map<String, Map<String, UploadArtifactInfo>> result = new HashMap<>();
- Map<String, String> map1 = new HashMap<>();
- map1.put("file", "test_file");
- map1.put("type", "test_type");
- Deencapsulation.invoke(testSubject, "addModuleNodeTemplateArtifacts", result, map1, "test_art");
- Assert.assertTrue(MapUtils.isNotEmpty(result));
- Assert.assertTrue(MapUtils.isNotEmpty(result.get(ARTIFACTS.getElementName())));
- Assert.assertEquals("test_file", result.get(ARTIFACTS.getElementName()).get("test_art").getFile());
- Assert.assertEquals("test_type", result.get(ARTIFACTS.getElementName()).get("test_art").getType());
+ private void stubGetPolicyType () {
+ when(policyTypeBusinessLogic.getLatestPolicyTypeByType(eq(OPENECOMP_ANTILOCATE_POLICY_TYPE))).thenReturn(
+ OPENECOMP_POLICY_TYPE);
}
- @Test
- public void testBuildModuleNodeTemplateArtifact() {
- Map<String, String> map1 = new HashMap<>();
- map1.put("file", "test_file");
- map1.put("type", "test_type");
- UploadArtifactInfo result;
- result = Deencapsulation.invoke(testSubject, "buildModuleNodeTemplateArtifact", map1);
- assertNotNull(result);
- Assert.assertEquals("test_file", result.getFile());
- Assert.assertEquals("test_type", result.getType());
+ private static PolicyTypeDefinition buildOpenecompPolicyType() {
+ return createPolicyTypeDefinition(OPENECOMP_POLICY_NAME, OPENECOMP_ANTILOCATE_POLICY_TYPE, ROOT_POLICIES_TYPE,
+ "The Openecomp Antilocate policy");
}
- @Test
- public void testFillArtifact() {
- Map<String, String> map1 = new HashMap<>();
- map1.put("file", "test_file");
- map1.put("type", "test_type");
- UploadArtifactInfo result = new UploadArtifactInfo();
- Deencapsulation.invoke(testSubject, "fillArtifact", result, map1);
- assertNotNull(result);
- Assert.assertEquals("test_file", result.getFile());
- Assert.assertEquals("test_type", result.getType());
+ private static PolicyTypeDefinition createPolicyTypeDefinition(String policyName, String policyType, String derivedFrom, String description) {
+ PolicyTypeDefinition policyTypeDefinition = new PolicyTypeDefinition();
+ if (policyName != null && !policyName.isEmpty()) {
+ policyTypeDefinition.setName(policyName);
+ }
+ if (policyType != null) {
+ policyTypeDefinition.setType(policyType);
+ }
+ if (derivedFrom != null) {
+ policyTypeDefinition.setDerivedFrom(derivedFrom);
+ }
+ if (description != null) {
+ policyTypeDefinition.setDescription(description);
+ }
+ return policyTypeDefinition;
}
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java
index a27c959a2e..48c2c9c2a2 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java
@@ -30,6 +30,7 @@ import org.openecomp.sdc.be.components.csar.CsarBusinessLogic;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.impl.CompositionBusinessLogic;
import org.openecomp.sdc.be.components.impl.InputsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.PolicyBusinessLogic;
import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
@@ -64,7 +65,7 @@ public class CheckoutTest extends LifecycleTestBase {
private final PropertyBusinessLogic propertyBusinessLogic = Mockito.mock(PropertyBusinessLogic.class);
protected ComponentContactIdValidator componentContactIdValidator = new ComponentContactIdValidator(componentsUtils);
protected ComponentNameValidator componentNameValidator = new ComponentNameValidator(componentsUtils, toscaOperationFacade);
-
+ private final PolicyBusinessLogic policyBusinessLogic = Mockito.mock(PolicyBusinessLogic.class);
@InjectMocks
ResourceBusinessLogic bl = new ResourceBusinessLogic(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation, artifactsBusinessLogic,
@@ -72,7 +73,7 @@ public class CheckoutTest extends LifecycleTestBase {
resourceDataMergeBusinessLogic, csarArtifactsAndGroupsBusinessLogic, mergeInstanceUtils,
uiComponentDataConverter, csarBusinessLogic, artifactToscaOperation, propertyBusinessLogic,
componentContactIdValidator, componentNameValidator, componentTagsValidator, componentValidator,
- componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator );
+ componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator ,policyBusinessLogic);
@Before
public void setup() {
diff --git a/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml b/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml
index 39316c62f9..a28f31b1b0 100644
--- a/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml
+++ b/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml
@@ -2239,3 +2239,18 @@ errors:
message: 'Error: Invalid Content. %1 has invalid format.',
messageId: "SVC4723"
}
+ #---------SVC4801------------------------------
+ # %1 - policy type
+ POLICY_TYPE_IS_INVALID: {
+ code: 400,
+ message: "Error: Invalid content. Policy type %1 does not exist",
+ messageId: "SVC4801"
+ }
+
+ #---------SVC4802------------------------------
+ # %1 - policy name
+ POLICY_MISSING_POLICY_TYPE: {
+ code: 400,
+ message: "Error: Invalid content. Type name is not defined for policy %1",
+ messageId: "SVC4802"
+ }