diff options
author | vasraz <vasyl.razinkov@est.tech> | 2022-07-27 11:44:52 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2022-08-19 14:39:23 +0000 |
commit | 1cb3596e003729d9fcbd2c5b3d426db6e575c7ce (patch) | |
tree | 35ac468c54603aebde269bb550cc8dd07157b201 /catalog-be/src/test/java | |
parent | 59d0b40c4106065ac659981f5c7ba460e45b3dec (diff) |
Support Inputs during Import Service
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: Ifc761d607a5d3c11187486fec3133be44c2d38b0
Issue-ID: SDC-4082
Diffstat (limited to 'catalog-be/src/test/java')
2 files changed, 49 insertions, 13 deletions
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 e5a4592b51..07593a0cd7 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 @@ -28,9 +28,9 @@ import static org.mockito.Mockito.anyMap; import static org.mockito.Mockito.contains; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.isNull; import static org.mockito.Mockito.matches; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.isNull; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.openecomp.sdc.be.components.impl.ServiceImportBusinessLogic.CREATE_RESOURCE; @@ -46,6 +46,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Collections; import java.util.EnumMap; import java.util.HashMap; import java.util.List; @@ -55,6 +56,7 @@ import java.util.Set; import org.apache.commons.codec.binary.Base64; import org.apache.commons.collections.map.HashedMap; import org.apache.commons.lang3.tuple.ImmutablePair; +import org.json.simple.JSONObject; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -73,6 +75,7 @@ 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.datatypes.tosca.ToscaGetFunctionType; import org.openecomp.sdc.be.externalapi.servlet.ArtifactExternalServlet; import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.info.NodeTypeInfoToUpdateArtifacts; @@ -157,10 +160,22 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest @Test void testCreateService_OK() { Service oldService = createServiceObject(true); + oldService.setComponentInstances(creatComponentInstances()); + oldService.setComponentInstancesProperties( + Collections.singletonMap(COMPONENT_ID, Collections.singletonList(new ComponentInstanceProperty()))); String payloadName = "valid_vf"; Map<String, byte[]> payload = crateCsarFromPayload(); Service newService = createServiceObject(true); newService.setComponentInstances(creatComponentInstances()); + ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty(); + componentInstanceProperty.setName("propertiesName"); + final JSONObject jsonObject = new JSONObject(); + jsonObject.put(ToscaGetFunctionType.GET_INPUT.getFunctionName(), "zxjTestImportServiceAb_propertiesName"); + componentInstanceProperty.setValue(jsonObject.toJSONString()); + + newService.setComponentInstancesProperties( + Collections.singletonMap(COMPONENT_ID + "." + "zxjTestImportServiceAb", Collections.singletonList(componentInstanceProperty))); + newService.setProperties(getProperties()); when(serviceBusinessLogic.validateServiceBeforeCreate(eq(newService), any(User.class), any(AuditingActionEnum.class))) .thenReturn(Either.left(newService)); @@ -200,12 +215,15 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest when(mockJanusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK); when(graphLockOperation.unlockComponentByName(anyString(), anyString(), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK); when(serviceImportParseLogic.createOutputsOnService(any(Service.class), any(), anyString())).thenReturn(newService); - + when(toscaOperationFacade.updateInputsToComponent(anyList(), eq(newService.getUniqueId()))).thenReturn(Either.left(new ArrayList<>())); + when(applicationDataTypeCache.get(any(), contains("tosca.datatypes.test_"))).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); when(applicationDataTypeCache.get(any(), matches("^((?!tosca.datatypes.test_).)*$"))).thenReturn(Either.left(new DataTypeDefinition())); - + when(toscaOperationFacade.getLatestByToscaResourceName(contains("org.openecomp.resource"), isNull())).thenReturn(Either.left(null)); when(toscaOperationFacade.getLatestByToscaResourceName(contains("tosca.nodes."), isNull())).thenReturn(Either.left(null)); + when(toscaOperationFacade.updatePropertyOfComponent(eq(oldService), any(PropertyDefinition.class))).thenReturn(Either.left(null)); + when(toscaOperationFacade.updateComponentInstancePropsToComponent(anyMap(), anyString())).thenReturn(Either.left(null)); Service result = sIBL.createService(oldService, AuditingActionEnum.CREATE_RESOURCE, user, payload, payloadName); assertNotNull(result); @@ -218,7 +236,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest assertEquals(1, result.getComponentInstances().get(0).getRequirements().size()); assertNotNull(result.getCategories()); assertEquals(1, result.getCategories().size()); - + ArgumentCaptor<String> yaml = ArgumentCaptor.forClass(String.class); verify(dataTypeBusinessLogic).createDataTypeFromYaml(yaml.capture(), isNull(), anyBoolean()); Map<String, Object> yamlMap = new Yaml().load(yaml.getValue()); @@ -953,7 +971,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest List<UploadPropInfo> propertyList = getPropertyList(); Assertions.assertNotNull(resource); Assertions.assertNotNull(currPropertiesMap); - sIBL.processProperty(resource, currentCompInstance, allDataTypes, currPropertiesMap, instPropList, propertyList); + sIBL.processProperty(resource, allDataTypes, currPropertiesMap, instPropList, propertyList); } @Test @@ -1293,7 +1311,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest propertyList.add(propertyInfo); Assertions.assertNotNull(resource); - sIBL.processProperty(resource, currentCompInstance, allDataTypes, currPropertiesMap, instPropList, propertyList); + sIBL.processProperty(resource, allDataTypes, currPropertiesMap, instPropList, propertyList); } @Test @@ -2326,6 +2344,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest componentInstance.setUniqueId("uniqueId"); componentInstance.setComponentUid("componentUid"); componentInstance.setName("zxjTestImportServiceAb"); + componentInstance.setNormalizedName("zxjTestImportServiceAb"); + componentInstance.setProperties(getProperties()); componentInstances.add(componentInstance); return componentInstances; } @@ -2375,20 +2395,20 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest protected ServiceCsarInfo getCsarInfo() { String csarUuid = "0010"; User user = new User("jh0003"); - + try { File csarFile = new File( - ServiceImportBusinessLogicTest.class.getClassLoader().getResource("csars/service-Ser09080002-csar.csar").toURI()); + ServiceImportBusinessLogicTest.class.getClassLoader().getResource("csars/service-Ser09080002-csar.csar").toURI()); Map<String, byte[]> csar = ZipUtils.readZip(csarFile, false); - + String vfReousrceName = "resouceName"; String mainTemplateName = "Definitions/service_import_template.yml"; - + Optional<String> keyOp = csar.keySet().stream().filter(k -> k.endsWith("service-Ser09080002-template.yml")).findAny(); byte[] mainTemplateService = keyOp.map(csar::get).orElse(null); assertNotNull(mainTemplateService); final String mainTemplateContent = new String(mainTemplateService); - + return new ServiceCsarInfo(user, csarUuid, csar, vfReousrceName, mainTemplateName, mainTemplateContent, false); } catch (URISyntaxException | ZipException e) { fail(e); 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 06594dc180..fd39b65db0 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 @@ -85,9 +85,11 @@ import org.openecomp.sdc.be.model.CapabilityDefinition; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.ComponentInstance; import org.openecomp.sdc.be.model.GroupDefinition; +import org.openecomp.sdc.be.model.InputDefinition; import org.openecomp.sdc.be.model.LifecycleStateEnum; import org.openecomp.sdc.be.model.NodeTypeInfo; import org.openecomp.sdc.be.model.ParsedToscaYamlInfo; +import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.RequirementCapabilityRelDef; import org.openecomp.sdc.be.model.RequirementDefinition; import org.openecomp.sdc.be.model.Resource; @@ -118,7 +120,7 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM 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 COMPONENT_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(); @@ -270,6 +272,19 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM service.setProjectCode("12345"); service.setEcompGeneratedNaming(true); + List<InputDefinition> inputs = new ArrayList<>(); + InputDefinition input_1 = new InputDefinition(); + input_1.setName("propertiesName"); + input_1.setUniqueId("uniqueId"); + input_1.setType("inputDefinitionType"); + inputs.add(input_1); + InputDefinition input_2 = new InputDefinition(); + input_2.setName("zxjTestImportServiceAb_propertiesName"); + input_2.setUniqueId("uniqueId"); + input_2.setType("inputDefinitionType"); + inputs.add(input_2); + service.setInputs(inputs); + if (afterCreate) { service.setVersion("0.1"); service.setUniqueId(service.getName() + ":" + service.getVersion()); @@ -309,7 +324,7 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM protected Resource createParseResourceObject(boolean afterCreate) { Resource resource = new Resource(); - resource.setUniqueId(COMPONNET_ID); + resource.setUniqueId(COMPONENT_ID); resource.setName(RESOURCE_NAME); resource.setToscaResourceName(RESOURCE_TOSCA_NAME); resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY); @@ -487,6 +502,7 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM componentInstance.setUniqueId("uniqueId"); componentInstance.setComponentUid("componentUid"); componentInstance.setName("zxjTestImportServiceAb"); + componentInstance.setProperties(Collections.singletonList(new PropertyDefinition())); componentInstances.add(componentInstance); return componentInstances; } |