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/BaseServiceBusinessLogicTest.java88
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/ServiceDistributionBLTest.java3
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandlerTest.java (renamed from catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java)177
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java513
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java80
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java511
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java56
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportManagerTest.java9
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java20
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/path/BaseForwardingPathTest.java6
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PolicyExportParserImplTest.java282
11 files changed, 882 insertions, 863 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/BaseServiceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/BaseServiceBusinessLogicTest.java
index 692e8cce50..638eef6898 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/BaseServiceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/BaseServiceBusinessLogicTest.java
@@ -78,16 +78,29 @@ import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.springframework.web.context.WebApplicationContext;
public abstract class BaseServiceBusinessLogicTest extends ComponentBusinessLogicMock {
+
+ protected static final String CERTIFIED_VERSION = "1.0";
+ protected static final String UNCERTIFIED_VERSION = "0.2";
+ protected static final String COMPONNET_ID = "myUniqueId";
+ protected static final String GENERIC_SERVICE_NAME = "org.openecomp.resource.abstract.nodes.service";
private static final String SERVICE_CATEGORY = "Mobility";
- private final ServletContext servletContext = Mockito.mock(ServletContext.class);
- private UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
- private WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
- private WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
+ protected static Map<AuditingFieldsKey, Object> FILTER_MAP_CERTIFIED_VERSION = new HashMap<>();
+ protected static Map<AuditingFieldsKey, Object> FILTER_MAP_UNCERTIFIED_VERSION_CURR = new HashMap<>();
+ protected static Map<AuditingFieldsKey, Object> FILTER_MAP_UNCERTIFIED_VERSION_PREV = new HashMap<>();
+ protected static ForwardingPathDataDefinition forwardingPathDataDefinition;
protected final IDistributionEngine distributionEngine = Mockito.mock(IDistributionEngine.class);
protected final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
protected final ServiceDistributionValidation serviceDistributionValidation = Mockito.mock(ServiceDistributionValidation.class);
protected final ForwardingPathValidator forwardingPathValidator = Mockito.mock(ForwardingPathValidator.class);
protected final UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
+ private final ServletContext servletContext = Mockito.mock(ServletContext.class);
+ private final ModelOperation modelOperation = Mockito.mock(ModelOperation.class);
+ User user = null;
+ Service serviceResponse = null;
+ Resource genericService = null;
+ private UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
+ private WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
+ private WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
private ServiceBusinessLogic bl;
private ResponseFormatManager responseManager = null;
private IElementOperation mockElementDao;
@@ -98,20 +111,25 @@ public abstract class BaseServiceBusinessLogicTest extends ComponentBusinessLogi
private JanusGraphDao mockJanusGraphDao = Mockito.mock(JanusGraphDao.class);
private ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
private GenericTypeBusinessLogic genericTypeBusinessLogic = Mockito.mock(GenericTypeBusinessLogic.class);
- private ForwardingPathOperation forwardingPathOperation = Mockito.mock(ForwardingPathOperation.class);
- private final ModelOperation modelOperation = Mockito.mock(ModelOperation.class);
+ private ForwardingPathOperation forwardingPathOperation = Mockito.mock(ForwardingPathOperation.class);
- User user = null;
- Service serviceResponse = null;
- Resource genericService = null;
+ protected static ForwardingPathDataDefinition createMockPath() {
+ if (forwardingPathDataDefinition != null) {
+ return forwardingPathDataDefinition;
+ }
+ forwardingPathDataDefinition = new ForwardingPathDataDefinition("Yoyo");
+ forwardingPathDataDefinition.setUniqueId(java.util.UUID.randomUUID().toString());
+ forwardingPathDataDefinition.setDestinationPortNumber("414155");
+ forwardingPathDataDefinition.setProtocol("http");
+ org.openecomp.sdc.be.datatypes.elements.ListDataDefinition<org.openecomp.sdc.be.datatypes.elements.ForwardingPathElementDataDefinition> forwardingPathElementDataDefinitionListDataDefinition = new org.openecomp.sdc.be.datatypes.elements.ListDataDefinition<>();
+ forwardingPathElementDataDefinitionListDataDefinition.add(
+ new ForwardingPathElementDataDefinition("fromNode", "toNode", "333", "444", "2222", "5555"));
+ forwardingPathElementDataDefinitionListDataDefinition.add(
+ new ForwardingPathElementDataDefinition("toNode", "toNode2", "4444", "44444", "4", "44"));
+ forwardingPathDataDefinition.setPathElements(forwardingPathElementDataDefinitionListDataDefinition);
+ return forwardingPathDataDefinition;
+ }
- protected static final String CERTIFIED_VERSION = "1.0";
- protected static final String UNCERTIFIED_VERSION = "0.2";
- protected static final String COMPONNET_ID = "myUniqueId";
- protected static final String GENERIC_SERVICE_NAME = "org.openecomp.resource.abstract.nodes.service";
- protected static Map<AuditingFieldsKey, Object> FILTER_MAP_CERTIFIED_VERSION = new HashMap<>();
- protected static Map<AuditingFieldsKey, Object> FILTER_MAP_UNCERTIFIED_VERSION_CURR = new HashMap<>();
- protected static Map<AuditingFieldsKey, Object> FILTER_MAP_UNCERTIFIED_VERSION_PREV = new HashMap<>();
@Before
public void setup() {
@@ -141,7 +159,8 @@ public abstract class BaseServiceBusinessLogicTest extends ComponentBusinessLogi
// artifact bussinesslogic
ArtifactDefinition artifactDef = new ArtifactDefinition();
- when(artifactBl.createArtifactPlaceHolderInfo(Mockito.anyString(), Mockito.anyString(), Mockito.anyMap(), Mockito.any(User.class), Mockito.any(ArtifactGroupTypeEnum.class))).thenReturn(artifactDef);
+ when(artifactBl.createArtifactPlaceHolderInfo(Mockito.anyString(), Mockito.anyString(), Mockito.anyMap(), Mockito.any(User.class),
+ Mockito.any(ArtifactGroupTypeEnum.class))).thenReturn(artifactDef);
// createService
serviceResponse = createServiceObject(true);
@@ -157,9 +176,9 @@ public abstract class BaseServiceBusinessLogicTest extends ComponentBusinessLogi
when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_SERVICE_NAME)).thenReturn(findLatestGeneric);
//forwardingPath
- when(forwardingPathOperation.addForwardingPath(any(),any())).thenReturn(Either.left(createMockPath()));
- when(forwardingPathOperation.updateForwardingPath(any(),any())).thenReturn(Either.left(createMockPath()));
- when(forwardingPathOperation.deleteForwardingPath(any(),any())).thenReturn(Either.left(Sets.newHashSet("Wow-It-Works")));
+ when(forwardingPathOperation.addForwardingPath(any(), any())).thenReturn(Either.left(createMockPath()));
+ when(forwardingPathOperation.updateForwardingPath(any(), any())).thenReturn(Either.left(createMockPath()));
+ when(forwardingPathOperation.deleteForwardingPath(any(), any())).thenReturn(Either.left(Sets.newHashSet("Wow-It-Works")));
when(toscaOperationFacade.getToscaElement("delete_forward_test")).thenReturn(Either.left(createServiceObject(true)));
bl = new ServiceBusinessLogic(elementDao, groupOperation, groupInstanceOperation,
@@ -168,7 +187,7 @@ public abstract class BaseServiceBusinessLogicTest extends ComponentBusinessLogi
serviceDistributionValidation, forwardingPathValidator, uiComponentDataConverter,
artifactToscaOperation, componentContactIdValidator, componentNameValidator,
componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator,
- modelOperation);
+ modelOperation, null, null, null, null, null);
bl.setUserAdmin(mockUserAdmin);
bl.setGraphLockOperation(graphLockOperation);
bl.setJanusGraphDao(mockJanusGraphDao);
@@ -192,15 +211,15 @@ public abstract class BaseServiceBusinessLogicTest extends ComponentBusinessLogi
service.setUniqueId("serviceUniqueId");
List<ComponentInstance> componentInstances = new ArrayList<>();
ComponentInstance ci;
- for(int i= 0; i<listSize; ++i){
+ for (int i = 0; i < listSize; ++i) {
ci = new ComponentInstance();
ci.setName("ciName" + i);
ci.setUniqueId("ciId" + i);
- List<GroupInstance> groupInstances= new ArrayList<>();
+ List<GroupInstance> groupInstances = new ArrayList<>();
GroupInstance gi;
- for(int j = 0; j<listSize; ++j){
+ for (int j = 0; j < listSize; ++j) {
gi = new GroupInstance();
- gi.setName(ci.getName( )+ "giName" + j);
+ gi.setName(ci.getName() + "giName" + j);
gi.setUniqueId(ci.getName() + "giId" + j);
groupInstances.add(gi);
}
@@ -321,27 +340,10 @@ public abstract class BaseServiceBusinessLogicTest extends ComponentBusinessLogi
return service;
}
- protected Resource setupGenericServiceMock(){
+ protected Resource setupGenericServiceMock() {
Resource genericService = new Resource();
genericService.setVersion("1.0");
genericService.setToscaResourceName(GENERIC_SERVICE_NAME);
return genericService;
}
-
- protected static ForwardingPathDataDefinition forwardingPathDataDefinition;
-
- protected static ForwardingPathDataDefinition createMockPath() {
- if (forwardingPathDataDefinition != null){
- return forwardingPathDataDefinition ;
- }
- forwardingPathDataDefinition = new ForwardingPathDataDefinition("Yoyo");
- forwardingPathDataDefinition.setUniqueId(java.util.UUID.randomUUID().toString());
- forwardingPathDataDefinition.setDestinationPortNumber("414155");
- forwardingPathDataDefinition.setProtocol("http");
- org.openecomp.sdc.be.datatypes.elements.ListDataDefinition<org.openecomp.sdc.be.datatypes.elements.ForwardingPathElementDataDefinition> forwardingPathElementDataDefinitionListDataDefinition = new org.openecomp.sdc.be.datatypes.elements.ListDataDefinition<>();
- forwardingPathElementDataDefinitionListDataDefinition.add(new ForwardingPathElementDataDefinition("fromNode","toNode", "333","444","2222","5555"));
- forwardingPathElementDataDefinitionListDataDefinition.add(new ForwardingPathElementDataDefinition("toNode","toNode2", "4444","44444","4","44"));
- forwardingPathDataDefinition.setPathElements(forwardingPathElementDataDefinitionListDataDefinition);
- return forwardingPathDataDefinition;
- }
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ServiceDistributionBLTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ServiceDistributionBLTest.java
index 0b3973e584..602a3bb4ce 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ServiceDistributionBLTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ServiceDistributionBLTest.java
@@ -76,7 +76,8 @@ class ServiceDistributionBLTest extends ComponentBusinessLogicMock {
serviceDistributionValidation, forwardingPathValidator, uiComponentDataConverter,
artifactToscaOperation, componentContactIdValidator,
componentNameValidator, componentTagsValidator, componentValidator, componentIconValidator,
- componentProjectCodeValidator, componentDescriptionValidator, modelOperation);
+ componentProjectCodeValidator, componentDescriptionValidator, modelOperation, null, null,
+ null, null, null);
private Service serviceToActivate;
private ActivationRequestInformation activationRequestInformation;
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/csar/YamlTemplateParsingHandlerTest.java
index 5f85b5134a..a2931a515b 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/csar/YamlTemplateParsingHandlerTest.java
@@ -18,21 +18,35 @@
* ============LICENSE_END=================================================
*/
-package org.openecomp.sdc.be.components.impl.utils;
+package org.openecomp.sdc.be.components.csar;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.ARTIFACTS;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
import mockit.Deencapsulation;
import org.apache.commons.collections.MapUtils;
import org.assertj.core.util.Lists;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.openecomp.sdc.be.components.csar.CsarInfo;
-import org.openecomp.sdc.be.components.csar.YamlTemplateParsingHandler;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.be.components.impl.AnnotationBusinessLogic;
import org.openecomp.sdc.be.components.impl.GroupTypeBusinessLogic;
import org.openecomp.sdc.be.components.impl.PolicyTypeBusinessLogic;
@@ -54,27 +68,9 @@ import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.operations.impl.AnnotationTypeOperations;
import org.openecomp.sdc.common.zip.ZipUtils;
import org.openecomp.sdc.common.zip.exception.ZipException;
-
-import java.io.File;
-import java.net.URISyntaxException;
-import java.util.Collections;
-import java.util.HashMap;
-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.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.when;
-import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.ARTIFACTS;
-
-@RunWith(MockitoJUnitRunner.class)
+@ExtendWith(MockitoExtension.class)
public class YamlTemplateParsingHandlerTest {
@Mock
@@ -117,9 +113,9 @@ public class YamlTemplateParsingHandlerTest {
private static final String NESTED_GROUP_NAME = "nested_mg_vepdg_group";
@InjectMocks
- YamlTemplateParsingHandler testSubject;
+ private YamlTemplateParsingHandler testSubject;
- @BeforeClass()
+ @BeforeAll
public static void prepareData() throws URISyntaxException, ZipException {
final File csarFile = new File(
YamlTemplateParsingHandlerTest.class.getClassLoader().getResource(CSAR_FILE_PATH).toURI());
@@ -132,34 +128,34 @@ public class YamlTemplateParsingHandlerTest {
resourceYml = new String(mainTemplateService);
}
- @Before
+ @BeforeEach
public void setup() {
AnnotationBusinessLogic annotationBusinessLogic = new AnnotationBusinessLogic(annotationTypeOperations,
- annotationValidator);
+ annotationValidator);
handler = new YamlTemplateParsingHandler(janusGraphDao, groupTypeBusinessLogic, annotationBusinessLogic, policyTypeBusinessLogic);
ReflectionTestUtils.setField(handler, "policyTypeBusinessLogic", policyTypeBusinessLogic);
- stubGetGroupType();
- stubGetPolicyType();
}
@Test
- public void parseResourceInfoFromOneNodeTest() {
+ void parseResourceInfoFromOneNodeTest() {
+ when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE), any())).thenReturn(heatGroupType);
String main_template_content = new String(csar.get(MAIN_TEMPLATE_NAME));
CsarInfo csarInfo = new CsarInfo(user, CSAR_UUID, csar, RESOURCE_NAME,
- MAIN_TEMPLATE_NAME, main_template_content, true);
+ MAIN_TEMPLATE_NAME, main_template_content, true);
Resource resource = new Resource();
ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
- csarInfo.extractTypesInfo(), NODE_NAME, resource, getInterfaceTemplateYaml(csarInfo).get());
+ csarInfo.extractTypesInfo(), NODE_NAME, resource, getInterfaceTemplateYaml(csarInfo).get());
validateParsedYaml(parsedYaml, NESTED_GROUP_NAME,
- Lists.newArrayList("heat_file", "description"));
+ Lists.newArrayList("heat_file", "description"));
}
@Test
- public void parseServicePropertiesInfoFromYamlTest() {
+ void parseServicePropertiesInfoFromYamlTest() {
+ when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE), any())).thenReturn(heatGroupType);
String main_template_content = new String(csar.get(MAIN_TEMPLATE_NAME));
CsarInfo csarInfo = new CsarInfo(user, CSAR_UUID, csar, RESOURCE_NAME,
MAIN_TEMPLATE_NAME, main_template_content, true);
@@ -178,30 +174,32 @@ public class YamlTemplateParsingHandlerTest {
}
@Test
- public void parseResourceInfoFromYAMLTest() {
+ void parseResourceInfoFromYAMLTest() {
+ stubGetGroupType();
+ stubGetPolicyType();
Resource resource = new Resource();
ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
- new HashMap<>(), "", resource, null);
+ new HashMap<>(), "", resource, null);
validateParsedYamlWithCapability(parsedYaml);
}
@Test
- public void testSetArtifacts() {
+ 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");
+ 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() {
+ void testCreateArtifactsModuleFromYaml() {
Map<String, Map<String, Map<String, String>>> nodeTemplateJsonMap = new HashMap<>();
- Map<String, Map<String,String>> map0 = 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");
@@ -209,54 +207,56 @@ public class YamlTemplateParsingHandlerTest {
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());
+ assertTrue(MapUtils.isNotEmpty(result));
+ assertTrue(MapUtils.isNotEmpty(result.get(ARTIFACTS.getElementName())));
+ assertEquals("test_file", result.get(ARTIFACTS.getElementName()).get("test_art").getFile());
+ assertEquals("test_type", result.get(ARTIFACTS.getElementName()).get("test_art").getType());
}
@Test
- public void testAddModuleNodeTemplateArtifacts() {
+ 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());
+ assertTrue(MapUtils.isNotEmpty(result));
+ assertTrue(MapUtils.isNotEmpty(result.get(ARTIFACTS.getElementName())));
+ assertEquals("test_file", result.get(ARTIFACTS.getElementName()).get("test_art").getFile());
+ assertEquals("test_type", result.get(ARTIFACTS.getElementName()).get("test_art").getType());
}
@Test
- public void testBuildModuleNodeTemplateArtifact() {
+ 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());
+ assertEquals("test_file", result.getFile());
+ assertEquals("test_type", result.getType());
}
@Test
- public void testFillArtifact() {
+ 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());
+ assertEquals("test_file", result.getFile());
+ assertEquals("test_type", result.getType());
}
@Test
- public void parseResourceWithPoliciesDefined() {
+ void parseResourceWithPoliciesDefined() {
+ stubGetGroupType();
+ stubGetPolicyType();
Resource resource = new Resource();
ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
- new HashMap<>(), "", resource, "");
+ new HashMap<>(), "", resource, "");
validateParsedYamlWithPolicies(parsedYaml);
}
@@ -267,10 +267,10 @@ public class YamlTemplateParsingHandlerTest {
assertThat(parsedYaml.getGroups().get(group).getProperties()).isNotNull();
assertThat(parsedYaml.getGroups().get(group).getProperties()
- .stream()
- .map(PropertyDataDefinition::getName)
- .collect(Collectors.toList()))
- .containsAll(expectedProp);
+ .stream()
+ .map(PropertyDataDefinition::getName)
+ .collect(Collectors.toList()))
+ .containsAll(expectedProp);
assertThat(parsedYaml.getGroups().get(group).getMembers()).isNotNull();
}
@@ -278,13 +278,13 @@ public class YamlTemplateParsingHandlerTest {
private void validateParsedYamlWithCapability(ParsedToscaYamlInfo parsedYaml) {
final List<String> expectedProp = Lists.newArrayList("vfc_parent_port_role",
- "network_collection_function", "vfc_instance_group_function", "subinterface_role");
+ "network_collection_function", "vfc_instance_group_function", "subinterface_role");
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();
assertThat(parsedYaml.getSubstitutionMappingNodeType()).isEqualTo("org.openecomp.resource.abstract.nodes.VF");
}
@@ -297,18 +297,18 @@ public class YamlTemplateParsingHandlerTest {
private static GroupTypeDefinition buildRootGroupType() {
return createGroupTypeDefinition(ROOT_GROUP_TYPE, null,
- "The TOSCA Group Type all other TOSCA Group Types derive from");
+ "The TOSCA Group Type all other TOSCA Group Types derive from");
}
private static GroupTypeDefinition buildHeatStackGroupType() {
GroupTypeDefinition groupType = createGroupTypeDefinition(HEAT_GROUP_TYPE, "tosca.groups.Root",
- "Grouped all heat resources which are in the same heat stack");
+ "Grouped all heat resources which are in the same heat stack");
GroupProperty property1 = createGroupProperty("heat_file",
- "Heat file which associate to this group/heat stack", "SUPPORTED");
+ "Heat file which associate to this group/heat stack", "SUPPORTED");
GroupProperty property2 = createGroupProperty("description",
- "Group description", "SUPPORTED");
+ "Group description", "SUPPORTED");
groupType.setProperties(Lists.newArrayList(property1, property2));
return groupType;
@@ -316,19 +316,19 @@ public class YamlTemplateParsingHandlerTest {
private static GroupTypeDefinition buildVfcInstanceGroupType() {
GroupTypeDefinition groupType = createGroupTypeDefinition(VFC_GROUP_TYPE, "tosca.groups.Root",
- "Groups of VFCs with same parent port role");
+ "Groups of VFCs with same parent port role");
GroupProperty property1 = createGroupProperty("vfc_instance_group_function",
- "Function of this VFC group", null);
+ "Function of this VFC group", null);
GroupProperty property2 = createGroupProperty("vfc_parent_port_role",
- "Common role of parent ports of VFCs in this group", null);
+ "Common role of parent ports of VFCs in this group", null);
GroupProperty property3 = createGroupProperty("network_collection_function",
- "Network collection function assigned to this group", null);
+ "Network collection function assigned to this group", null);
GroupProperty property4 = createGroupProperty("subinterface_role",
- "Common role of subinterfaces of VFCs in this group, criteria the group is created", null);
+ "Common role of subinterfaces of VFCs in this group, criteria the group is created", null);
groupType.setProperties(Lists.newArrayList(property1, property2, property3, property4));
@@ -346,11 +346,12 @@ public class YamlTemplateParsingHandlerTest {
return groupType;
}
- private static GroupTypeDefinition createGroupTypeDefinition(String type, String derivedFrom, String description){
+ private static GroupTypeDefinition createGroupTypeDefinition(String type, String derivedFrom, String description) {
GroupTypeDefinition property = new GroupTypeDefinition();
- if (type != null)
+ if (type != null) {
property.setType(type);
+ }
if (derivedFrom != null) {
property.setDerivedFrom(derivedFrom);
@@ -362,11 +363,13 @@ public class YamlTemplateParsingHandlerTest {
return property;
}
+
private static GroupProperty createGroupProperty(String name, String description,
- String status){
+ String status) {
GroupProperty property = new GroupProperty();
- if (name != null)
+ if (name != null) {
property.setName(name);
+ }
if (description != null) {
property.setDescription(description);
@@ -389,14 +392,14 @@ public class YamlTemplateParsingHandlerTest {
assertThat(parsedYaml.getPolicies().get(OPENECOMP_POLICY_NAME)).isInstanceOf(PolicyDefinition.class);
}
- private void stubGetPolicyType () {
- when(policyTypeBusinessLogic.getLatestPolicyTypeByType(eq(OPENECOMP_ANTILOCATE_POLICY_TYPE), any())).thenReturn(
- OPENECOMP_POLICY_TYPE);
+ private void stubGetPolicyType() {
+ when(policyTypeBusinessLogic.getLatestPolicyTypeByType(eq(OPENECOMP_ANTILOCATE_POLICY_TYPE), any()))
+ .thenReturn(OPENECOMP_POLICY_TYPE);
}
private static PolicyTypeDefinition buildOpenecompPolicyType() {
return createPolicyTypeDefinition(OPENECOMP_POLICY_NAME, OPENECOMP_ANTILOCATE_POLICY_TYPE, ROOT_POLICIES_TYPE,
- "The Openecomp Antilocate policy");
+ "The Openecomp Antilocate policy");
}
private static PolicyTypeDefinition createPolicyTypeDefinition(String policyName, String policyType, String derivedFrom, String description) {
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 7a8a15a905..15b7706598 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
@@ -16,16 +16,19 @@
package org.openecomp.sdc.be.components.impl;
-
-import static org.assertj.core.api.Java6Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
+import static org.openecomp.sdc.be.dao.api.ActionStatus.POLICY_TARGET_DOES_NOT_EXIST;
+import static org.openecomp.sdc.be.dao.api.ActionStatus.PROPERTY_NOT_FOUND;
import fj.data.Either;
import java.util.ArrayList;
@@ -35,15 +38,15 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections.CollectionUtils;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator;
@@ -53,8 +56,8 @@ import org.openecomp.sdc.be.components.utils.ResourceBuilder;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
@@ -73,6 +76,7 @@ import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.PolicyTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
@@ -85,9 +89,34 @@ import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.openecomp.sdc.exception.ResponseFormat;
-@RunWith(MockitoJUnitRunner.class)
-public class PolicyBusinessLogicTest {
-
+@ExtendWith(MockitoExtension.class)
+class PolicyBusinessLogicTest {
+
+ private static final String COMPONENT_ID = "componentId";
+ private static final String NON_EXIST_COMPONENT_ID = "nonExistComponentId";
+ private static final String COMPONENT_NAME = "componentName";
+ private static final String POLICY_TYPE_NAME = "policyTypeName";
+ private static final String POLICY_ID = "policyId";
+ private static final String INVALID_POLICY_ID = "invalidPolicyId";
+ private static final String POLICY_NAME = "policyName";
+ private static final String OTHER_POLICY_NAME = "otherPolicyName";
+ private static final String USER_ID = "jh0003";
+ private static final String UNIQUE_ID_EXSISTS = "uniqueIdExists";
+ private static final String UNIQUE_ID_DOESNT_EXSISTS = "uniqueIdDoesntExists";
+ private static final String CREATE_POLICY = "create Policy";
+ private static final String PROPERTY_NAME = "propDefinition";
+ private static final User user = buildUser();
+ private static final PolicyDefinition policy = buildPolicy(POLICY_NAME);
+ private static final Resource resource = buildResource();
+ private static final PolicyDefinition otherPolicy = buildPolicy(OTHER_POLICY_NAME);
+ private static final PolicyTypeDefinition policyType = buildPolicyType();
+ private static Either<Component, StorageOperationStatus> componentSuccessEither;
+ private static Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeSuccessEither;
+ private static Either<PolicyDefinition, StorageOperationStatus> policySuccessEither;
+ private final ConfigurationManager configurationManager = new ConfigurationManager(
+ new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
+ @Mock
+ private PropertyDeclarationOrchestrator propertyDeclarationOrchestrator;
@InjectMocks
private PolicyBusinessLogic businessLogic;
@Mock
@@ -106,43 +135,72 @@ public class PolicyBusinessLogicTest {
private ApplicationDataTypeCache applicationDataTypeCache;
@Mock
private PropertyOperation propertyOperation;
- @Mock
- PropertyDeclarationOrchestrator propertyDeclarationOrchestrator;
-
- private final static String COMPONENT_ID = "componentId";
- private final static String NON_EXIST_COMPONENT_ID = "nonExistComponentId";
- private final static String COMPONENT_NAME = "componentName";
- private final static String POLICY_TYPE_NAME = "policyTypeName";
- private final static String POLICY_ID = "policyId";
- private final static String INVALID_POLICY_ID = "invalidPolicyId";
- private final static String POLICY_NAME = "policyName";
- private final static String OTHER_POLICY_NAME = "otherPolicyName";
- private final static String USER_ID = "jh0003";
- private final static String UNIQUE_ID_EXSISTS = "uniqueIdExists";
- private final static String UNIQUE_ID_DOESNT_EXSISTS = "uniqueIdDoesntExists";
- private final static String CREATE_POLICY = "create Policy";
- private final static String PROPERTY_NAME = "propDefinition";
- private final static User user = buildUser();
- private final static PolicyDefinition policy = buildPolicy(POLICY_NAME);
- private final static PolicyDefinition otherPolicy = buildPolicy(OTHER_POLICY_NAME);
- private final static Resource resource = buildResource();
- private final static PolicyTypeDefinition policyType = buildPolicyType();
-
- private static Either<Component, StorageOperationStatus> componentSuccessEither;
- private static Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeSuccessEither;
- private static Either<PolicyDefinition, StorageOperationStatus> policySuccessEither;
- private static ResponseFormat notFoundResponse;
- private static ResponseFormat invalidContentResponse;
- private static ResponseFormat nameExistsResponse;
- private final ConfigurationManager configurationManager = new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
- @BeforeClass
- public static void setup() {
+ @BeforeAll
+ static void setup() {
createResponses();
}
- @Before
- public void initBl() {
+ private static void createResponses() {
+ componentSuccessEither = Either.left(resource);
+ getPolicyTypeSuccessEither = Either.left(policyType);
+ policySuccessEither = Either.left(policy);
+ }
+
+ private static PolicyTypeDefinition buildPolicyType() {
+ PolicyTypeDefinition policyType = new PolicyTypeDefinition();
+ policyType.setType(POLICY_TYPE_NAME);
+ return policyType;
+ }
+
+ private static PolicyDefinition buildPolicy(String policyName) {
+ PolicyDefinition policy = new PolicyDefinition();
+ policy.setUniqueId(POLICY_ID);
+ policy.setPolicyTypeName(POLICY_TYPE_NAME);
+ policy.setComponentName(COMPONENT_NAME);
+ policy.setName(policyName);
+ return policy;
+ }
+
+ private static Resource buildResource() {
+ Resource resource = new Resource();
+ resource.setUniqueId(COMPONENT_ID);
+ resource.setName(COMPONENT_NAME);
+ resource.setCreatorUserId(USER_ID);
+ resource.setLastUpdaterUserId(USER_ID);
+ resource.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ resource.setIsDeleted(false);
+ resource.setResourceType(ResourceTypeEnum.VF);
+ resource.setToscaType(ToscaElementTypeEnum.TOPOLOGY_TEMPLATE.getValue());
+ resource.setComponentType(ComponentTypeEnum.RESOURCE);
+ Map<String, PolicyDefinition> policies = new HashMap<>();
+ policies.put(POLICY_ID, policy);
+ resource.setPolicies(policies);
+ return resource;
+ }
+
+ private static Service buildService() {
+ Service service = new Service();
+ service.setUniqueId(COMPONENT_ID);
+ service.setName(COMPONENT_NAME);
+ service.setCreatorUserId(USER_ID);
+ service.setLastUpdaterUserId(USER_ID);
+ service.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ service.setIsDeleted(false);
+ service.setToscaType(ToscaElementTypeEnum.TOPOLOGY_TEMPLATE.getValue());
+ service.setComponentType(ComponentTypeEnum.SERVICE);
+ Map<String, PolicyDefinition> policies = new HashMap<>();
+ policies.put(POLICY_ID, policy);
+ service.setPolicies(policies);
+ return service;
+ }
+
+ private static User buildUser() {
+ return new User(USER_ID);
+ }
+
+ @BeforeEach
+ void initBl() {
MockitoAnnotations.openMocks(this);
businessLogic.setComponentsUtils(componentsUtils);
businessLogic.setToscaOperationFacade(toscaOperationFacade);
@@ -155,31 +213,18 @@ public class PolicyBusinessLogicTest {
businessLogic.setPropertyDeclarationOrchestrator(propertyDeclarationOrchestrator);
}
-
- private static void createResponses() {
- componentSuccessEither = Either.left(resource);
- getPolicyTypeSuccessEither = Either.left(policyType);
- policySuccessEither = Either.left(policy);
- notFoundResponse = new ResponseFormat();
- notFoundResponse.setStatus(404);
- invalidContentResponse = new ResponseFormat();
- invalidContentResponse.setStatus(400);
- nameExistsResponse = new ResponseFormat();
- nameExistsResponse.setStatus(409);
- }
-
@Test
- public void createPolicySuccessTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
+ void createPolicySuccessTest() {
+ stubValidateAndLockSuccess();
when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeSuccessEither);
when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(policySuccessEither);
stubUnlockAndCommit();
PolicyDefinition response = businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
- assertThat(response.isEmpty()).isFalse();
+ assertFalse(response.isEmpty());
}
@Test
- public void createPolicyFromCsarDefinitionTest() {
+ void createPolicyOnResourceFromCsarDefinitionTest() {
String prop1 = "Prop_1";
String prop2 = "Prop_2";
Map<String, PolicyDefinition> policies = new HashMap<>();
@@ -199,186 +244,249 @@ public class PolicyBusinessLogicTest {
Resource newResource = buildResource();
newResource.setPolicies(policies);
newResource.setComponentInstances(instanceList);
-
+
+ when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeSuccessEither);
+ when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(Either.left(policy));
+ when(toscaOperationFacade.getToscaFullElement(COMPONENT_ID)).thenReturn(Either.left(newResource));
+ when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(
+ Either.left(policy));
+ 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.createPolicies(newResource, policies);
+
+ assertFalse(createdPolicy.isEmpty());
+ PolicyDefinition newPolicy = createdPolicy.get(POLICY_NAME);
+ assertNotNull(newPolicy);
+ assertTrue(newPolicy.getIsFromCsar());
+ assertNotNull(newPolicy.getTargets());
+ assertNotNull(newPolicy.getProperties());
+ assertEquals(2, newPolicy.getProperties().size());
+ assertEquals(1, newPolicy.getTargets().size());
+ }
+
+ @Test
+ void createPolicyOnServiceFromCsarDefinitionTest() {
+ 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);
+
+ Service newService = buildService();
+ newService.setPolicies(policies);
+ newService.setComponentInstances(instanceList);
+
when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).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(toscaOperationFacade.getToscaFullElement(COMPONENT_ID)).thenReturn(Either.left(newService));
+ when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(
+ Either.left(policy));
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);
+ Map<String, PolicyDefinition> createdPolicy = businessLogic.createPolicies(newService, policies);
- assertThat(createdPolicy.isEmpty()).isFalse();
+ assertFalse(createdPolicy.isEmpty());
PolicyDefinition newPolicy = createdPolicy.get(POLICY_NAME);
assertNotNull(newPolicy);
+ assertTrue(newPolicy.getIsFromCsar());
assertNotNull(newPolicy.getTargets());
assertNotNull(newPolicy.getProperties());
assertEquals(2, newPolicy.getProperties().size());
assertEquals(1, newPolicy.getTargets().size());
+ assertTrue(newPolicy.getTargets().containsKey(PolicyTargetType.COMPONENT_INSTANCES));
+ assertEquals(2, newPolicy.getTargets().get(PolicyTargetType.COMPONENT_INSTANCES).size());
+ newPolicy.getTargets().get(PolicyTargetType.COMPONENT_INSTANCES).forEach(t -> assertTrue(t.equals(UNIQUE_ID_EXSISTS)));
+ newPolicy.getProperties().forEach(p -> assertTrue(p.getName().equals(prop1) || p.getName().equals(prop2)));
}
-
+
@Test
- public void createPolicyUserFailureTest(){
+ void createPolicyUserFailureTest() {
ByActionStatusComponentException userNotFoundException = new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND);
- when(userValidations.validateUserExists(eq(USER_ID))).thenThrow(userNotFoundException);
- stubRollback();
- try{
+ when(userValidations.validateUserExists(USER_ID)).thenThrow(userNotFoundException);
+ try {
businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
- } catch(ByActionStatusComponentException e){
+ } catch (ByActionStatusComponentException e) {
assertEquals(e.getActionStatus(), userNotFoundException.getActionStatus());
}
}
- private void assertNotFound(Either<PolicyDefinition, ResponseFormat> response) {
- assertThat(response.isRight() && response.right().value().getStatus().equals(404)).isTrue();
- }
-
- @Test(expected = ComponentException.class)
- public void createPolicyComponentFailureTest(){
- when(userValidations.validateUserExists(eq(USER_ID))).thenReturn(user);
+ @Test
+ void createPolicyComponentFailureTest() {
+ when(userValidations.validateUserExists(USER_ID)).thenReturn(user);
Either<Component, StorageOperationStatus> componentNotFoundResponse = Either.right(StorageOperationStatus.NOT_FOUND);
- when(componentsUtils.convertFromStorageResponse(eq(StorageOperationStatus.NOT_FOUND), eq(ComponentTypeEnum.RESOURCE))).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
+ when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND, ComponentTypeEnum.RESOURCE)).thenReturn(
+ ActionStatus.RESOURCE_NOT_FOUND);
when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(componentNotFoundResponse);
- businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
+ assertThrows(ComponentException.class,
+ () -> businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true));
}
-
- @Test(expected = ComponentException.class)
- public void createPolicyPolicyTypeFailureTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
+
+ @Test
+ void createPolicyPolicyTypeFailureTest() {
+ stubValidateAndLockSuccess();
Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeFailed = Either.right(StorageOperationStatus.NOT_FOUND);
when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeFailed);
- when(componentsUtils.convertFromStorageResponse(eq(getPolicyTypeFailed.right().value()))).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
+ when(componentsUtils.convertFromStorageResponse(getPolicyTypeFailed.right().value())).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
stubUnlockAndRollback();
- businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
+ assertThrows(ComponentException.class,
+ () -> businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true));
}
-
- @Test(expected = ComponentException.class)
- public void createPolicyComponentTypeFailureTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
+
+ @Test
+ void createPolicyComponentTypeFailureTest() {
+ stubValidateAndLockSuccess();
when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeSuccessEither);
Either<PolicyDefinition, StorageOperationStatus> addPolicyRes = Either.right(StorageOperationStatus.BAD_REQUEST);
when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(addPolicyRes);
- when(componentsUtils.convertFromStorageResponse(eq(addPolicyRes.right().value()))).thenReturn(ActionStatus.INVALID_CONTENT);
+ when(componentsUtils.convertFromStorageResponse(addPolicyRes.right().value())).thenReturn(ActionStatus.INVALID_CONTENT);
stubUnlockAndRollback();
- businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
+ assertThrows(ComponentException.class,
+ () -> businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true));
}
@Test
- public void updatePolicySuccessTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
- when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(policySuccessEither);
+ void updatePolicySuccessTest() {
+ stubValidateAndLockSuccess();
+ when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(
+ policySuccessEither);
stubUnlockAndCommit();
- PolicyDefinition response = businessLogic.updatePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, otherPolicy, USER_ID, true);
- assertThat(response.isEmpty()).isFalse();
+ PolicyDefinition response = businessLogic.updatePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, otherPolicy, USER_ID, true);
+ assertFalse(response.isEmpty());
}
-
- @Test(expected = ComponentException.class)
- public void updatePolicyNameFailureTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
+
+ @Test
+ void updatePolicyNameFailureTest() {
+ stubValidateAndLockSuccess();
stubUnlockAndRollback();
- businessLogic.updatePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, policy, USER_ID, true);
+ assertThrows(ComponentException.class, () -> businessLogic.updatePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, policy, USER_ID, true));
}
-
+
@Test
- public void getPolicySuccessTest(){
- stubValidationSuccess(CREATE_POLICY);
- stubCommit();
+ void getPolicySuccessTest() {
+ stubValidationSuccess();
PolicyDefinition response = businessLogic.getPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, USER_ID);
- assertThat(response.isEmpty()).isFalse();
+ assertFalse(response.isEmpty());
}
-
- @Test(expected = ComponentException.class)
- public void getPolicyFailureTest(){
- stubValidationSuccess(CREATE_POLICY);
- stubRollback();
- businessLogic.getPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, INVALID_POLICY_ID, USER_ID);
+
+ @Test
+ void getPolicyFailureTest() {
+ stubValidationSuccess();
+ assertThrows(ComponentException.class, () -> businessLogic.getPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, INVALID_POLICY_ID, USER_ID));
}
-
+
@Test
- public void deletePolicySuccessTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
+ void deletePolicySuccessTest() {
+ stubValidateAndLockSuccess();
stubCommit();
- when(toscaOperationFacade.removePolicyFromComponent(eq(COMPONENT_ID),eq(POLICY_ID))).thenReturn(StorageOperationStatus.OK);
- PolicyDefinition response = businessLogic.deletePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, USER_ID, true);
- assertThat(response.isEmpty()).isFalse();
- }
-
- @Test(expected = ComponentException.class)
- public void deletePolicyFailureTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
- stubCommit();
- businessLogic.deletePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, INVALID_POLICY_ID, USER_ID, true);
+ when(toscaOperationFacade.removePolicyFromComponent(COMPONENT_ID, POLICY_ID)).thenReturn(StorageOperationStatus.OK);
+ PolicyDefinition response = businessLogic.deletePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, USER_ID, true);
+ assertFalse(response.isEmpty());
}
+ @Test
+ void deletePolicyFailureTest() {
+ stubValidateAndLockSuccess();
+ assertThrows(ComponentException.class,
+ () -> businessLogic.deletePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, INVALID_POLICY_ID, USER_ID, true));
+ }
@Test
- public void updatePolicyPropertiesSuccessTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
+ void updatePolicyPropertiesSuccessTest() {
+ stubValidateAndLockSuccess();
String prop1 = "Name";
String prop2 = "Type";
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));
- when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(policySuccessEither);
+ when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(
+ policySuccessEither);
stubUnlockAndCommit();
PropertyDataDefinition[] properties = getProperties(prop1, prop2);
policy.setProperties(Arrays.asList(properties));
- List<PropertyDataDefinition> response = businessLogic.updatePolicyProperties(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, properties , USER_ID, true);
+ List<PropertyDataDefinition> response = businessLogic.updatePolicyProperties(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, properties,
+ USER_ID, true);
List<PropertyDataDefinition> updatedProperties = response;
- assertThat(updatedProperties.size()).isEqualTo(2);
+ assertEquals(2, updatedProperties.size());
}
@Test
- public void updatePolicyTargetsSuccessTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
+ void updatePolicyTargetsSuccessTest() {
+ stubValidateAndLockSuccess();
stubGetToscaFullElementSuccess();
stubUpdatePolicyOfComponentSuccess();
stubGetToscaElementSuccess();
PolicyDefinition policyResult = businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getTargets(), USER_ID);
Map<PolicyTargetType, List<String>> targets = getTargets();
- assertThat(policyResult.getTargets().values()).usingFieldByFieldElementComparator().containsExactlyInAnyOrder(targets.get(PolicyTargetType.GROUPS), targets.get(PolicyTargetType.COMPONENT_INSTANCES));
+ assertTrue(policyResult.getTargets().values()
+ .containsAll(Arrays.asList(targets.get(PolicyTargetType.GROUPS), targets.get(PolicyTargetType.COMPONENT_INSTANCES))));
}
- @Test(expected = ComponentException.class)
- public void updatePolicyTargetsTargetIDFailureTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
+ @Test
+ void updatePolicyTargetsTargetIDFailureTest() {
+ stubValidateAndLockSuccess();
stubGetToscaFullElementSuccess();
stubGetToscaElementSuccess();
- stubUpdatePolicyOfComponentSuccess();
stubRollback();
- businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getTargetListFakeId(), USER_ID);
-
+ Map<PolicyTargetType, List<String>> targetListFakeId = getTargetListFakeId();
+ final var componentException = assertThrows(ComponentException.class,
+ () -> businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, targetListFakeId, USER_ID));
+ assertNotNull(componentException);
+ assertEquals(POLICY_TARGET_DOES_NOT_EXIST, componentException.getActionStatus());
+ assertEquals(400, componentException.getResponseFormat().getStatus());
+ assertEquals(1, componentException.getParams().length);
+ assertEquals(UNIQUE_ID_DOESNT_EXSISTS, componentException.getParams()[0]);
}
-
- @Test(expected = ComponentException.class)
- public void updatePolicyTargetsTypeFailureTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
+ @Test
+ void updatePolicyTargetsTypeFailureTest() {
+ stubValidateAndLockSuccess();
stubGetToscaFullElementSuccess();
stubGetToscaElementSuccess();
- stubUpdatePolicyOfComponentSuccess();
stubRollback();
- businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getTargetListFakeType(), USER_ID);
-
+ Map<PolicyTargetType, List<String>> targetListFakeType = getTargetListFakeType();
+ final var componentException = assertThrows(ComponentException.class,
+ () -> businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, targetListFakeType, USER_ID));
+ assertNotNull(componentException);
+ assertEquals(POLICY_TARGET_DOES_NOT_EXIST, componentException.getActionStatus());
+ assertEquals(400, componentException.getResponseFormat().getStatus());
+ assertEquals(1, componentException.getParams().length);
+ assertEquals(UNIQUE_ID_EXSISTS, componentException.getParams()[0]);
}
private void stubUpdatePolicyOfComponentSuccess() {
- when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), eq(policy), any(PromoteVersionEnum.class))).thenReturn(policySuccessEither);
+ when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), eq(policy), any(PromoteVersionEnum.class))).thenReturn(
+ policySuccessEither);
}
-
- @Test(expected = ComponentException.class)
- public void updatePolicyPropertiesFailureTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
- stubUnlockAndRollback();
+ @Test
+ void updatePolicyPropertiesFailureTest() {
+ stubValidateAndLockSuccess();
+ when(graphLockOperation.unlockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
policy.setProperties(null);
- businessLogic.updatePolicyProperties(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getProperties("Name", "Type") , USER_ID, true);
+ PropertyDataDefinition[] properties = getProperties("Name", "Type");
+ final var componentException = assertThrows(ComponentException.class,
+ () -> businessLogic.updatePolicyProperties(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, properties, USER_ID, true));
+ assertNotNull(componentException);
+ assertEquals(PROPERTY_NOT_FOUND, componentException.getActionStatus());
+ assertEquals(404, componentException.getResponseFormat().getStatus());
+ assertEquals(0, componentException.getParams().length);
}
@Test
- public void testDeclarePropertiesAsPoliciesSuccess() {
+ void testDeclarePropertiesAsPoliciesSuccess() {
when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(resource));
when(graphLockOperation.lockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
when(graphLockOperation.unlockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
@@ -386,28 +494,30 @@ public class PolicyBusinessLogicTest {
when(propertyDeclarationOrchestrator.declarePropertiesToPolicies(any(), any())).thenReturn(Either.left(getDeclaredPolicies()));
Either<List<PolicyDefinition>, ResponseFormat> declaredPoliciesEither = businessLogic
- .declareProperties(USER_ID,
- resource.getUniqueId(),
- ComponentTypeEnum.RESOURCE,
- getInputForPropertyToPolicyDeclaration());
+ .declareProperties(USER_ID,
+ resource.getUniqueId(),
+ ComponentTypeEnum.RESOURCE,
+ getInputForPropertyToPolicyDeclaration());
- assertThat(declaredPoliciesEither.isLeft()).isTrue();
+ assertTrue(declaredPoliciesEither.isLeft());
List<PolicyDefinition> declaredPolicies = declaredPoliciesEither.left().value();
- assertThat(CollectionUtils.isNotEmpty(declaredPolicies)).isTrue();
+ assertTrue(CollectionUtils.isNotEmpty(declaredPolicies));
assertEquals(1, declaredPolicies.size());
}
@Test
- public void testDeclarePropertiesAsPoliciesFailure() {
- when(toscaOperationFacade.getToscaElement(eq(NON_EXIST_COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
- when(componentsUtils.convertFromStorageResponse(eq(StorageOperationStatus.NOT_FOUND), eq(ComponentTypeEnum.RESOURCE))).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
+ void testDeclarePropertiesAsPoliciesFailure() {
+ when(toscaOperationFacade.getToscaElement(eq(NON_EXIST_COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(
+ Either.right(StorageOperationStatus.NOT_FOUND));
+ when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND, ComponentTypeEnum.RESOURCE)).thenReturn(
+ ActionStatus.RESOURCE_NOT_FOUND);
try {
businessLogic
- .declareProperties(USER_ID,
- NON_EXIST_COMPONENT_ID,
- ComponentTypeEnum.RESOURCE,
- getInputForPropertyToPolicyDeclaration());
+ .declareProperties(USER_ID,
+ NON_EXIST_COMPONENT_ID,
+ ComponentTypeEnum.RESOURCE,
+ getInputForPropertyToPolicyDeclaration());
} catch (ComponentException e) {
assertEquals(ActionStatus.RESOURCE_NOT_FOUND, e.getActionStatus());
return;
@@ -450,8 +560,7 @@ public class PolicyBusinessLogicTest {
property2.setValue(prop2);
return new PropertyDataDefinition[]{property1, property2};
}
-
-
+
private void stubUnlockAndRollback() {
when(graphLockOperation.unlockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
stubRollback();
@@ -469,23 +578,23 @@ public class PolicyBusinessLogicTest {
when(graphLockOperation.unlockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
stubCommit();
}
-
- private void stubValidateAndLockSuccess(String methodName) {
- stubValidationSuccess(methodName);
+
+ private void stubValidateAndLockSuccess() {
+ stubValidationSuccess();
when(graphLockOperation.lockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
- }
+ }
- private void stubValidationSuccess(String methodName) {
- when(userValidations.validateUserExists(eq(USER_ID))).thenReturn(user);
+ private void stubValidationSuccess() {
+ when(userValidations.validateUserExists(USER_ID)).thenReturn(user);
when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(componentSuccessEither);
}
private void stubGetToscaFullElementSuccess() {
- when(toscaOperationFacade.getToscaFullElement(eq(COMPONENT_ID))).thenReturn(buildElementEither());
+ when(toscaOperationFacade.getToscaFullElement(COMPONENT_ID)).thenReturn(buildElementEither());
}
private void stubGetToscaElementSuccess() {
- when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID))).thenReturn(componentSuccessEither);
+ when(toscaOperationFacade.getToscaElement(COMPONENT_ID)).thenReturn(componentSuccessEither);
}
private Either<Component, StorageOperationStatus> buildElementEither() {
@@ -503,46 +612,6 @@ public class PolicyBusinessLogicTest {
return targets;
}
-
-
- private static PolicyTypeDefinition buildPolicyType() {
- PolicyTypeDefinition policyType = new PolicyTypeDefinition();
- policyType.setType(POLICY_TYPE_NAME);
- return policyType;
- }
-
- private static PolicyDefinition buildPolicy(String policyName) {
- PolicyDefinition policy = new PolicyDefinition();
- policy.setUniqueId(POLICY_ID);
- policy.setPolicyTypeName(POLICY_TYPE_NAME);
- policy.setComponentName(COMPONENT_NAME);
- policy.setName(policyName);
- return policy;
- }
-
- private static Resource buildResource() {
- Resource resource = new Resource();
- resource.setUniqueId(COMPONENT_ID);
- resource.setName(COMPONENT_NAME);
- resource.setCreatorUserId(USER_ID);
- resource.setLastUpdaterUserId(USER_ID);
- resource.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
- resource.setIsDeleted(false);
- resource.setResourceType(ResourceTypeEnum.VF);
- resource.setToscaType(ToscaElementTypeEnum.TOPOLOGY_TEMPLATE.getValue());
- resource.setComponentType(ComponentTypeEnum.RESOURCE);
- Map<String, PolicyDefinition> policies = new HashMap<>();
- policies.put(POLICY_ID, policy);
- resource.setPolicies(policies);
- return resource;
- }
-
- private static User buildUser() {
- User user = new User();
- user.setUserId(USER_ID);
- return user;
- }
-
private Map<PolicyTargetType, List<String>> getTargetListFakeType() {
Map<PolicyTargetType, List<String>> targets = new HashMap<>();
targets.put(PolicyTargetType.TYPE_DOES_NOT_EXIST, Collections.singletonList(UNIQUE_ID_EXSISTS));
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java
index 5b4585136f..049f8a5541 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java
@@ -91,10 +91,18 @@ import org.springframework.web.context.WebApplicationContext;
class ServiceBusinessLogicBaseTestSetup extends BaseBusinessLogicMock {
- protected ServiceBusinessLogic bl;
protected static final String SERVICE_CATEGORY = "Mobility";
protected static final String INSTANTIATION_TYPE = "A-la-carte";
+ protected static final String CERTIFIED_VERSION = "1.0";
+ protected static final String UNCERTIFIED_VERSION = "0.2";
+ protected static final String COMPONNET_ID = "myUniqueId";
+ protected static final String GENERIC_SERVICE_NAME = "org.openecomp.resource.abstract.nodes.service";
+ protected static final String SERVICE_ROLE = JsonPresentationFields.SERVICE_ROLE.getPresentation();
+ protected static final String SERVICE_TYPE = JsonPresentationFields.SERVICE_TYPE.getPresentation();
+ protected static final String SERVICE_FUNCTION = JsonPresentationFields.SERVICE_FUNCTION.getPresentation();
protected final ServletContext servletContext = Mockito.mock(ServletContext.class);
+ protected final ComponentValidator componentValidator = Mockito.mock(ComponentValidator.class);
+ protected ServiceBusinessLogic bl;
protected UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
protected WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
protected WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
@@ -112,37 +120,26 @@ class ServiceBusinessLogicBaseTestSetup extends BaseBusinessLogicMock {
protected ResourceAdminEvent auditArchive2 = Mockito.mock(ResourceAdminEvent.class);
protected ResourceAdminEvent auditRestore = Mockito.mock(ResourceAdminEvent.class);
protected ModelOperation modelOperation = Mockito.mock(ModelOperation.class);
- IElementOperation mockElementDao = new ElementOperationMock();
- DistributionEngine distributionEngine = Mockito.mock(DistributionEngine.class);
- ServiceDistributionValidation serviceDistributionValidation = Mockito.mock(ServiceDistributionValidation.class);
- ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
- ForwardingPathValidator forwardingPathValidator = Mockito.mock(ForwardingPathValidator.class);
- UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
protected ServiceTypeValidator serviceTypeValidator = new ServiceTypeValidator(componentsUtils);
- protected ServiceCategoryValidator serviceCategoryValidator = new ServiceCategoryValidator(componentsUtils, mockElementDao);
protected ServiceRoleValidator serviceRoleValidator = new ServiceRoleValidator(componentsUtils);
protected ServiceFunctionValidator serviceFunctionValidator = new ServiceFunctionValidator(componentsUtils);
protected ServiceInstantiationTypeValidator serviceInstantiationTypeValidator = new ServiceInstantiationTypeValidator(componentsUtils);
- protected ComponentDescriptionValidator componentDescriptionValidator = new ComponentDescriptionValidator(componentsUtils);
- protected ComponentProjectCodeValidator componentProjectCodeValidator = new ComponentProjectCodeValidator(componentsUtils);
+ protected ComponentDescriptionValidator componentDescriptionValidator = new ComponentDescriptionValidator(componentsUtils);
+ protected ComponentProjectCodeValidator componentProjectCodeValidator = new ComponentProjectCodeValidator(componentsUtils);
protected ComponentIconValidator componentIconValidator = new ComponentIconValidator(componentsUtils);
protected ComponentContactIdValidator componentContactIdValidator = new ComponentContactIdValidator(componentsUtils);
protected ComponentTagsValidator componentTagsValidator = new ComponentTagsValidator(componentsUtils);
protected ComponentNameValidator componentNameValidator = new ComponentNameValidator(componentsUtils, toscaOperationFacade);
- protected final ComponentValidator componentValidator = Mockito.mock(ComponentValidator.class);
- protected ServiceValidator serviceValidator = createServiceValidator();
-
protected User user = null;
protected Resource genericService = null;
-
- protected static final String CERTIFIED_VERSION = "1.0";
- protected static final String UNCERTIFIED_VERSION = "0.2";
- protected static final String COMPONNET_ID = "myUniqueId";
- protected static final String GENERIC_SERVICE_NAME = "org.openecomp.resource.abstract.nodes.service";
-
- protected static final String SERVICE_ROLE = JsonPresentationFields.SERVICE_ROLE.getPresentation();
- protected static final String SERVICE_TYPE = JsonPresentationFields.SERVICE_TYPE.getPresentation();
- protected static final String SERVICE_FUNCTION = JsonPresentationFields.SERVICE_FUNCTION.getPresentation();
+ IElementOperation mockElementDao = new ElementOperationMock();
+ protected ServiceCategoryValidator serviceCategoryValidator = new ServiceCategoryValidator(componentsUtils, mockElementDao);
+ protected ServiceValidator serviceValidator = createServiceValidator();
+ DistributionEngine distributionEngine = Mockito.mock(DistributionEngine.class);
+ ServiceDistributionValidation serviceDistributionValidation = Mockito.mock(ServiceDistributionValidation.class);
+ ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
+ ForwardingPathValidator forwardingPathValidator = Mockito.mock(ForwardingPathValidator.class);
+ UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
public ServiceBusinessLogicBaseTestSetup() {
@@ -150,19 +147,17 @@ class ServiceBusinessLogicBaseTestSetup extends BaseBusinessLogicMock {
protected ServiceValidator createServiceValidator() {
List<ComponentFieldValidator> componentFieldValidators = Arrays.asList(componentContactIdValidator,
- componentDescriptionValidator,
- componentIconValidator, componentNameValidator,
- new ComponentProjectCodeValidator(componentsUtils),
- componentTagsValidator);
+ componentDescriptionValidator,
+ componentIconValidator, componentNameValidator,
+ new ComponentProjectCodeValidator(componentsUtils),
+ componentTagsValidator);
List<ServiceFieldValidator> serviceFieldValidators = Arrays.asList(serviceCategoryValidator, new ServiceEnvironmentContextValidator(),
- serviceInstantiationTypeValidator, new ServiceNamingPolicyValidator(componentsUtils),
- serviceRoleValidator, serviceTypeValidator);
+ serviceInstantiationTypeValidator, new ServiceNamingPolicyValidator(componentsUtils),
+ serviceRoleValidator, serviceTypeValidator);
return new ServiceValidator(componentsUtils, componentFieldValidators, serviceFieldValidators);
}
-
-
@BeforeEach
public void setup() {
@@ -188,7 +183,8 @@ class ServiceBusinessLogicBaseTestSetup extends BaseBusinessLogicMock {
when(catalogOperation.updateCatalog(Mockito.any(), Mockito.any())).thenReturn(ActionStatus.OK);
// artifact bussinesslogic
ArtifactDefinition artifactDef = new ArtifactDefinition();
- when(artifactBl.createArtifactPlaceHolderInfo(Mockito.any(), Mockito.anyString(), Mockito.anyMap(), Mockito.any(User.class), Mockito.any(ArtifactGroupTypeEnum.class))).thenReturn(artifactDef);
+ when(artifactBl.createArtifactPlaceHolderInfo(Mockito.any(), Mockito.anyString(), Mockito.anyMap(), Mockito.any(User.class),
+ Mockito.any(ArtifactGroupTypeEnum.class))).thenReturn(artifactDef);
// createService
Service serviceResponse = createServiceObject(true);
@@ -204,27 +200,22 @@ class ServiceBusinessLogicBaseTestSetup extends BaseBusinessLogicMock {
Either<Resource, StorageOperationStatus> findLatestGeneric = Either.left(genericService);
when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_SERVICE_NAME)).thenReturn(findLatestGeneric);
-
- bl = new ServiceBusinessLogic(elementDao, groupOperation, groupInstanceOperation,
- groupTypeOperation, groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation,
- artifactBl, distributionEngine, componentInstanceBusinessLogic,
- serviceDistributionValidation, forwardingPathValidator, uiComponentDataConverter,
- artifactToscaOperation, componentContactIdValidator,
- componentNameValidator, componentTagsValidator, componentValidator,
- componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator, modelOperation);
+ bl = new ServiceBusinessLogic(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic, interfaceOperation,
+ interfaceLifecycleTypeOperation, artifactBl, distributionEngine, componentInstanceBusinessLogic, serviceDistributionValidation,
+ forwardingPathValidator, uiComponentDataConverter, artifactToscaOperation, componentContactIdValidator, componentNameValidator,
+ componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator,
+ modelOperation, serviceRoleValidator, serviceInstantiationTypeValidator, serviceCategoryValidator, serviceValidator, null);
bl.setComponentContactIdValidator(componentContactIdValidator);
bl.setComponentIconValidator(componentIconValidator);
bl.setComponentTagsValidator(componentTagsValidator);
bl.setComponentNameValidator(componentNameValidator);
bl.setComponentDescriptionValidator(componentDescriptionValidator);
bl.setComponentProjectCodeValidator(componentProjectCodeValidator);
- bl.setServiceCategoryValidator(serviceCategoryValidator);
bl.setServiceTypeValidator(serviceTypeValidator);
bl.setServiceFunctionValidator(serviceFunctionValidator);
bl.setElementDao(mockElementDao);
bl.setUserAdmin(mockUserAdmin);
bl.setArtifactBl(artifactBl);
- bl.setServiceValidator(createServiceValidator());
bl.setGraphLockOperation(graphLockOperation);
bl.setJanusGraphDao(mockJanusGraphDao);
bl.setToscaOperationFacade(toscaOperationFacade);
@@ -241,7 +232,7 @@ class ServiceBusinessLogicBaseTestSetup extends BaseBusinessLogicMock {
}
- protected Resource setupGenericServiceMock(){
+ protected Resource setupGenericServiceMock() {
Resource genericService = new Resource();
genericService.setVersion("1.0");
genericService.setToscaResourceName(GENERIC_SERVICE_NAME);
@@ -377,7 +368,8 @@ class ServiceBusinessLogicBaseTestSetup extends BaseBusinessLogicMock {
Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(eitherService);
Either<List<DistributionDeployEvent>, ActionStatus> emptyEventList = Either.left(Collections.emptyList());
- Mockito.when(auditingDao.getDistributionDeployByStatus(Mockito.anyString(), Mockito.eq("DResult"), Mockito.anyString())).thenReturn(emptyEventList);
+ Mockito.when(auditingDao.getDistributionDeployByStatus(Mockito.anyString(), Mockito.eq("DResult"), Mockito.anyString()))
+ .thenReturn(emptyEventList);
}
private void assertResponse(Either<Service, ResponseFormat> createResponse, ActionStatus expectedStatus, String... variables) {
@@ -386,7 +378,7 @@ class ServiceBusinessLogicBaseTestSetup extends BaseBusinessLogicMock {
protected void assertComponentException(ComponentException e, ActionStatus expectedStatus, String... variables) {
ResponseFormat actualResponse = e.getResponseFormat() != null ?
- e.getResponseFormat() : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ e.getResponseFormat() : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
assertResponse(actualResponse, expectedStatus, variables);
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java
index ac73a0da99..1d6a3ff673 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java
@@ -19,15 +19,15 @@ package org.openecomp.sdc.be.components.impl;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.anyList;
import static org.mockito.Mockito.anyMap;
import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.eq;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.openecomp.sdc.be.components.impl.ServiceImportBusinessLogic.CREATE_RESOURCE;
import fj.data.Either;
import java.io.IOException;
@@ -50,8 +50,8 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
+import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.openecomp.sdc.be.components.csar.CsarBusinessLogic;
import org.openecomp.sdc.be.components.csar.CsarInfo;
import org.openecomp.sdc.be.components.impl.artifact.ArtifactOperationInfo;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
@@ -61,9 +61,9 @@ import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.externalapi.servlet.ArtifactExternalServlet;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServletUtils;
import org.openecomp.sdc.be.info.NodeTypeInfoToUpdateArtifacts;
import org.openecomp.sdc.be.model.ArtifactDefinition;
@@ -96,13 +96,11 @@ import org.openecomp.sdc.be.model.UploadPropInfo;
import org.openecomp.sdc.be.model.UploadReqInfo;
import org.openecomp.sdc.be.model.UploadResourceInfo;
import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.ICapabilityTypeOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.servlets.AbstractValidationsServlet;
import org.openecomp.sdc.be.tosca.CsarUtils;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.api.Constants;
@@ -111,19 +109,14 @@ import org.openecomp.sdc.exception.ResponseFormat;
class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTestSetup {
@InjectMocks
- private static ServiceImportBusinessLogic serviceImportBusinessLogic;
-
- private ServiceBusinessLogic serviceBusinessLogic = mock(ServiceBusinessLogic.class);
- private CsarBusinessLogic csarBusinessLogic = mock(CsarBusinessLogic.class);
- private ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class);
- private ServiceImportParseLogic serviceImportParseLogic = mock(ServiceImportParseLogic.class);
- private ArtifactDefinition artifactDefinition = mock(ArtifactDefinition.class);
- private UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class);
- private ComponentInstanceBusinessLogic componentInstanceBusinessLogic = mock(ComponentInstanceBusinessLogic.class);
- private ComponentsUtils componentsUtils = mock(ComponentsUtils.class);
- private ServletUtils servletUtils = mock(ServletUtils.class);
- private ResourceImportManager resourceImportManager = mock(ResourceImportManager.class);
- private ArtifactsBusinessLogic artifactsBusinessLogic = mock(ArtifactsBusinessLogic.class);
+ private ServiceImportBusinessLogic sIBL;
+
+ @Mock
+ private ArtifactDefinition artifactDefinition;
+ @Mock
+ private ServletUtils servletUtils;
+ @Mock
+ private ResourceImportManager resourceImportManager;
private AbstractValidationsServlet servlet = new ArtifactExternalServlet(userBusinessLogic,
componentInstanceBusinessLogic, componentsUtils, servletUtils, resourceImportManager, artifactsBusinessLogic);
@@ -145,28 +138,69 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(artifactDefinition.getMandatory()).thenReturn(true);
when(artifactDefinition.getArtifactName()).thenReturn("creatorFullName");
when(artifactDefinition.getArtifactType()).thenReturn("TOSCA_CSAR");
-
- sIB1.setServiceBusinessLogic(serviceBusinessLogic);
- sIB1.setCsarBusinessLogic(csarBusinessLogic);
- sIB1.setServiceImportParseLogic(serviceImportParseLogic);
- sIB1.setToscaOperationFacade(toscaOperationFacade);
- sIB1.setComponentsUtils(componentsUtils);
- sIB1.setCsarArtifactsAndGroupsBusinessLogic(csarArtifactsAndGroupsBusinessLogic);
-
}
@Test
- void testGetComponentsUtils() {
- assertNotNull(serviceImportBusinessLogic.getComponentsUtils());
- }
+ void testCreateService_OK() {
+ Service oldService = createServiceObject(true);
+ String payloadName = "valid_vf";
+ Map<String, byte[]> payload = crateCsarFromPayload();
+ Service newService = createServiceObject(true);
+ newService.setComponentInstances(creatComponentInstances());
- @Test
- void testSetComponentsUtils() {
- assertNotNull(serviceImportBusinessLogic);
+ when(serviceBusinessLogic.validateServiceBeforeCreate(eq(newService), any(User.class), any(AuditingActionEnum.class)))
+ .thenReturn(Either.left(newService));
+ when(toscaOperationFacade.validateCsarUuidUniqueness(anyString())).thenReturn(StorageOperationStatus.OK);
+ CsarInfo csarInfo = getCsarInfo();
+ when(csarBusinessLogic.getCsarInfo(any(Service.class), any(), any(User.class), any(Map.class), anyString())).thenReturn(csarInfo);
+ when(serviceImportParseLogic.findNodeTypesArtifactsToHandle(any(Map.class), any(CsarInfo.class), any(Service.class)))
+ .thenReturn(Either.left(new HashMap<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>>()));
+ when(csarBusinessLogic.getParsedToscaYamlInfo(anyString(), anyString(), any(), any(CsarInfo.class), any(), any(Service.class)))
+ .thenReturn(getParsedToscaYamlInfo());
+ when(serviceBusinessLogic.lockComponentByName(newService.getSystemName(), oldService, CREATE_RESOURCE)).thenReturn(Either.left(true));
+ when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())).thenReturn(Either.left(createOldResource()));
+ when(serviceImportParseLogic.createServiceTransaction(oldService, csarInfo.getModifier(), false)).thenReturn(newService);
+ when(serviceImportParseLogic.createInputsOnService(eq(oldService), anyMap())).thenReturn(newService);
+ Assertions.assertDoesNotThrow(() -> {
+ when(serviceImportParseLogic.createSubstitutionFilterOnService(eq(oldService), any())).thenReturn(newService);
+ });
+ when(serviceImportParseLogic.getNodeTypesFromTemplate(anyMap())).thenReturn(getNodeTypes());
+ when(serviceImportParseLogic.createNodeTypeResourceFromYaml(anyString(), any(Map.Entry.class), any(User.class), anyMap(), any(Service.class),
+ anyBoolean(), any(), anyList(), anyBoolean(), any(CsarInfo.class), anyBoolean())).thenReturn(
+ new ImmutablePair<>(new Resource(), ActionStatus.OK));
+ when(serviceImportParseLogic.getComponentWithInstancesFilter()).thenReturn(new ComponentParametersView());
+ when(toscaOperationFacade.getToscaElement(anyString(), any(ComponentParametersView.class))).thenReturn(Either.left(newService));
+ when(serviceImportParseLogic.getComponentFilterAfterCreateRelations()).thenReturn(new ComponentParametersView());
+ when(toscaOperationFacade.getToscaElement(anyString(), any(ComponentParametersView.class))).thenReturn(Either.left(newService));
+ when(serviceImportParseLogic.findAvailableRequirement(anyString(), anyString(), any(UploadComponentInstanceInfo.class),
+ any(ComponentInstance.class), anyString())).thenReturn(Either.left(new RequirementDefinition()));
+ when(serviceImportParseLogic.findAvailableCapabilityByTypeOrName(any(RequirementDefinition.class), any(ComponentInstance.class),
+ any(UploadReqInfo.class))).thenReturn(new CapabilityDefinition());
+ when(componentsUtils.getResponseFormat(eq(ActionStatus.OK), anyString())).thenReturn(new ResponseFormat(200));
+ when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(newService));
+ doNothing().when(compositionBusinessLogic).setPositionsForComponentInstances(any(Service.class), anyString());
+ when(groupBusinessLogic.validateUpdateVfGroupNames(anyMap(), anyString())).thenReturn(Either.left(new HashMap<>()));
+ when(csarArtifactsAndGroupsBusinessLogic.deleteVFModules(any(Service.class), any(CsarInfo.class), anyBoolean(), anyBoolean()))
+ .thenReturn(Either.left(newService));
+ when(serviceImportParseLogic.getServiceWithGroups(anyString())).thenReturn(newService);
+ when(mockJanusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
+ when(graphLockOperation.unlockComponentByName(anyString(), anyString(), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
+
+ Service result = sIBL.createService(oldService, AuditingActionEnum.CREATE_RESOURCE, user, payload, payloadName);
+ assertNotNull(result);
+ assertNotNull(result.getComponentInstances());
+ assertEquals(1, result.getComponentInstances().size());
+ assertNotNull(result.getComponentInstances().get(0));
+ assertNotNull(result.getComponentInstances().get(0).getCapabilities());
+ assertEquals(1, result.getComponentInstances().get(0).getCapabilities().size());
+ assertNotNull(result.getComponentInstances().get(0).getRequirements());
+ assertEquals(1, result.getComponentInstances().get(0).getRequirements().size());
+ assertNotNull(result.getCategories());
+ assertEquals(1, result.getCategories().size());
}
@Test
- void testCreateService() {
+ void testCreateService_Fail_NotFoundNodeTypesArtifacts() {
Service oldService = createServiceObject(true);
String payloadName = "valid_vf";
Map<String, byte[]> payload = crateCsarFromPayload();
@@ -175,16 +209,14 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(serviceBusinessLogic.validateServiceBeforeCreate(any(Service.class), any(User.class), any(AuditingActionEnum.class)))
.thenReturn(Either.left(newService));
when(toscaOperationFacade.validateCsarUuidUniqueness(anyString())).thenReturn(StorageOperationStatus.OK);
- when(csarBusinessLogic.getCsarInfo(any(Service.class), any(),
- any(User.class), any(Map.class), anyString())).thenReturn(getCsarInfo());
- when(serviceImportParseLogic.findNodeTypesArtifactsToHandle(any(Map.class), any(CsarInfo.class),
- any(Service.class))).thenReturn(Either.right(ActionStatus.GENERAL_ERROR));
- when(csarBusinessLogic.getParsedToscaYamlInfo(anyString(), anyString(), any(),
- any(CsarInfo.class), anyString(), any(Service.class))).thenReturn(getParsedToscaYamlInfo());
-
- Assertions.assertThrows(ComponentException.class, () -> sIB1.createService(oldService,
- AuditingActionEnum.CREATE_RESOURCE, user, payload, payloadName));
+ when(csarBusinessLogic.getCsarInfo(any(Service.class), any(), any(User.class), any(Map.class), anyString())).thenReturn(getCsarInfo());
+ when(serviceImportParseLogic.findNodeTypesArtifactsToHandle(any(Map.class), any(CsarInfo.class), any(Service.class)))
+ .thenReturn(Either.right(ActionStatus.GENERAL_ERROR));
+ when(csarBusinessLogic.getParsedToscaYamlInfo(anyString(), anyString(), any(), any(CsarInfo.class), anyString(),
+ any(Service.class))).thenReturn(getParsedToscaYamlInfo());
+ Assertions.assertThrows(ComponentException.class,
+ () -> sIBL.createService(oldService, AuditingActionEnum.CREATE_RESOURCE, user, payload, payloadName));
}
@Test
@@ -200,7 +232,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
any(Map.class), anyString())).thenReturn(csarInfo);
when(serviceImportParseLogic.findNodeTypesArtifactsToHandle(any(Map.class), any(CsarInfo.class),
any(Service.class))).thenReturn(Either.left(map));
- Assertions.assertThrows(ComponentException.class, () -> sIB1.createServiceFromCsar(oldService,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.createServiceFromCsar(oldService,
user, payload, csarUUID));
}
@@ -219,14 +251,13 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
map.put("tosca_definitions_version", "123");
nodeTypesInfo.get(nodeName).setMappedToscaTemplate(map);
ParsedToscaYamlInfo parsedToscaYamlInfo = getParsedToscaYamlInfo();
- when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString()))
- .thenReturn(Either.left(resource));
+ when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())).thenReturn(Either.left(resource));
when(csarBusinessLogic.getParsedToscaYamlInfo(anyString(), anyString(), any(Map.class),
eq(csarInfo), anyString(), any(Component.class))).thenReturn(parsedToscaYamlInfo);
when(serviceBusinessLogic.lockComponentByName(anyString(), any(Service.class), anyString()))
.thenReturn(Either.left(true));
- Assertions.assertThrows(ComponentException.class, () -> sIB1.createServiceFromYaml(oldService,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.createServiceFromYaml(oldService,
topologyTemplateYaml, yamlName, nodeTypesInfo, csarInfo,
nodeTypesArtifactsToCreate, false, true, nodeName));
}
@@ -245,9 +276,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
ParsedToscaYamlInfo parsedToscaYamlInfo = getParsedToscaYamlInfo();
csfyp.setNodeTypesInfo(nodeTypesInfo);
csfyp.setParsedToscaYamlInfo(parsedToscaYamlInfo);
- when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString()))
- .thenReturn(Either.left(resource));
- Assertions.assertThrows(ComponentException.class, () -> sIB1.createServiceAndRIsFromYaml(oldService,
+ when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())).thenReturn(Either.left(resource));
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.createServiceAndRIsFromYaml(oldService,
false, nodeTypesArtifactsToCreate, false, true, csfyp));
}
@@ -265,9 +295,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
ParsedToscaYamlInfo parsedToscaYamlInfo = getParsedToscaYamlInfo();
csfyp.setNodeTypesInfo(nodeTypesInfo);
csfyp.setParsedToscaYamlInfo(parsedToscaYamlInfo);
- when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString()))
- .thenReturn(Either.left(resource));
- Assertions.assertThrows(ComponentException.class, () -> sIB1.createServiceAndRIsFromYaml(oldService,
+ when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())).thenReturn(Either.left(resource));
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.createServiceAndRIsFromYaml(oldService,
false, nodeTypesArtifactsToCreate, false, true, csfyp));
}
@@ -295,11 +324,9 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
nodeTypeInfoToUpdateArtifacts.setNodeTypesArtifactsToHandle(nodeTypesArtifactsToHandle);
Assertions.assertNotNull(
- sIB1.createOrUpdateArtifacts(operation, createdArtifacts, yamlFileName, csarInfo,
+ sIBL.createOrUpdateArtifacts(operation, createdArtifacts, yamlFileName, csarInfo,
preparedResource, nodeTypeInfoToUpdateArtifacts, true, true)
);
-
-
}
@Test
@@ -324,7 +351,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
.createResourceArtifactsFromCsar(any(CsarInfo.class), any(Resource.class), anyString(), anyString(),
anyList())).thenReturn(Either.left(resource));
Assertions.assertNotNull(
- sIB1.handleVfCsarArtifacts(resource,
+ sIBL.handleVfCsarArtifacts(resource,
csarInfo, createdArtifacts, artifactOperation, true, true));
}
@@ -350,7 +377,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
.createResourceArtifactsFromCsar(any(CsarInfo.class), any(Resource.class), anyString(), anyString(),
anyList())).thenReturn(Either.left(resource));
Assertions.assertNotNull(
- sIB1.handleVfCsarArtifacts(resource,
+ sIBL.handleVfCsarArtifacts(resource,
csarInfo, createdArtifacts, artifactOperation, true, true));
}
@@ -366,7 +393,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
resource.setDeploymentArtifacts(deploymentArtifacts);
Assertions.assertNotNull(resource);
Assertions.assertNotNull(csarInfo);
- sIB1.createOrUpdateSingleNonMetaArtifactToComstants(resource, csarInfo, artifactOperation, true, true);
+ sIBL.createOrUpdateSingleNonMetaArtifactToComstants(resource, csarInfo, artifactOperation, true, true);
}
@@ -377,7 +404,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true, true, ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE);
- Either<Resource, ResponseFormat> result = sIB1.createOrUpdateNonMetaArtifacts(csarInfo, resource,
+ Either<Resource, ResponseFormat> result = sIBL.createOrUpdateNonMetaArtifacts(csarInfo, resource,
createdArtifacts, true, true, artifactOperation);
assertEquals(result.left().value(), resource);
}
@@ -402,23 +429,11 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
List<CsarUtils.NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>();
Either<EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>>,
- ResponseFormat> result = sIB1.findVfCsarArtifactsToHandle(resource, artifactPathAndNameList, user);
+ ResponseFormat> result = sIBL.findVfCsarArtifactsToHandle(resource, artifactPathAndNameList, user);
assertNotNull(result.left().value());
}
@Test
- void testIsNonMetaArtifact() {
- ArtifactDefinition artifactDefinition = new ArtifactDefinition();
- artifactDefinition.setMandatory(false);
- artifactDefinition.setArtifactName("creatorFullName");
- artifactDefinition.setArtifactType("TOSCA_CSAR");
-
- boolean nonMetaArtifact = sIB1.isNonMetaArtifact(artifactDefinition);
- assertTrue(nonMetaArtifact);
-
- }
-
- @Test
void testOrganizeVfCsarArtifactsByArtifactOperation() {
List<CsarUtils.NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>();
artifactPathAndNameList.add(getNonMetaArtifactInfo());
@@ -431,7 +446,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Resource resource = createParseResourceObject(false);
Either<EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>>, ResponseFormat>
- enumMapResponseFormatEither = sIB1.organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList, existingArtifactsToHandle,
+ enumMapResponseFormatEither = sIBL.organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList,
+ existingArtifactsToHandle,
resource, user);
assertNotNull(enumMapResponseFormatEither.left().value());
}
@@ -448,8 +464,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
existingArtifactsToHandle.add(artifactDefinition);
Resource resource = createParseResourceObject(false);
Assertions.assertNotNull(
- sIB1.organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList, existingArtifactsToHandle, resource, user));
-
+ sIBL.organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList, existingArtifactsToHandle, resource,
+ user));
}
@Test
@@ -464,9 +480,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
EnumMap<>(ArtifactsBusinessLogic.ArtifactOperationEnum.class);
vfCsarArtifactsToHandle.put(ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE, artifactPathAndNameList);
Assertions.assertNotNull(
- sIB1.processCsarArtifacts(csarInfo,
+ sIBL.processCsarArtifacts(csarInfo,
resource, createdArtifacts, true, true, resStatus, vfCsarArtifactsToHandle));
-
}
@Test
@@ -494,31 +509,16 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Either<ArtifactDefinition, Operation> artifactDefinitionOperationEither = Either.left(artifactDefinition);
when(csarArtifactsAndGroupsBusinessLogic.createOrUpdateCsarArtifactFromJson(any(Resource.class), any(User.class),
any(Map.class), any(ArtifactOperationInfo.class))).thenReturn(Either.left(artifactDefinitionOperationEither));
+ when(artifactsBusinessLogic.handleDelete(anyString(), anyString(), any(User.class), any(Component.class), anyBoolean(), anyBoolean()))
+ .thenReturn(Either.left(artifactDefinition));
Assertions.assertNotNull(
- sIB1.createOrUpdateSingleNonMetaArtifact(resource, csarInfo, artifactPath,
+ sIBL.createOrUpdateSingleNonMetaArtifact(resource, csarInfo, artifactPath,
artifactFileName, artifactType, artifactGroupType, artifactLabel,
artifactDisplayName, artifactDescription, artifactId, artifactOperation,
createdArtifacts, true, true, true));
}
@Test
- void testHandleNodeTypeArtifacts() {
- Resource nodeTypeResource = createParseResourceObject(true);
- nodeTypeResource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
- Map<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle = new HashMap<>();
- List<ArtifactDefinition> artifactDefinitions = new ArrayList<>();
- ArtifactDefinition artifactDefinition = new ArtifactDefinition();
- artifactDefinition.setArtifactName("artifactName");
- artifactDefinitions.add(artifactDefinition);
- nodeTypeArtifactsToHandle.put(ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE,
- artifactDefinitions);
- List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
- Assertions.assertNotNull(
- sIB1.handleNodeTypeArtifacts(nodeTypeResource, nodeTypeArtifactsToHandle,
- createdArtifacts, user, true, true));
- }
-
- @Test
void testCreateOrUpdateServiceArtifacts() throws IOException {
ArtifactsBusinessLogic.ArtifactOperationEnum operation = ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE;
List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
@@ -543,7 +543,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(csarArtifactsAndGroupsBusinessLogic.updateResourceArtifactsFromCsar(any(CsarInfo.class), any(Service.class),
anyString(), anyString(), anyList(), anyBoolean(), anyBoolean())).thenReturn(Either.left(preparedService));
Assertions.assertNotNull(
- sIB1.createOrUpdateArtifacts(operation, createdArtifacts, yamlFileName, csarInfo,
+ sIBL.createOrUpdateArtifacts(operation, createdArtifacts, yamlFileName, csarInfo,
preparedService, nodeTypeInfoToUpdateArtifacts, true, true));
}
@@ -563,8 +563,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(csarArtifactsAndGroupsBusinessLogic.deleteVFModules(any(Service.class), any(CsarInfo.class), anyBoolean(), anyBoolean())).thenReturn(
Either.left(service));
Assertions.assertNotNull(
- sIB1.handleVfCsarArtifacts(service, csarInfo, createdArtifacts, artifactOperation, true, true));
-
+ sIBL.handleVfCsarArtifacts(service, csarInfo, createdArtifacts, artifactOperation, true, true));
}
@Test
@@ -588,7 +587,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(csarArtifactsAndGroupsBusinessLogic.createResourceArtifactsFromCsar(any(CsarInfo.class), any(Service.class),
anyString(), anyString(), anyList())).thenReturn(Either.left(service));
Assertions.assertNotNull(
- sIB1.handleVfCsarArtifacts(service,
+ sIBL.handleVfCsarArtifacts(service,
csarInfo, createdArtifacts, artifactOperation, true, true));
}
@@ -599,7 +598,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true, true, ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE);
- Either<Service, ResponseFormat> result = sIB1.createOrUpdateNonMetaArtifacts(csarInfo,
+ Either<Service, ResponseFormat> result = sIBL.createOrUpdateNonMetaArtifacts(csarInfo,
service, createdArtifacts, true, true, artifactOperation);
assertEquals(result.left().value(), service);
}
@@ -624,7 +623,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
List<CsarUtils.NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>();
Either<EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>>,
- ResponseFormat> result = sIB1.findVfCsarArtifactsToHandle(service, artifactPathAndNameList, user);
+ ResponseFormat> result = sIBL.findVfCsarArtifactsToHandle(service, artifactPathAndNameList, user);
assertNotNull(result.left().value());
}
@@ -641,7 +640,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Service service = createServiceObject(true);
Either<EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>>, ResponseFormat>
- enumMapResponseFormatEither = sIB1.organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList,
+ enumMapResponseFormatEither = sIBL.organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList,
existingArtifactsToHandle, service, user);
assertNotNull(enumMapResponseFormatEither.left().value());
}
@@ -658,7 +657,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
existingArtifactsToHandle.add(artifactDefinition);
Service service = createServiceObject(true);
Assertions.assertNotNull(
- sIB1.organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList, existingArtifactsToHandle, service, user));
+ sIBL.organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList, existingArtifactsToHandle, service, user));
}
@@ -674,16 +673,15 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
objects.add(getNonMetaArtifactInfo());
vfCsarArtifactsToHandle.put(ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE, objects);
Assertions.assertNotNull(
- sIB1.processCsarArtifacts(csarInfo,
- service, createdArtifacts, true, true, resStatus, vfCsarArtifactsToHandle));
-
+ sIBL.processCsarArtifacts(csarInfo, service, createdArtifacts, true, true, resStatus, vfCsarArtifactsToHandle));
}
@Test
void testGetValidArtifactNames() {
CsarInfo csarInfo = getCsarInfo();
Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
- Either<List<CsarUtils.NonMetaArtifactInfo>, String> result = sIB1.getValidArtifactNames(csarInfo, collectedWarningMessages);
+ Either<List<CsarUtils.NonMetaArtifactInfo>, String> result = sIBL.getValidArtifactNames(csarInfo,
+ collectedWarningMessages);
assertNotNull(result.left().value());
}
@@ -713,8 +711,10 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Either<ArtifactDefinition, Operation> artifactDefinitionOperationEither = Either.left(artifactDefinition);
when(csarArtifactsAndGroupsBusinessLogic.createOrUpdateCsarArtifactFromJson(any(Service.class), any(User.class),
anyMap(), any(ArtifactOperationInfo.class))).thenReturn(Either.left(artifactDefinitionOperationEither));
+ when(artifactsBusinessLogic.handleDelete(anyString(), anyString(), any(User.class), any(Component.class), anyBoolean(), anyBoolean()))
+ .thenReturn(Either.left(artifactDefinition));
Assertions.assertNotNull(
- sIB1.createOrUpdateSingleNonMetaArtifact(service, csarInfo, artifactPath, artifactFileName,
+ sIBL.createOrUpdateSingleNonMetaArtifact(service, csarInfo, artifactPath, artifactFileName,
artifactType, artifactGroupType, artifactLabel, artifactDisplayName,
artifactDescription, artifactId, artifactOperation, createdArtifacts,
true, true, true));
@@ -729,8 +729,10 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
String artifactLabel = "", artifactDisplayName = "", artifactDescription = "", artifactId = "artifactId";
ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true, true, ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE);
List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
+ when(artifactsBusinessLogic.handleDelete(anyString(), anyString(), any(User.class), any(Component.class), anyBoolean(), anyBoolean()))
+ .thenReturn(Either.left(artifactDefinition));
Assertions.assertNotNull(
- sIB1.createOrUpdateSingleNonMetaArtifact(service, csarInfo, artifactPath, artifactFileName,
+ sIBL.createOrUpdateSingleNonMetaArtifact(service, csarInfo, artifactPath, artifactFileName,
artifactType, artifactGroupType, artifactLabel, artifactDisplayName,
artifactDescription, artifactId, artifactOperation, createdArtifacts,
true, true, true));
@@ -740,29 +742,28 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
void testCreateGroupsOnResource() {
Service service = createServiceObject(true);
Map<String, GroupDefinition> groups = new HashMap<>();
- Assertions.assertNotNull(
- sIB1.createGroupsOnResource(service, groups));
+ Assertions.assertNotNull(sIBL.createGroupsOnResource(service, groups));
}
@Test
void testCreateGroupsOnResourceNull() {
Service service = createServiceObject(true);
Map<String, GroupDefinition> groups = new HashMap<>();
- Assertions.assertNotNull(sIB1.createGroupsOnResource(service, groups));
+ Assertions.assertNotNull(sIBL.createGroupsOnResource(service, groups));
}
@Test
void testUpdateGroupsMembersUsingResource() {
Service service = createServiceObject(true);
Map<String, GroupDefinition> groups = getGroups();
- Assertions.assertNotNull(sIB1.updateGroupsMembersUsingResource(groups, service));
+ Assertions.assertNotNull(sIBL.updateGroupsMembersUsingResource(groups, service));
}
@Test
void testUpdateGroupsMembersUsingResource_left() {
Service service = createServiceObject(true);
Map<String, GroupDefinition> groups = getGroups();
- Assertions.assertNotNull(sIB1.updateGroupsMembersUsingResource(groups, service));
+ Assertions.assertNotNull(sIBL.updateGroupsMembersUsingResource(groups, service));
}
@Test
@@ -782,7 +783,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
CsarInfo csarInfo = getCsarInfo();
Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate = new HashMap<>();
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.createRIAndRelationsFromYaml(yamlName, resource, uploadComponentInstanceInfoMap,
topologyTemplateYaml, nodeTypesNewCreatedArtifacts, nodeTypesInfo,
csarInfo, nodeTypesArtifactsToCreate, nodeName));
@@ -795,10 +796,10 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
resource.setComponentInstances(creatComponentInstances());
resource.setResourceType(ResourceTypeEnum.VF);
Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
- uploadResInstancesMap.put("uploadResInstancesMap", getuploadComponentInstanceInfo());
+ uploadResInstancesMap.put("uploadResInstancesMap", getUploadComponentInstanceInfo());
when(serviceImportParseLogic.getResourceAfterCreateRelations(any(Resource.class))).thenReturn(resource);
when(toscaOperationFacade.getToscaFullElement(anyString())).thenReturn(Either.left(resource));
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.createResourceInstancesRelations(user, yamlName, resource, uploadResInstancesMap));
}
@@ -809,10 +810,10 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
resource.setComponentInstances(creatComponentInstances());
resource.setResourceType(ResourceTypeEnum.VF);
Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
- uploadResInstancesMap.put("uploadResInstancesMap", getuploadComponentInstanceInfo());
+ uploadResInstancesMap.put("uploadResInstancesMap", getUploadComponentInstanceInfo());
when(serviceImportParseLogic.getResourceAfterCreateRelations(any(Resource.class))).thenReturn(resource);
when(toscaOperationFacade.getToscaFullElement(anyString())).thenReturn(Either.left(resource));
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.createResourceInstancesRelations(user, yamlName, resource, uploadResInstancesMap));
}
@@ -842,7 +843,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
uploadComponentInstanceInfo.setName("zxjTestImportServiceAb");
Assertions.assertNotNull(resource);
Assertions.assertNotNull(yamlName);
- sIB1.processComponentInstance(yamlName, resource, componentInstancesList, allDataTypes.left().value(), instProperties,
+ sIBL.processComponentInstance(yamlName, resource, componentInstancesList, allDataTypes.left().value(), instProperties,
instCapabilties, instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes,
originCompMap, instInputs, instNodeFilter, uploadComponentInstanceInfo);
}
@@ -867,7 +868,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo();
uploadComponentInstanceInfo.setName("zxjTestImportServiceAb0");
- Assertions.assertThrows(ComponentException.class, () -> sIB1.processComponentInstance(yamlName,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.processComponentInstance(yamlName,
resource, componentInstancesList, null, instProperties, instCapabilties,
instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, originCompMap,
instInputs, instNodeFilter, uploadComponentInstanceInfo));
@@ -896,7 +897,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
dataTypeDefinition.setName("dataTypeDefinitionName");
allDataTypes.put("dataTypeDefinitionMap", dataTypeDefinition);
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.addInputsValuesToRi(uploadComponentInstanceInfo, resource, originResource,
currentCompInstance, instInputs, allDataTypes));
}
@@ -919,7 +920,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
List<UploadPropInfo> propertyList = getPropertyList();
Assertions.assertNotNull(resource);
Assertions.assertNotNull(currPropertiesMap);
- sIB1.processProperty(resource, currentCompInstance, allDataTypes, currPropertiesMap, instPropList, propertyList);
+ sIBL.processProperty(resource, currentCompInstance, allDataTypes, currPropertiesMap, instPropList, propertyList);
}
@Test
@@ -930,8 +931,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(toscaOperationFacade.getToscaFullElement(anyString()))
.thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
- Assertions.assertThrows(ComponentException.class, () -> sIB1
- .handleSubstitutionMappings(resource, uploadResInstancesMap));
+ Assertions.assertThrows(ComponentException.class,
+ () -> sIBL.handleSubstitutionMappings(resource, uploadResInstancesMap));
}
@Test
@@ -942,8 +943,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(toscaOperationFacade.getToscaFullElement(anyString()))
.thenReturn(Either.left(resource));
- Assertions.assertThrows(ComponentException.class, () -> sIB1
- .handleSubstitutionMappings(resource, uploadResInstancesMap));
+ Assertions.assertThrows(ComponentException.class,
+ () -> sIBL.handleSubstitutionMappings(resource, uploadResInstancesMap));
}
@Test
@@ -959,8 +960,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, Resource> nodeNamespaceMap = new HashMap<>();
nodeNamespaceMap.put("resources", originResource);
- Assertions.assertThrows(ComponentException.class, () -> sIB1
- .createResourceInstances(yamlName, resource, uploadResInstancesMap, nodeNamespaceMap));
+ Assertions.assertThrows(ComponentException.class,
+ () -> sIBL.createResourceInstances(yamlName, resource, uploadResInstancesMap, nodeNamespaceMap));
}
@Test
@@ -980,7 +981,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
CsarInfo csarInfo = getCsarInfo();
Assertions.assertNotNull(resource);
- sIB1.handleNodeTypes(yamlName, resource, topologyTemplateYaml, needLock, nodeTypesArtifactsToHandle,
+ sIBL.handleNodeTypes(yamlName, resource, topologyTemplateYaml, needLock, nodeTypesArtifactsToHandle,
nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, nodeName);
}
@@ -997,7 +998,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
nodesInfo.put(nodeName, nodeTypeInfo);
CsarInfo csarInfo = getCsarInfo();
- Assertions.assertThrows(ComponentException.class, () -> sIB1.handleNestedVfc(resource,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.handleNestedVfc(resource,
nodeTypesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo, nodeName));
}
@@ -1017,28 +1018,11 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(serviceImportParseLogic.validateNestedDerivedFromDuringUpdate(any(Resource.class), any(Resource.class),
anyBoolean())).thenReturn(Either.left(true));
- Assertions.assertThrows(ComponentException.class, () -> sIB1.handleComplexVfc(resource,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.handleComplexVfc(resource,
nodeTypesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo, nodeName, yamlName));
}
@Test
- void testCreateResourcesFromYamlNodeTypesList1() {
- String yamlName = "group.yml";
- Resource resource = createParseResourceObject(false);
- Map<String, Object> mappedToscaTemplate = new HashMap<>();
- boolean needLock = true;
- Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>();
- List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>();
- Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>();
- CsarInfo csarInfo = getCsarInfo();
-
- Assertions.assertThrows(ComponentException.class, () -> sIB1
- .createResourcesFromYamlNodeTypesList(yamlName, resource, mappedToscaTemplate, needLock,
- nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo));
-
- }
-
- @Test
void testCreateNodeTypes1() {
String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test";
String yamlName = "group.yml";
@@ -1067,7 +1051,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
nodeTypes.put(nodeName, "");
Assertions.assertNotNull(resource);
- sIB1.createNodeTypes(yamlName,
+ sIBL.createNodeTypes(yamlName,
resource, needLock, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts,
nodeTypesInfo, csarInfo, mapToConvert, nodeTypes);
}
@@ -1101,7 +1085,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
anyMap(), anyList(), anyBoolean(), any(CsarInfo.class),
anyString(), anyBoolean())).thenReturn(immutablePair);
Assertions.assertNotNull(
- sIB1.createNodeTypeResourceFromYaml(yamlName, nodeNameValue, user, mapToConvert,
+ sIBL.createNodeTypeResourceFromYaml(yamlName, nodeNameValue, user, mapToConvert,
resourceVf, needLock, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts,
forceCertificationAllowed, csarInfo, isNested));
}
@@ -1119,7 +1103,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate = new HashMap<>();
String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test";
- Assertions.assertNotNull(sIB1
+ Assertions.assertNotNull(sIBL
.createRIAndRelationsFromYaml(yamlName, service, uploadComponentInstanceInfoMap,
topologyTemplateYaml, nodeTypesNewCreatedArtifacts, nodeTypesInfo,
csarInfo, nodeTypesArtifactsToCreate, nodeName));
@@ -1150,8 +1134,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
any(ComponentInstance.class), any(UploadReqInfo.class))).thenReturn(capabilityDefinition);
when(componentsUtils.getResponseFormat(any(ActionStatus.class), anyString())).thenReturn(responseFormat);
when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(service));
- Assertions.assertNotNull(sIB1
- .createServiceInstancesRelations(user, yamlName, service, uploadResInstancesMap));
+ Assertions.assertNotNull(sIBL.createServiceInstancesRelations(user, yamlName, service, uploadResInstancesMap));
}
@Test
@@ -1161,8 +1144,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
service.setComponentInstances(creatComponentInstances());
Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
- Assertions.assertThrows(ComponentException.class, () -> sIB1
- .createServiceInstancesRelations(user, yamlName, service, uploadResInstancesMap));
+ Assertions.assertThrows(ComponentException.class,
+ () -> sIBL.createServiceInstancesRelations(user, yamlName, service, uploadResInstancesMap));
}
@Test
@@ -1191,7 +1174,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
uploadComponentInstanceInfo.setName("zxjTestImportServiceAb");
Assertions.assertNotNull(service);
- sIB1.processComponentInstance(yamlName, service, componentInstancesList, allDataTypes.left().value(),
+ sIBL.processComponentInstance(yamlName, service, componentInstancesList, allDataTypes.left().value(),
instProperties, instCapabilties, instRequirements, instDeploymentArtifacts,
instArtifacts, instAttributes, originCompMap, instInputs, instNodeFilter,
uploadComponentInstanceInfo);
@@ -1217,7 +1200,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo();
uploadComponentInstanceInfo.setName("zxjTestImportServiceAb0");
- Assertions.assertThrows(ComponentException.class, () -> sIB1.processComponentInstance(yamlName,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.processComponentInstance(yamlName,
service, componentInstancesList, null, instProperties, instCapabilties,
instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, originCompMap,
instInputs, instNodeFilter, uploadComponentInstanceInfo));
@@ -1245,7 +1228,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>();
Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.addInputsValuesToRi(uploadComponentInstanceInfo, resource, originResource,
currentCompInstance, instInputs, allDataTypes));
}
@@ -1277,7 +1260,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
propertyList.add(propertyInfo);
Assertions.assertNotNull(resource);
- sIB1.processProperty(resource, currentCompInstance, allDataTypes, currPropertiesMap, instPropList, propertyList);
+ sIBL.processProperty(resource, currentCompInstance, allDataTypes, currPropertiesMap, instPropList, propertyList);
}
@Test
@@ -1286,8 +1269,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
List<InputDefinition> inputs = new ArrayList<>();
GetInputValueDataDefinition getInputIndex = new GetInputValueDataDefinition();
- Assertions.assertThrows(ComponentException.class, () -> sIB1.processGetInput(getInputValues,
- inputs, getInputIndex));
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.processGetInput(getInputValues, inputs, getInputIndex));
}
@Test
@@ -1302,7 +1284,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
getInputIndex.setInputName("InputName");
Assertions.assertNotNull(inputs);
- sIB1.processGetInput(getInputValues, inputs, getInputIndex);
+ sIBL.processGetInput(getInputValues, inputs, getInputIndex);
}
@Test
@@ -1323,11 +1305,11 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, List<ComponentInstanceProperty>> instProperties = new HashMap<>();
Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
ResponseFormat responseFormat = new ResponseFormat();
- when(serviceImportParseLogic.findInputByName(anyList(), any(GetInputValueDataDefinition.class)))
+ when(serviceImportParseLogic.findInputByName(eq(inputs), any(GetInputValueDataDefinition.class)))
.thenReturn(inputDefinition);
when(componentsUtils.getResponseFormat(any(ActionStatus.class))).thenReturn(responseFormat);
Assertions.assertNotNull(
- sIB1.addPropertyValuesToRi(uploadComponentInstanceInfo, resource, originResource,
+ sIBL.addPropertyValuesToRi(uploadComponentInstanceInfo, resource, originResource,
currentCompInstance, instProperties, allDataTypes));
}
@@ -1343,9 +1325,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
ResponseFormat responseFormat = new ResponseFormat();
when(componentsUtils.getResponseFormat(any(ActionStatus.class))).thenReturn(responseFormat);
Assertions.assertNotNull(
- sIB1.addPropertyValuesToRi(uploadComponentInstanceInfo, resource, originResource, currentCompInstance,
+ sIBL.addPropertyValuesToRi(uploadComponentInstanceInfo, resource, originResource, currentCompInstance,
instProperties, allDataTypes));
-
}
@Test
@@ -1370,7 +1351,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(serviceImportParseLogic.findInputByName(anyList(), any(GetInputValueDataDefinition.class)))
.thenReturn(inputDefinition);
Assertions.assertNotNull(
- sIB1.addPropertyValuesToRi(uploadComponentInstanceInfo, service, originResource,
+ sIBL.addPropertyValuesToRi(uploadComponentInstanceInfo, service, originResource,
currentCompInstance, instProperties, allDataTypes));
}
@@ -1386,7 +1367,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
ResponseFormat responseFormat = new ResponseFormat();
when(componentsUtils.getResponseFormat(any(ActionStatus.class))).thenReturn(responseFormat);
Assertions.assertNotNull(
- sIB1.addPropertyValuesToRi(uploadComponentInstanceInfo, service, originResource, currentCompInstance,
+ sIBL.addPropertyValuesToRi(uploadComponentInstanceInfo, service, originResource, currentCompInstance,
instProperties, allDataTypes));
}
@@ -1399,8 +1380,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
ComponentInstance currentCompInstance = new ComponentInstance();
Resource originResource = createParseResourceObject(false);
Assertions.assertNotNull(originResource);
- sIB1.processComponentInstanceCapabilities(null, instCapabilties,
- uploadComponentInstanceInfo, currentCompInstance, originResource);
+ sIBL.processComponentInstanceCapabilities(null, instCapabilties, uploadComponentInstanceInfo, currentCompInstance,
+ originResource);
}
@Test
@@ -1412,8 +1393,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Resource originResource = createParseResourceObject(false);
Assertions.assertNotNull(originResource);
- sIB1.processComponentInstanceCapabilities(null, instCapabilties, uploadComponentInstanceInfo,
- currentCompInstance, originResource);
+ sIBL.processComponentInstanceCapabilities(null, instCapabilties, uploadComponentInstanceInfo, currentCompInstance,
+ originResource);
}
@Test
@@ -1422,7 +1403,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, List<CapabilityDefinition>> originCapabilities = new HashMap<>();
Map<String, Map<String, UploadPropInfo>> newPropertiesMap = new HashMap<>();
Assertions.assertNull(allDataTypes);
- sIB1.updateCapabilityPropertiesValues(null, originCapabilities, newPropertiesMap, null);
+ sIBL.updateCapabilityPropertiesValues(null, originCapabilities, newPropertiesMap);
}
@Test
@@ -1431,7 +1412,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, UploadPropInfo> newProperties = new HashMap<>();
Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
Assertions.assertNotNull(allDataTypes);
- sIB1.updatePropertyValues(properties, newProperties, allDataTypes);
+ sIBL.updatePropertyValues(properties, newProperties, allDataTypes);
}
@Test
@@ -1443,8 +1424,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
when(serviceBusinessLogic.validatePropValueBeforeCreate(any(IPropertyInputCommon.class), anyString(), anyBoolean(), anyMap())).thenReturn(
"qw");
- Assertions.assertNotNull(
- sIB1.updatePropertyValue(property, propertyInfo, allDataTypes));
+ Assertions.assertNotNull(sIBL.updatePropertyValue(property, propertyInfo, allDataTypes));
}
@Test
@@ -1455,17 +1435,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
currentCompInstance.setComponentUid("currentCompInstance");
when(toscaOperationFacade.getToscaFullElement(anyString()))
.thenReturn(Either.left(createParseResourceObject(true)));
- Assertions.assertNotNull(
- sIB1.getOriginResource(yamlName, originCompMap, currentCompInstance));
- }
-
- @Test
- void testHandleSubstitutionMappings2() {
- Service service = createServiceObject(true);
- Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
- Assertions.assertNotNull(service);
-
- sIB1.handleSubstitutionMappings(service, uploadResInstancesMap);
+ Assertions.assertNotNull(sIBL.getOriginResource(yamlName, originCompMap, currentCompInstance));
}
@Test
@@ -1475,8 +1445,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = getUploadResInstancesMap();
when(toscaOperationFacade.deleteAllCalculatedCapabilitiesRequirements(any())).thenReturn(StorageOperationStatus.OK);
- Assertions.assertNotNull(
- sIB1.updateCalculatedCapReqWithSubstitutionMappings(resource, uploadResInstancesMap));
+ Assertions.assertNotNull(sIBL.updateCalculatedCapReqWithSubstitutionMappings(resource, uploadResInstancesMap));
}
@Test
@@ -1487,7 +1456,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<ComponentInstance, Map<String, List<RequirementDefinition>>> updatedInstRequirement = new HashMap<>();
Assertions.assertNotNull(componentInstances);
- sIB1.fillUpdatedInstCapabilitiesRequirements(componentInstances, uploadResInstancesMap,
+ sIBL.fillUpdatedInstCapabilitiesRequirements(componentInstances, uploadResInstancesMap,
updatedInstCapabilities, updatedInstRequirement);
}
@@ -1506,7 +1475,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
capabilitiesNamesToUpdate.put("mme_ipu_vdu.feature", "capabilitiesNamesToUpdate");
Assertions.assertNotNull(instance);
- sIB1.fillUpdatedInstCapabilities(updatedInstCapabilties, instance, capabilitiesNamesToUpdate);
+ sIBL.fillUpdatedInstCapabilities(updatedInstCapabilties, instance, capabilitiesNamesToUpdate);
}
@Test
@@ -1526,7 +1495,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
"requirementsNamesToUpdate");
Assertions.assertNotNull(instance);
- sIB1.fillUpdatedInstRequirements(updatedInstRequirements, instance, requirementsNamesToUpdate);
+ sIBL.fillUpdatedInstRequirements(updatedInstRequirements, instance, requirementsNamesToUpdate);
}
@Test
@@ -1535,7 +1504,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Service service = createServiceObject(true);
Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
- UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo nodesInfoValue = getUploadComponentInstanceInfo();
uploadResInstancesMap.put("uploadComponentInstanceInfo", nodesInfoValue);
List<ComponentInstance> componentInstancesList = creatComponentInstances();
ComponentInstance componentInstance = new ComponentInstance();
@@ -1561,7 +1530,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(componentsUtils.getResponseFormat(any(ActionStatus.class), anyString())).thenReturn(responseFormat);
Assertions.assertNotNull(service);
- sIB1.addRelationsToRI(yamlName, service, uploadResInstancesMap, componentInstancesList, relations);
+ sIBL.addRelationsToRI(yamlName, service, uploadResInstancesMap, componentInstancesList, relations);
}
@Test
@@ -1569,12 +1538,12 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
String yamlName = "group.yml";
Service service = createServiceObject(true);
Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
- UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo nodesInfoValue = getUploadComponentInstanceInfo();
uploadResInstancesMap.put("uploadComponentInstanceInfo", nodesInfoValue);
List<ComponentInstance> componentInstancesList = new ArrayList<>();
List<RequirementCapabilityRelDef> relations = new ArrayList<>();
- Assertions.assertThrows(ComponentException.class, () -> sIB1.addRelationsToRI(yamlName,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.addRelationsToRI(yamlName,
service, uploadResInstancesMap, componentInstancesList, relations));
}
@@ -1584,7 +1553,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Service service = createServiceObject(true);
service.setComponentInstances(creatComponentInstances());
- UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo nodesInfoValue = getUploadComponentInstanceInfo();
List<RequirementCapabilityRelDef> relations = new ArrayList<>();
RequirementDefinition requirementDefinition = new RequirementDefinition();
requirementDefinition.setName("zxjtestimportserviceab0.mme_ipu_vdu.dependency.test");
@@ -1598,8 +1567,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(serviceImportParseLogic.findAvailableCapabilityByTypeOrName(any(RequirementDefinition.class),
any(ComponentInstance.class), any(UploadReqInfo.class))).thenReturn(capabilityDefinition);
when(componentsUtils.getResponseFormat(any(ActionStatus.class), anyString())).thenReturn(responseFormat);
- Assertions.assertNotNull(
- sIB1.addRelationToRI(yamlName, service, nodesInfoValue, relations));
+ Assertions.assertNotNull(sIBL.addRelationToRI(yamlName, service, nodesInfoValue, relations));
}
@Test
@@ -1609,11 +1577,10 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
List<ComponentInstance> componentInstancesList = new ArrayList<>();
service.setComponentInstances(componentInstancesList);
ResponseFormat responseFormat = new ResponseFormat();
- UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo nodesInfoValue = getUploadComponentInstanceInfo();
List<RequirementCapabilityRelDef> relations = new ArrayList<>();
when(componentsUtils.getResponseFormat(any(ActionStatus.class), anyString())).thenReturn(responseFormat);
- Assertions.assertNotNull(
- sIB1.addRelationToRI(yamlName, service, nodesInfoValue, relations));
+ Assertions.assertNotNull(sIBL.addRelationToRI(yamlName, service, nodesInfoValue, relations));
}
@@ -1624,8 +1591,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(serviceImportParseLogic.getComponentFilterAfterCreateRelations()).thenReturn(componentParametersView);
when(toscaOperationFacade.getToscaElement(anyString(), any(ComponentParametersView.class)))
.thenReturn(Either.left(createServiceObject(true)));
- Assertions.assertNotNull(
- sIB1.getResourceAfterCreateRelations(service));
+ Assertions.assertNotNull(sIBL.getResourceAfterCreateRelations(service));
}
@Test
@@ -1633,20 +1599,20 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
String yamlName = "group.yml";
Service service = createServiceObject(true);
Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
- UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo nodesInfoValue = getUploadComponentInstanceInfo();
uploadResInstancesMap.put("uploadResInstancesMap", nodesInfoValue);
Map<String, Resource> nodeNamespaceMap = new HashMap<>();
Resource resource = createParseResourceObject(true);
resource.setToscaResourceName("toscaResourceName");
nodeNamespaceMap.put("nodeNamespaceMap", resource);
- Assertions.assertThrows(ComponentException.class, () -> sIB1
- .createServiceInstances(yamlName, service, uploadResInstancesMap, nodeNamespaceMap));
+ Assertions.assertThrows(ComponentException.class,
+ () -> sIBL.createServiceInstances(yamlName, service, uploadResInstancesMap, nodeNamespaceMap));
}
@Test
void testCreateAndAddResourceInstance() {
- UploadComponentInstanceInfo uploadComponentInstanceInfo = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo uploadComponentInstanceInfo = getUploadComponentInstanceInfo();
String yamlName = "group.yml";
Resource resource = createParseResourceObject(false);
Resource originResource = createParseResourceObject(true);
@@ -1656,14 +1622,14 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, Resource> existingnodeTypeMap = new HashMap<>();
Map<ComponentInstance, Resource> resourcesInstancesMap = new HashMap<>();
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.createAndAddResourceInstance(uploadComponentInstanceInfo, yamlName, resource,
nodeNamespaceMap, existingnodeTypeMap, resourcesInstancesMap));
}
@Test
void testCreateAndAddResourceInstances() {
- UploadComponentInstanceInfo uploadComponentInstanceInfo = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo uploadComponentInstanceInfo = getUploadComponentInstanceInfo();
String yamlName = "group.yml";
Service service = createServiceObject(true);
service.setServiceType("services");
@@ -1674,7 +1640,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, Resource> existingnodeTypeMap = new HashMap<>();
Map<ComponentInstance, Resource> resourcesInstancesMap = new HashMap<>();
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.createAndAddResourceInstance(uploadComponentInstanceInfo, yamlName, service,
nodeNamespaceMap, existingnodeTypeMap, resourcesInstancesMap));
}
@@ -1682,7 +1648,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
@Test
void testValidateResourceInstanceBeforeCreate() {
String yamlName = "group.yml";
- UploadComponentInstanceInfo uploadComponentInstanceInfo = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo uploadComponentInstanceInfo = getUploadComponentInstanceInfo();
Resource originResource = createParseResourceObject(true);
ResourceMetadataDataDefinition componentMetadataDataDefinition = new ResourceMetadataDataDefinition();
componentMetadataDataDefinition.setState(LifecycleStateEnum.CERTIFIED.name());
@@ -1694,10 +1660,9 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
originResource.setResourceType(ResourceTypeEnum.VF);
Map<String, Resource> nodeNamespaceMap = new HashMap<>();
nodeNamespaceMap.put("resources", originResource);
- when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString()))
- .thenReturn(Either.left(originResource));
+ when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())).thenReturn(Either.left(originResource));
Assertions.assertNotNull(
- sIB1.validateResourceInstanceBeforeCreate(yamlName, uploadComponentInstanceInfo, nodeNamespaceMap));
+ sIBL.validateResourceInstanceBeforeCreate(yamlName, uploadComponentInstanceInfo, nodeNamespaceMap));
}
@Test
@@ -1712,20 +1677,19 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, NodeTypeInfo> nodeTypesInfo = getNodeTypesInfo();
CsarInfo csarInfo = getCsarInfo();
String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test";
- when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString()))
- .thenReturn(Either.left(createOldResource()));
+ when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())).thenReturn(Either.left(createOldResource()));
Assertions.assertNotNull(service);
- sIB1.handleServiceNodeTypes(yamlName, service, topologyTemplateYaml, needLock,
- nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo,
- csarInfo, nodeName);
+ sIBL.handleServiceNodeTypes(yamlName, service, topologyTemplateYaml, needLock, nodeTypesArtifactsToHandle,
+ nodeTypesNewCreatedArtifacts,
+ nodeTypesInfo, csarInfo, nodeName);
}
@Test
void testValidateResourceNotExisted() {
String type = "org.openecomp.resource.vf";
- Assertions.assertThrows(ComponentException.class, () -> sIB1.validateResourceNotExisted(type));
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.validateResourceNotExisted(type));
}
@Test
@@ -1737,7 +1701,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
CsarInfo csarInfo = getCsarInfo();
String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test";
- Assertions.assertThrows(ComponentException.class, () -> sIB1.handleNestedVF(service,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.handleNestedVF(service,
nodeTypesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo, nodeName));
}
@@ -1750,7 +1714,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
CsarInfo csarInfo = getCsarInfo();
String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test";
- Assertions.assertThrows(ComponentException.class, () -> sIB1.handleNestedVfc(service,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.handleNestedVfc(service,
nodeTypesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo, nodeName));
}
@@ -1769,7 +1733,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(serviceImportParseLogic.validateNestedDerivedFromDuringUpdate(any(Resource.class), any(Resource.class), anyBoolean()))
.thenReturn(Either.left(true));
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.handleComplexVfc(nodeTypesArtifactsToHandle, createdArtifacts, nodesInfo,
csarInfo, nodeName, yamlName));
}
@@ -1787,7 +1751,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(toscaOperationFacade.getFullLatestComponentByToscaResourceName(anyString()))
.thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.handleComplexVfc(nodeTypesArtifactsToHandle, createdArtifacts, nodesInfo,
csarInfo, nodeName, yamlName));
}
@@ -1806,7 +1770,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Resource oldComplexVfc = createParseResourceObject(false);
Resource newComplexVfc = createParseResourceObject(true);
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.handleComplexVfc(nodeTypesArtifactsToHandle, createdArtifacts, nodesInfo,
csarInfo, nodeName, yamlName, oldComplexVfc, newComplexVfc));
}
@@ -1836,7 +1800,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
any(Resource.class), any(AuditingActionEnum.class), anyBoolean())).thenReturn(Either.left(true));
when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class)))
.thenReturn(Either.left(newResource));
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.updateResourceFromYaml(oldResource, newResource, actionEnum, createdArtifacts,
yamlFileName, yamlFileContent, csarInfo, nodeTypesInfo,
nodeTypesArtifactsToHandle, nodeName, isNested));
@@ -1861,14 +1825,13 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(csarBusinessLogic.getParsedToscaYamlInfo(anyString(), anyString(), anyMap(), any(CsarInfo.class),
anyString(), any(Component.class))).thenReturn(getParsedToscaYamlInfo());
- when(serviceBusinessLogic.fetchAndSetDerivedFromGenericType(any(Resource.class))).thenReturn(resource);
- when(toscaOperationFacade.validateComponentNameExists(anyString(), any(ResourceTypeEnum.class)
- , any(ComponentTypeEnum.class))).thenReturn(Either.left(false));
+ when(serviceBusinessLogic.fetchAndSetDerivedFromGenericType(any(Component.class))).thenReturn(resource);
+ when(toscaOperationFacade.validateComponentNameExists(anyString(), any(ResourceTypeEnum.class), any(ComponentTypeEnum.class)))
+ .thenReturn(Either.left(false));
when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(Either.left(resource));
- Assertions.assertThrows(ComponentException.class, () -> sIB1.createResourceFromYaml(resource,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.createResourceFromYaml(resource,
topologyTemplateYaml, yamlName, nodeTypesInfo, csarInfo,
nodeTypesArtifactsToCreate, shouldLock, inTransaction, nodeName));
-
}
@Test
@@ -1898,12 +1861,12 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(serviceBusinessLogic.lockComponentByName(anyString(), any(), anyString()))
.thenReturn(Either.left(true));
- when(toscaOperationFacade.validateComponentNameExists(anyString(), any(ResourceTypeEnum.class)
- , any(ComponentTypeEnum.class))).thenReturn(Either.left(false));
+ when(toscaOperationFacade.validateComponentNameExists(anyString(), any(ResourceTypeEnum.class), any(ComponentTypeEnum.class)))
+ .thenReturn(Either.left(false));
when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(Either.left(resource));
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.createResourceAndRIsFromYaml(yamlName, resource, parsedToscaYamlInfo, actionEnum,
isNormative, createdArtifacts, topologyTemplateYaml, nodeTypesInfo, csarInfo,
nodeTypesArtifactsToCreate, shouldLock, inTransaction, nodeName));
@@ -1918,7 +1881,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
groupDefinition.setUniqueId("groupDefinitionUniqueId");
groupDefinition.setName("groupDefinition");
groupDefinitionList.add(groupDefinition);
- Assertions.assertNotNull(sIB1.createGroupsOnResource(resource, groups));
+ Assertions.assertNotNull(sIBL.createGroupsOnResource(resource, groups));
}
@Test
@@ -1926,7 +1889,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Resource resource = createParseResourceObject(false);
Map<String, GroupDefinition> groups = null;
- Either<Resource, ResponseFormat> result = sIB1.createGroupsOnResource(resource, groups);
+ Either<Resource, ResponseFormat> result = sIBL.createGroupsOnResource(resource, groups);
assertEquals(result.left().value(), resource);
}
@@ -1934,14 +1897,14 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
void testUpdateGroupsMembersUsingResource2() {
Resource resource = createParseResourceObject(true);
Map<String, GroupDefinition> groups = getGroups();
- Assertions.assertNotNull(sIB1.updateGroupsMembersUsingResource(groups, resource));
+ Assertions.assertNotNull(sIBL.updateGroupsMembersUsingResource(groups, resource));
}
@Test
void testUpdateGroupsMembersUsingResource_left2() {
Resource resource = createParseResourceObject(true);
Map<String, GroupDefinition> groups = getGroups();
- Assertions.assertNotNull(sIB1.updateGroupsMembersUsingResource(groups, resource));
+ Assertions.assertNotNull(sIBL.updateGroupsMembersUsingResource(groups, resource));
}
@Test
@@ -1955,7 +1918,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
members.put("zxjTestImportServiceAb", getGroupsYaml());
Assertions.assertNotNull(component);
- sIB1.updateGroupMembers(groups, updatedGroupDefinition, component, componentInstances, groupName, members);
+ sIBL.updateGroupMembers(groups, updatedGroupDefinition, component, componentInstances, groupName, members);
}
@Test
@@ -1968,7 +1931,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, String> members = new HashMap<>();
members.put("zxjTestImportServiceAb", getGroupsYaml());
- Assertions.assertThrows(ComponentException.class, () -> sIB1.updateGroupMembers(groups,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.updateGroupMembers(groups,
updatedGroupDefinition, component, componentInstances, groupName, members));
}
@@ -1977,11 +1940,10 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Resource resource = createParseResourceObject(false);
resource.setComponentType(ComponentTypeEnum.RESOURCE);
boolean isNormative = true;
- when(toscaOperationFacade.validateComponentNameExists(anyString(), any(), any()))
+ when(toscaOperationFacade.validateComponentNameExists(anyString(), any(ResourceTypeEnum.class), any(ComponentTypeEnum.class)))
.thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
- Assertions.assertThrows(ComponentException.class, () -> sIB1.createResourceTransaction(resource,
- user, isNormative));
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.createResourceTransaction(resource, user, isNormative));
}
@Test
@@ -1989,22 +1951,18 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Resource resource = createParseResourceObject(false);
resource.setComponentType(ComponentTypeEnum.RESOURCE);
boolean isNormative = true;
- when(toscaOperationFacade.validateComponentNameExists(anyString(), any(), any()))
- .thenReturn(Either.left(true));
+ when(toscaOperationFacade.validateComponentNameExists(anyString(), any(), any())).thenReturn(Either.left(true));
- Assertions.assertThrows(ComponentException.class, () -> sIB1
- .createResourceTransaction(resource, user, isNormative));
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.createResourceTransaction(resource, user, isNormative));
}
@Test
void setCreateResourceTransaction_Left() {
Resource resource = createParseResourceObject(false);
resource.setComponentType(ComponentTypeEnum.RESOURCE);
- when(toscaOperationFacade.validateComponentNameExists(anyString(), any(), any()))
- .thenReturn(Either.left(false));
+ when(toscaOperationFacade.validateComponentNameExists(anyString(), any(), any())).thenReturn(Either.left(false));
when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(Either.left(resource));
- Assertions.assertNotNull(
- sIB1.createResourceTransaction(resource, user, false));
+ Assertions.assertNotNull(sIBL.createResourceTransaction(resource, user, false));
}
@Test
@@ -2017,9 +1975,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
any(Resource.class), any(AuditingActionEnum.class), anyBoolean())).thenReturn(Either.left(true));
when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class)))
.thenReturn(Either.left(newResource));
- Assertions.assertNotNull(
- sIB1.updateExistingResourceByImport(newResource, oldResource, user,
- true, false, true));
+ Assertions.assertNotNull(sIBL.updateExistingResourceByImport(newResource, oldResource, user, true, false, true));
}
@Test
@@ -2027,7 +1983,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Resource newResource = createNewResource();
Resource oldResource = createOldResource();
- sIB1.createNewResourceToOldResource(newResource, oldResource, user);
+ sIBL.createNewResourceToOldResource(newResource, oldResource, user);
assertEquals(newResource.getSystemName(), oldResource.getSystemName());
}
@@ -2042,7 +1998,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>();
CsarInfo csarInfo = getCsarInfo();
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.createResourcesFromYamlNodeTypesList(yamlName, service, mappedToscaTemplate, needLock,
nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo));
}
@@ -2072,7 +2028,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
nodeTypes.put("org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test",
nodeTypeInfo);
- Assertions.assertThrows(ComponentException.class, () -> sIB1.createNodeTypes(yamlName,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.createNodeTypes(yamlName,
service, needLock, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts,
nodeTypesInfo, csarInfo, mapToConvert, nodeTypes));
}
@@ -2111,10 +2067,9 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
anyBoolean())).thenReturn(getResourceCreated());
Assertions.assertNotNull(service);
- sIB1.createNodeTypes(yamlName,
+ sIBL.createNodeTypes(yamlName,
service, needLock, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts,
nodeTypesInfo, csarInfo, mapToConvert, nodeTypes);
-
}
protected ImmutablePair<Resource, ActionStatus> getResourceCreated() {
@@ -2206,7 +2161,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
return propertyList;
}
- protected Map<String, NodeTypeInfo> getNodeTypesInfo() {
+ private Map<String, NodeTypeInfo> getNodeTypesInfo() {
Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>();
NodeTypeInfo nodeTypeInfo = new NodeTypeInfo();
Map<String, Object> mappedToscaTemplate = new HashMap<>();
@@ -2218,9 +2173,21 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
return nodeTypesInfo;
}
- protected Map<String, UploadComponentInstanceInfo> getUploadResInstancesMap() {
+ private Map<String, Object> getNodeTypes() {
+ Map<String, Object> nodeTypesInfo = new HashMap<>();
+ NodeTypeInfo nodeTypeInfo = new NodeTypeInfo();
+ Map<String, Object> mappedToscaTemplate = new HashMap<>();
+ nodeTypeInfo.setNested(true);
+ nodeTypeInfo.setTemplateFileName("templateFileName");
+ nodeTypeInfo.setMappedToscaTemplate(mappedToscaTemplate);
+ String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test";
+ nodeTypesInfo.put(nodeName, nodeTypeInfo);
+ return nodeTypesInfo;
+ }
+
+ private Map<String, UploadComponentInstanceInfo> getUploadResInstancesMap() {
Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
- UploadComponentInstanceInfo uploadComponentInstanceInfo = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo uploadComponentInstanceInfo = getUploadComponentInstanceInfo();
Map<String, String> capabilitiesNamesToUpdate = new HashMap<>();
capabilitiesNamesToUpdate.put("mme_ipu_vdu.feature", "capabilitiesNamesToUpdate");
Map<String, String> requirementsNamesToUpdate = new HashMap<>();
@@ -2324,10 +2291,10 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
return componentInstances;
}
- protected CreateServiceFromYamlParameter getCsfyp() {
+ private CreateServiceFromYamlParameter getCsfyp() {
CreateServiceFromYamlParameter csfyp = new CreateServiceFromYamlParameter();
List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
- Map<String, NodeTypeInfo> nodeTypesInfo = new HashedMap();
+ Map<String, NodeTypeInfo> nodeTypesInfo = getNodeTypesInfo();
csfyp.setNodeName("org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test");
csfyp.setTopologyTemplateYaml(getMainTemplateContent("service_import_template.yml"));
@@ -2341,12 +2308,11 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
return csfyp;
}
- protected ParsedToscaYamlInfo getParsedToscaYamlInfo() {
+ private ParsedToscaYamlInfo getParsedToscaYamlInfo() {
ParsedToscaYamlInfo parsedToscaYamlInfo = new ParsedToscaYamlInfo();
Map<String, InputDefinition> inputs = new HashMap<>();
Map<String, UploadComponentInstanceInfo> instances = new HashMap<>();
- UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo();
- uploadComponentInstanceInfo.setName("uploadComponentInstanceInfo");
+ UploadComponentInstanceInfo uploadComponentInstanceInfo = getUploadComponentInstanceInfo();
instances.put("instances", uploadComponentInstanceInfo);
Map<String, GroupDefinition> groups = new HashMap<>();
Map<String, PolicyDefinition> policies = new HashMap<>();
@@ -2369,13 +2335,12 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
protected CsarInfo getCsarInfo() {
String csarUuid = "0010";
- User user = new User();
+ User user = new User("jh0003");
Map<String, byte[]> csar = crateCsarFromPayload();
String vfReousrceName = "resouceName";
String mainTemplateName = "mainTemplateName";
String mainTemplateContent = getMainTemplateContent("service_import_template.yml");
- CsarInfo csarInfo = new CsarInfo(user, csarUuid, csar, vfReousrceName, mainTemplateName, mainTemplateContent, false);
- return csarInfo;
+ return new CsarInfo(user, csarUuid, csar, vfReousrceName, mainTemplateName, mainTemplateContent, false);
}
protected CsarUtils.NonMetaArtifactInfo getNonMetaArtifactInfo() {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java
index 5dfa28765b..8ff8163128 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java
@@ -37,15 +37,18 @@ import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
import org.junit.jupiter.api.BeforeEach;
+import org.mockito.Mock;
import org.mockito.Mockito;
import org.openecomp.sdc.ElementOperationMock;
-import org.openecomp.sdc.be.auditing.impl.AuditingManager;
import org.openecomp.sdc.be.components.csar.CsarArtifactsAndGroupsBusinessLogic;
+import org.openecomp.sdc.be.components.csar.CsarBusinessLogic;
import org.openecomp.sdc.be.components.csar.CsarInfo;
import org.openecomp.sdc.be.components.distribution.engine.DistributionEngine;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic;
import org.openecomp.sdc.be.components.impl.utils.CreateServiceFromYamlParameter;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
+import org.openecomp.sdc.be.components.merge.resource.ResourceDataMergeBusinessLogic;
import org.openecomp.sdc.be.components.path.ForwardingPathValidator;
import org.openecomp.sdc.be.components.validation.NodeFilterValidator;
import org.openecomp.sdc.be.components.validation.ServiceDistributionValidation;
@@ -107,7 +110,6 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
-import org.openecomp.sdc.be.resources.data.auditing.ResourceAdminEvent;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
@@ -133,24 +135,33 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM
private static final String RESOURCE_SUBCATEGORY = "Router";
protected final ServletContext servletContext = Mockito.mock(ServletContext.class);
protected final ComponentValidator componentValidator = Mockito.mock(ComponentValidator.class);
- protected ServiceImportBusinessLogic sIB1;
- protected UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
+ final DistributionEngine distributionEngine = Mockito.mock(DistributionEngine.class);
+ final ServiceDistributionValidation serviceDistributionValidation = Mockito.mock(ServiceDistributionValidation.class);
+ final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
+ final ForwardingPathValidator forwardingPathValidator = Mockito.mock(ForwardingPathValidator.class);
+ final UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
+ final NodeFilterOperation serviceFilterOperation = Mockito.mock(NodeFilterOperation.class);
+ final NodeFilterValidator serviceFilterValidator = Mockito.mock(NodeFilterValidator.class);
+ // final ServiceBusinessLogic serviceBusinessLogic = Mockito.mock(ServiceBusinessLogic.class);
+ final CsarBusinessLogic csarBusinessLogic = Mockito.mock(CsarBusinessLogic.class);
+ final LifecycleBusinessLogic lifecycleBusinessLogic = Mockito.mock(LifecycleBusinessLogic.class);
+ final CompositionBusinessLogic compositionBusinessLogic = Mockito.mock(CompositionBusinessLogic.class);
+ final ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic = Mockito.mock(ResourceDataMergeBusinessLogic.class);
+ final ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic = Mockito.mock(ComponentNodeFilterBusinessLogic.class);
+ protected UserBusinessLogic userBusinessLogic = Mockito.mock(UserBusinessLogic.class);
protected WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
protected WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
protected ResponseFormatManager responseManager = null;
- protected ComponentsUtils componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class));
+ protected ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class);
protected AuditCassandraDao auditingDao = Mockito.mock(AuditCassandraDao.class);
- protected ArtifactsBusinessLogic artifactBl = Mockito.mock(ArtifactsBusinessLogic.class);
+ protected ArtifactsBusinessLogic artifactsBusinessLogic = Mockito.mock(ArtifactsBusinessLogic.class);
protected GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
protected JanusGraphDao mockJanusGraphDao = Mockito.mock(JanusGraphDao.class);
protected ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
protected CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic = Mockito.mock(CsarArtifactsAndGroupsBusinessLogic.class);
protected GenericTypeBusinessLogic genericTypeBusinessLogic = Mockito.mock(GenericTypeBusinessLogic.class);
protected UserValidations userValidations = Mockito.mock(UserValidations.class);
- protected ResourceAdminEvent auditArchive1 = Mockito.mock(ResourceAdminEvent.class);
protected CatalogOperation catalogOperation = Mockito.mock(CatalogOperation.class);
- protected ResourceAdminEvent auditArchive2 = Mockito.mock(ResourceAdminEvent.class);
- protected ResourceAdminEvent auditRestore = Mockito.mock(ResourceAdminEvent.class);
protected ServiceImportParseLogic serviceImportParseLogic = Mockito.mock(ServiceImportParseLogic.class);
protected ServiceTypeValidator serviceTypeValidator = new ServiceTypeValidator(componentsUtils);
protected ServiceRoleValidator serviceRoleValidator = new ServiceRoleValidator(componentsUtils);
@@ -164,16 +175,11 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM
protected ComponentNameValidator componentNameValidator = new ComponentNameValidator(componentsUtils, toscaOperationFacade);
protected User user = null;
protected Resource genericService = null;
+ @Mock
+ protected ServiceBusinessLogic serviceBusinessLogic;
IElementOperation mockElementDao = new ElementOperationMock();
protected ServiceCategoryValidator serviceCategoryValidator = new ServiceCategoryValidator(componentsUtils, mockElementDao);
protected ServiceValidator serviceValidator = createServiceValidator();
- DistributionEngine distributionEngine = Mockito.mock(DistributionEngine.class);
- ServiceDistributionValidation serviceDistributionValidation = Mockito.mock(ServiceDistributionValidation.class);
- ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
- ForwardingPathValidator forwardingPathValidator = Mockito.mock(ForwardingPathValidator.class);
- UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
- NodeFilterOperation serviceFilterOperation = Mockito.mock(NodeFilterOperation.class);
- NodeFilterValidator serviceFilterValidator = Mockito.mock(NodeFilterValidator.class);
public ServiceImportBussinessLogicBaseTestSetup() {
@@ -205,7 +211,7 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM
user.setLastName("Hendrix");
user.setRole(Role.ADMIN.name());
- when(mockUserAdmin.getUser("jh0003", false)).thenReturn(user);
+ when(userBusinessLogic.getUser("jh0003", false)).thenReturn(user);
when(userValidations.validateUserExists("jh0003")).thenReturn(user);
when(userValidations.validateUserNotEmpty(eq(user), anyString())).thenReturn(user);
// Servlet Context attributes
@@ -218,7 +224,7 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM
when(catalogOperation.updateCatalog(Mockito.any(), Mockito.any())).thenReturn(ActionStatus.OK);
// artifact bussinesslogic
ArtifactDefinition artifactDef = new ArtifactDefinition();
- when(artifactBl.createArtifactPlaceHolderInfo(Mockito.any(), Mockito.anyString(), Mockito.anyMap(), Mockito.any(User.class),
+ when(artifactsBusinessLogic.createArtifactPlaceHolderInfo(Mockito.any(), Mockito.anyString(), Mockito.anyMap(), Mockito.any(User.class),
Mockito.any(ArtifactGroupTypeEnum.class))).thenReturn(artifactDef);
// createService
@@ -250,14 +256,6 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM
when(serviceImportParseLogic.isArtifactDeletionRequired(anyString(), any(), anyBoolean())).thenReturn(true);
- sIB1 = new ServiceImportBusinessLogic(elementDao, groupOperation, groupInstanceOperation,
- groupTypeOperation, groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation,
- artifactBl, distributionEngine, componentInstanceBusinessLogic,
- serviceDistributionValidation, forwardingPathValidator, uiComponentDataConverter, serviceFilterOperation,
- serviceFilterValidator, artifactToscaOperation, componentContactIdValidator,
- componentNameValidator, componentTagsValidator, componentValidator,
- componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator);
-
mockAbstract();
responseManager = ResponseFormatManager.getInstance();
@@ -267,6 +265,7 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM
Service service = new Service();
service.setUniqueId("sid");
service.setName("Service");
+ service.setSystemName("SystemName");
CategoryDefinition category = new CategoryDefinition();
category.setName(SERVICE_CATEGORY);
category.setIcons(Collections.singletonList("defaulticon"));
@@ -323,6 +322,7 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM
protected Resource createParseResourceObject(boolean afterCreate) {
Resource resource = new Resource();
+ resource.setUniqueId(COMPONNET_ID);
resource.setName(RESOURCE_NAME);
resource.setToscaResourceName(RESOURCE_TOSCA_NAME);
resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
@@ -371,9 +371,9 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM
return groups;
}
- protected UploadComponentInstanceInfo getuploadComponentInstanceInfo() {
+ protected UploadComponentInstanceInfo getUploadComponentInstanceInfo() {
UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo();
- uploadComponentInstanceInfo.setType("resources");
+ uploadComponentInstanceInfo.setType("My-Resource_Tosca_Name");
Collection<String> directives = new Collection<String>() {
@Override
public int size() {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportManagerTest.java
index f723a1523f..1b5b7d8a7e 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportManagerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportManagerTest.java
@@ -18,6 +18,9 @@
package org.openecomp.sdc.be.components.impl;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -27,17 +30,13 @@ import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.UploadServiceInfo;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-
@ExtendWith(MockitoExtension.class)
class ServiceImportManagerTest {
+ private final ServiceBusinessLogic serviceBusinessLogic = Mockito.mock(ServiceBusinessLogic.class);
@InjectMocks
private ServiceImportManager serviceImportManager;
- public static final ServiceBusinessLogic serviceBusinessLogic = Mockito.mock(ServiceBusinessLogic.class);
-
@BeforeEach
public void setup() {
serviceImportManager = new ServiceImportManager();
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java
index d16dc23905..0306ce082e 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java
@@ -126,7 +126,9 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet
private ServiceImportParseLogic testSubject;
private ServiceImportParseLogic createTestSubject() {
- return new ServiceImportParseLogic();
+ return new ServiceImportParseLogic(serviceBusinessLogic, componentsUtils, toscaOperationFacade, lifecycleBusinessLogic, inputsBusinessLogic,
+ null, null, interfaceTypeOperation, capabilityTypeOperation, componentNodeFilterBusinessLogic,
+ groupBusinessLogic);
}
@BeforeEach
@@ -145,15 +147,7 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet
responseManager = ResponseFormatManager.getInstance();
testSubject = createTestSubject();
- testSubject.setComponentsUtils(componentsUtils);
- testSubject.setToscaOperationFacade(toscaOperationFacade);
serviceBusinessLogic.setElementDao(elementDao);
- testSubject.setServiceBusinessLogic(serviceBusinessLogic);
- testSubject.setCapabilityTypeOperation(capabilityTypeOperation);
- testSubject.setInterfaceTypeOperation(interfaceTypeOperation);
- testSubject.setInputsBusinessLogic(inputsBusinessLogic);
- testSubject.setLifecycleBusinessLogic(lifecycleBusinessLogic);
- testSubject.setComponentNodeFilterBusinessLogic(componentNodeFilterBusinessLogic);
}
@Test
@@ -1865,7 +1859,7 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet
Resource resource = createResourceObject(false);
Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
- UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo nodesInfoValue = getUploadComponentInstanceInfo();
nodesInfoValue.getRequirements().get("requirements").get(0).setName("zxjtestimportserviceab0.mme_ipu_vdu.dependency.test");
uploadResInstancesMap.put("uploadComponentInstanceInfo", nodesInfoValue);
List<ComponentInstance> componentInstancesList = creatComponentInstances();
@@ -1897,7 +1891,7 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet
String yamlName = "group.yml";
Resource resource = createParseResourceObject(true);
Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
- UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo nodesInfoValue = getUploadComponentInstanceInfo();
uploadResInstancesMap.put("uploadComponentInstanceInfo", nodesInfoValue);
List<ComponentInstance> componentInstancesList = new ArrayList<>();
List<RequirementCapabilityRelDef> relations = new ArrayList<>();
@@ -1912,7 +1906,7 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet
String yamlName = "yamlName";
Resource resource = createParseResourceObject(true);
resource.setComponentInstances(creatComponentInstances());
- UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo nodesInfoValue = getUploadComponentInstanceInfo();
List<RequirementCapabilityRelDef> relations = new ArrayList<>();
Assertions.assertNotNull(
@@ -1925,7 +1919,7 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet
Resource resource = createParseResourceObject(false);
List<ComponentInstance> componentInstancesList = new ArrayList<>();
resource.setComponentInstances(componentInstancesList);
- UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo nodesInfoValue = getUploadComponentInstanceInfo();
List<RequirementCapabilityRelDef> relations = new ArrayList<>();
Assertions.assertNotNull(
testSubject.addRelationToRI(yamlName, resource, nodesInfoValue, relations));
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/BaseForwardingPathTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/BaseForwardingPathTest.java
index e9c1d40121..ab4e638e6a 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/BaseForwardingPathTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/BaseForwardingPathTest.java
@@ -33,7 +33,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.openecomp.sdc.be.components.BeConfDependentTest;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
@@ -41,7 +40,6 @@ import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
import org.openecomp.sdc.be.components.path.beans.JanusGraphTestSetup;
import org.openecomp.sdc.be.components.path.utils.GraphTestUtils;
import org.openecomp.sdc.be.components.validation.service.ServiceValidator;
-import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphClient;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
@@ -65,8 +63,6 @@ import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.be.tosca.CapabilityRequirementConverter;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.common.datastructure.UserContext;
-import org.openecomp.sdc.common.impl.ExternalConfiguration;
-import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.openecomp.sdc.common.util.ThreadLocalsHolder;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
@@ -123,7 +119,6 @@ public abstract class BaseForwardingPathTest extends BeConfDependentTest impleme
userRole.add(user.getRole());
UserContext userContext = new UserContext(user.getUserId(), userRole, user.getFirstName(), user.getLastName());
ThreadLocalsHolder.setUserContext(userContext);
- bl.setServiceValidator(serviceValidator);
}
private void initGraph() {
@@ -144,7 +139,6 @@ public abstract class BaseForwardingPathTest extends BeConfDependentTest impleme
private Service createTestService() {
when(catalogOperation.updateCatalog(any(), any())).thenReturn(ActionStatus.OK);
bl.setCatalogOperations(catalogOperation);
- bl.setServiceValidator(serviceValidator);
createCategory();
createServiceCategory(CATEGORY_NAME);
initGraph();
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PolicyExportParserImplTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PolicyExportParserImplTest.java
index d7f70ae8a7..25c1f76e78 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PolicyExportParserImplTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PolicyExportParserImplTest.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.
@@ -22,6 +22,7 @@ package org.openecomp.sdc.be.tosca;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.when;
import fj.data.Either;
@@ -30,10 +31,10 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.be.components.impl.exceptions.SdcResourceNotFoundException;
import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
import org.openecomp.sdc.be.model.Component;
@@ -44,140 +45,139 @@ import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.tosca.model.ToscaMetadata;
import org.openecomp.sdc.be.tosca.model.ToscaPolicyTemplate;
-@RunWith(MockitoJUnitRunner.class)
-public class PolicyExportParserImplTest {
-
- private static final String[] POLICY_KEYS = {"policy_key_1","policy_key_2"};
- private static final String[] VERSIONS = {"version_1","version_1"};
- private static final String[] POLICY_NAMES = {"name_1","name_2"};
- private static final String[] POLICY_UUIDS = {"policyUUID_1","policyUUID_2"};
- private static final String[] INVARIANT_UUIDS = {"invariantUUID_1","invariantUUID_2"};
- private static final String[] POLICY_TYPE_NAMES = {"policyTypeName_1","policyTypeName_2"};
- private static final String[] POLICY_COMPONENT_INSTANCES = {"policyComponentInstanceId"};
- private static final String POLICY_COMPONENT_INSTANCES_NAME = "policyComponentInstanceName";
- private static final String[] POLICY_GROUPS = {"policyGroupId"};
- private static final String POLICY_GROUP_NAME = "PolicyGroupName";
-
- private PolicyExportParser policiyExportParser;
-
- @Mock
- private ApplicationDataTypeCache applicationDataTypeCache;
- @Mock
- private PropertyConvertor propertyConvertor;
-
- @Mock
- private Component component;
-
- @Test
- public void failToGetAllDataTypes() {
-
- when(applicationDataTypeCache.getAll(null)).thenReturn(Either.right(null));
- assertThatExceptionOfType(SdcResourceNotFoundException.class).isThrownBy(() -> policiyExportParser = new PolicyExportParserImpl(
- applicationDataTypeCache,
- propertyConvertor));
- }
-
- @Test
- public void noPoliciesInComponent() {
-
- when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(null));
- when(component.getPolicies()).thenReturn(null);
- policiyExportParser = new PolicyExportParserImpl(applicationDataTypeCache, propertyConvertor);
- Map<String, ToscaPolicyTemplate> policies = policiyExportParser.getPolicies(component);
- assertThat(policies).isEqualTo(null);
- }
-
- @Test
- public void onePoliciesInComponent() {
-
- List<Integer> constIndexes = Arrays.asList(new Integer[] {0});
- testPoliciesInComponent(constIndexes);
- }
-
- @Test
- public void twoPoliciesInComponent() {
-
- List<Integer> constIndexes = Arrays.asList(new Integer[] {0,1});
- testPoliciesInComponent(constIndexes);
- }
-
- private void testPoliciesInComponent(List<Integer> constIndexes) {
- when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(null));
- Map<String, PolicyDefinition> policiesToAdd = getPolicies(constIndexes);
-
- when(component.getPolicies()).thenReturn(policiesToAdd);
- when(component.getComponentInstances()).thenReturn(getComponentInstances());
- when(component.getGroups()).thenReturn(getGroups());
- policiyExportParser = new PolicyExportParserImpl(applicationDataTypeCache, propertyConvertor);
-
- Map<String, ToscaPolicyTemplate> policies = policiyExportParser.getPolicies(component);
-
- for(Integer i : constIndexes) {
-
-
- ToscaPolicyTemplate toscaPolicyTemplate = policies.get(POLICY_NAMES[i]);
- ToscaMetadata metadata = (ToscaMetadata) toscaPolicyTemplate.getMetadata();
-
- assertThat(metadata.getInvariantUUID()).isEqualTo(INVARIANT_UUIDS[i]);
- assertThat(metadata.getUUID()).isEqualTo(POLICY_UUIDS[i]);
- assertThat(metadata.getName()).isEqualTo(POLICY_NAMES[i]);
- assertThat(metadata.getVersion()).isEqualTo(VERSIONS[i]);
-
- String type = toscaPolicyTemplate.getType();
- assertThat(type).isEqualTo(POLICY_TYPE_NAMES[i]);
-
- List<String> targets = toscaPolicyTemplate.getTargets();
- assertThat(targets.get(0)).isEqualTo(POLICY_COMPONENT_INSTANCES_NAME);
- assertThat(targets.get(1)).isEqualTo(POLICY_GROUP_NAME);
- }
- }
-
- private List<GroupDefinition> getGroups() {
- List<GroupDefinition> groups = new ArrayList<>();
- GroupDefinition groupDefinition = new GroupDefinition();
- groupDefinition.setUniqueId(POLICY_GROUPS[0]);
- groupDefinition.setName(POLICY_GROUP_NAME);
- groups.add(groupDefinition);
- return groups;
- }
-
- private List<ComponentInstance> getComponentInstances() {
- List<ComponentInstance> componentInstances = new ArrayList<>();
- ComponentInstance componentInstance = new ComponentInstance();
- componentInstance.setUniqueId(POLICY_COMPONENT_INSTANCES[0]);
- componentInstance.setName(POLICY_COMPONENT_INSTANCES_NAME);
- componentInstances.add(componentInstance);
- return componentInstances;
- }
-
- private Map<String, PolicyDefinition> getPolicies(List<Integer> indexes) {
- Map<String, PolicyDefinition> policies = new HashMap<>();
-
- for (int index : indexes) {
-
- PolicyDefinition policyDefinition = new PolicyDefinition();
-
- // Set type
- policyDefinition.setPolicyTypeName(POLICY_TYPE_NAMES[index]);
-
- // Set Metadata
- policyDefinition.setInvariantUUID(INVARIANT_UUIDS[index]);
- policyDefinition.setPolicyUUID(POLICY_UUIDS[index]);
- policyDefinition.setName(POLICY_NAMES[index]);
- policyDefinition.setVersion(VERSIONS[index]);
-
- // Set targets
- policyDefinition.setTargets(getTargers());
-
- policies.put(POLICY_KEYS[index],policyDefinition);
- }
- return policies;
- }
-
- private Map<PolicyTargetType, List<String>> getTargers() {
- Map<PolicyTargetType, List<String>> targets = new HashMap<>();
- targets.put(PolicyTargetType.COMPONENT_INSTANCES, Arrays.asList(POLICY_COMPONENT_INSTANCES));
- targets.put(PolicyTargetType.GROUPS, Arrays.asList(POLICY_GROUPS));
- return targets;
- }
+@ExtendWith(MockitoExtension.class)
+class PolicyExportParserImplTest {
+
+ private static final String[] POLICY_KEYS = {"policy_key_1", "policy_key_2"};
+ private static final String[] VERSIONS = {"version_1", "version_1"};
+ private static final String[] POLICY_NAMES = {"name_1", "name_2"};
+ private static final String[] POLICY_UUIDS = {"policyUUID_1", "policyUUID_2"};
+ private static final String[] INVARIANT_UUIDS = {"invariantUUID_1", "invariantUUID_2"};
+ private static final String[] POLICY_TYPE_NAMES = {"policyTypeName_1", "policyTypeName_2"};
+ private static final String[] POLICY_COMPONENT_INSTANCES = {"policyComponentInstanceId"};
+ private static final String POLICY_COMPONENT_INSTANCES_NAME = "policyComponentInstanceName";
+ private static final String[] POLICY_GROUPS = {"policyGroupId"};
+ private static final String POLICY_GROUP_NAME = "PolicyGroupName";
+
+ private PolicyExportParser policiyExportParser;
+
+ @Mock
+ private ApplicationDataTypeCache applicationDataTypeCache;
+ @Mock
+ private PropertyConvertor propertyConvertor;
+
+ @Mock
+ private Component component;
+
+ @Test
+ void failToGetAllDataTypes() {
+
+ when(applicationDataTypeCache.getAll(null)).thenReturn(Either.right(null));
+ assertThatExceptionOfType(SdcResourceNotFoundException.class).isThrownBy(() -> policiyExportParser = new PolicyExportParserImpl(
+ applicationDataTypeCache,
+ propertyConvertor));
+ }
+
+ @Test
+ void noPoliciesInComponent() {
+
+ when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(null));
+ when(component.getPolicies()).thenReturn(null);
+ policiyExportParser = new PolicyExportParserImpl(applicationDataTypeCache, propertyConvertor);
+ Map<String, ToscaPolicyTemplate> policies = policiyExportParser.getPolicies(component);
+ assertNull(policies);
+ }
+
+ @Test
+ void onePoliciesInComponent() {
+
+ List<Integer> constIndexes = Arrays.asList(new Integer[]{0});
+ testPoliciesInComponent(constIndexes);
+ }
+
+ @Test
+ void twoPoliciesInComponent() {
+
+ List<Integer> constIndexes = Arrays.asList(new Integer[]{0, 1});
+ testPoliciesInComponent(constIndexes);
+ }
+
+ private void testPoliciesInComponent(List<Integer> constIndexes) {
+ when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(null));
+ Map<String, PolicyDefinition> policiesToAdd = getPolicies(constIndexes);
+
+ when(component.getPolicies()).thenReturn(policiesToAdd);
+ when(component.getComponentInstances()).thenReturn(getComponentInstances());
+ when(component.getGroups()).thenReturn(getGroups());
+ policiyExportParser = new PolicyExportParserImpl(applicationDataTypeCache, propertyConvertor);
+
+ Map<String, ToscaPolicyTemplate> policies = policiyExportParser.getPolicies(component);
+
+ for (Integer i : constIndexes) {
+
+ ToscaPolicyTemplate toscaPolicyTemplate = policies.get(POLICY_NAMES[i]);
+ ToscaMetadata metadata = (ToscaMetadata) toscaPolicyTemplate.getMetadata();
+
+ assertThat(metadata.getInvariantUUID()).isEqualTo(INVARIANT_UUIDS[i]);
+ assertThat(metadata.getUUID()).isEqualTo(POLICY_UUIDS[i]);
+ assertThat(metadata.getName()).isEqualTo(POLICY_NAMES[i]);
+ assertThat(metadata.getVersion()).isEqualTo(VERSIONS[i]);
+
+ String type = toscaPolicyTemplate.getType();
+ assertThat(type).isEqualTo(POLICY_TYPE_NAMES[i]);
+
+ List<String> targets = toscaPolicyTemplate.getTargets();
+ assertThat(targets.get(0)).isEqualTo(POLICY_COMPONENT_INSTANCES_NAME);
+ assertThat(targets.get(1)).isEqualTo(POLICY_GROUP_NAME);
+ }
+ }
+
+ private List<GroupDefinition> getGroups() {
+ List<GroupDefinition> groups = new ArrayList<>();
+ GroupDefinition groupDefinition = new GroupDefinition();
+ groupDefinition.setUniqueId(POLICY_GROUPS[0]);
+ groupDefinition.setName(POLICY_GROUP_NAME);
+ groups.add(groupDefinition);
+ return groups;
+ }
+
+ private List<ComponentInstance> getComponentInstances() {
+ List<ComponentInstance> componentInstances = new ArrayList<>();
+ ComponentInstance componentInstance = new ComponentInstance();
+ componentInstance.setUniqueId(POLICY_COMPONENT_INSTANCES[0]);
+ componentInstance.setName(POLICY_COMPONENT_INSTANCES_NAME);
+ componentInstances.add(componentInstance);
+ return componentInstances;
+ }
+
+ private Map<String, PolicyDefinition> getPolicies(List<Integer> indexes) {
+ Map<String, PolicyDefinition> policies = new HashMap<>();
+
+ for (int index : indexes) {
+
+ PolicyDefinition policyDefinition = new PolicyDefinition();
+
+ // Set type
+ policyDefinition.setPolicyTypeName(POLICY_TYPE_NAMES[index]);
+
+ // Set Metadata
+ policyDefinition.setInvariantUUID(INVARIANT_UUIDS[index]);
+ policyDefinition.setPolicyUUID(POLICY_UUIDS[index]);
+ policyDefinition.setName(POLICY_NAMES[index]);
+ policyDefinition.setVersion(VERSIONS[index]);
+
+ // Set targets
+ policyDefinition.setTargets(getTargets());
+
+ policies.put(POLICY_KEYS[index], policyDefinition);
+ }
+ return policies;
+ }
+
+ private Map<PolicyTargetType, List<String>> getTargets() {
+ Map<PolicyTargetType, List<String>> targets = new HashMap<>();
+ targets.put(PolicyTargetType.COMPONENT_INSTANCES, Arrays.asList(POLICY_COMPONENT_INSTANCES));
+ targets.put(PolicyTargetType.GROUPS, Arrays.asList(POLICY_GROUPS));
+ return targets;
+ }
}