+ ImmutablePair<String, byte[]> resourceTemplate = getNodeType();
+ String updatedNodeType = "org.openecomp.resource.cp.extCP";
+ resource.setToscaResourceName(updatedNodeType);
+
+ 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));
+ when(toscaOperationFacade.validateCsarUuidUniqueness(anyString())).thenReturn(StorageOperationStatus.OK);
+ ServiceCsarInfo csarInfo = getCsarInfo();
+ when(csarBusinessLogic.getCsarInfo(any(Service.class), any(), any(User.class), any(Map.class), anyString(), any())).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>>>()));
+ doReturn(getParsedToscaYamlInfo()).when(csarBusinessLogic)
+ .getParsedToscaYamlInfo(anyString(), anyString(), any(), any(CsarInfo.class), any(), any(Service.class));
+ doReturn(getParsedToscaYamlInfo()).when(csarBusinessLogic).getParsedToscaYamlInfo(any(ServiceCsarInfo.class), any(Service.class));
+ 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,
+ AuditingActionEnum.CREATE_RESOURCE)).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<>(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);
+ 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));
+ DataTypeDefinition typeToBeUpdated = new DataTypeDefinition();
+ List<PropertyDefinition> properties = new ArrayList<>();
+ PropertyDefinition nameProperty = new PropertyDefinition();
+ nameProperty.setName("name");
+ nameProperty.setType("string");
+ properties.add(nameProperty);
+ PropertyDefinition versionProperty = new PropertyDefinition();
+ versionProperty.setName("version");
+ versionProperty.setType("string");
+ properties.add(versionProperty);
+ typeToBeUpdated.setProperties(properties);
+ when(applicationDataTypeCache.get(any(), eq("onap.datatypes.ToscaConceptIdentifier.datatype"))).thenReturn(Either.left(typeToBeUpdated));
+ when(applicationDataTypeCache.get(any(), matches("^((?!(tosca.datatypes.test_|onap.datatypes.ToscaConceptIdentifier)).)*$"))).thenReturn(
+ Either.left(new DataTypeDefinition()));
+
+ when(artifactTypeOperation.getArtifactTypeByUid(contains("tosca.testartifacts.Name"))).thenReturn(
+ Either.right(StorageOperationStatus.NOT_FOUND));
+ when(artifactTypeOperation.getArtifactTypeByUid(contains("tosca.artifacts"))).thenReturn(Either.left(null));
+
+ when(interfaceLifecycleTypeOperation.getInterface(contains("tosca.interfaces"))).thenReturn(Either.left(new InterfaceDefinition()));
+ when(interfaceLifecycleTypeOperation.getInterface(contains("tosca.interfaces.test"))).thenReturn(
+ Either.right(StorageOperationStatus.NOT_FOUND));
+
+ when(capabilityTypeOperation.getCapabilityType(anyString()))
+ .thenReturn(Either.left(new CapabilityTypeDefinition()));
+ when(capabilityTypeOperation.getCapabilityType(contains("tosca.testcapabilitytypes.Name")))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+
+ when(toscaOperationFacade.getLatestByToscaResourceName(contains("org.openecomp.resource"), isNull()))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ when(toscaOperationFacade.getLatestByToscaResourceName(contains("tosca.nodes."), isNull()))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ when(toscaOperationFacade.getLatestByToscaResourceName(updatedNodeType, null)).thenReturn(Either.left(resource));
+ when(toscaOperationFacade.getLatestByToscaResourceName(contains("org.openecomp.service."), isNull()))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ when(artifactsBusinessLogic.handleDownloadRequestById(resourceUniqueId, artifactUniqueId, user.getUserId(), ComponentTypeEnum.RESOURCE, null,
+ null))
+ .thenReturn(resourceTemplate);
+ when(toscaOperationFacade.updatePropertyOfComponent(eq(oldService), any(PropertyDefinition.class))).thenReturn(Either.left(null));
+ when(toscaOperationFacade.updateComponentInstancePropsToComponent(anyMap(), anyString())).thenReturn(Either.left(null));
+ when(groupTypeOperation.getGroupTypeByUid(anyString())).thenReturn(Either.left(new GroupTypeDefinition()));
+
+ 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());
+
+ ArgumentCaptor<String> yaml = ArgumentCaptor.forClass(String.class);
+ verify(dataTypeBusinessLogic).createDataTypeFromYaml(yaml.capture(), isNull(), anyBoolean());
+ Map<String, Object> yamlMap = new Yaml().load(yaml.getValue());
+ assertEquals(3, yamlMap.size());
+ assertNotNull(yamlMap.get("tosca.datatypes.test_a"));
+ assertNotNull(yamlMap.get("tosca.datatypes.test_b"));
+ assertNotNull(yamlMap.get("onap.datatypes.ToscaConceptIdentifier"));
+
+ ArgumentCaptor<String> artifactTypes = ArgumentCaptor.forClass(String.class);
+ verify(artifactTypeImportManager).createArtifactTypes(artifactTypes.capture(), isNull(), anyBoolean());
+ Map<String, Object> artifactTypesMap = new Yaml().load(artifactTypes.getValue());
+ assertEquals(1, artifactTypesMap.size());
+ assertNotNull(artifactTypesMap.get("tosca.testartifacts.Name"));
+
+ ArgumentCaptor<String> capabilityTypes = ArgumentCaptor.forClass(String.class);
+ verify(capabilityTypeImportManager).createCapabilityTypes(
+ capabilityTypes.capture(),
+ isNull(),
+ anyBoolean());
+ Map<String, Object> capabilityTypesMap = new Yaml().load(capabilityTypes.getValue());
+ assertEquals(1, capabilityTypesMap.size());
+ assertNotNull(capabilityTypesMap.get("tosca.testcapabilitytypes.Name"));
+
+ ArgumentCaptor<Map<String, Object>> nodeTypes = ArgumentCaptor.forClass(Map.class);
+ verify(resourceImportManager).importAllNormativeResource(nodeTypes.capture(), any(), any(), any(), any(),
+ anyBoolean(), anyBoolean());
+ Map<String, Object> nodeTypesMap = nodeTypes.getValue();
+ Map<String, Object> newUpdatedNodeType = (Map<String, Object>) nodeTypesMap.get(updatedNodeType);
+ assertEquals(8, ((Map<String, Object>) newUpdatedNodeType.get("properties")).size());
+ Assertions.assertNull(newUpdatedNodeType.get("attributes"));
+ assertEquals(3, ((List<Map<String, Object>>) newUpdatedNodeType.get("requirements")).size());
+ assertEquals(1, ((Map<String, Object>) newUpdatedNodeType.get("capabilities")).size());
+ assertEquals(2, ((Map<String, Object>) newUpdatedNodeType.get("interfaces")).size());
+
+ ArgumentCaptor<String> interfaceTypes = ArgumentCaptor.forClass(String.class);
+ verify(interfaceLifecycleTypeImportManager).createLifecycleTypes(interfaceTypes.capture(), any(), anyBoolean());
+ Map<String, Object> yamlInterfaceMap = new Yaml().load(interfaceTypes.getValue());
+ assertEquals(3, yamlInterfaceMap.size());
+ assertNotNull(yamlInterfaceMap.get("tosca.interfaces.test.node.lifecycle.Attach"));
+ assertNotNull(yamlInterfaceMap.get("tosca.interfaces.test.node.lifecycle.Detach"));
+ assertNotNull(yamlInterfaceMap.get("tosca.interfaces.test.node.lifecycle.Reconfigure"));
+
+ }
+
+ @Test
+ void testCreateService_Fail_NotFoundNodeTypesArtifacts() {
+ Service oldService = createServiceObject(true);