Search in sources :

Example 16 with ServiceInstance

use of org.onap.aai.domain.yang.ServiceInstance in project so by onap.

the class WorkflowActionBBTasksTest method postProcessingExecuteBBActivateVfModuleReplaceInstanceHasConfigurationTest.

@Test
public void postProcessingExecuteBBActivateVfModuleReplaceInstanceHasConfigurationTest() throws CloneNotSupportedException {
    RequestDetails reqDetails = new RequestDetails();
    RelatedInstanceList[] list = new RelatedInstanceList[2];
    RelatedInstanceList vnfList = new RelatedInstanceList();
    RelatedInstanceList serviceList = new RelatedInstanceList();
    list[0] = vnfList;
    list[1] = serviceList;
    RelatedInstance vnfInstance = new RelatedInstance();
    RelatedInstance serviceInstance = new RelatedInstance();
    ModelInfo vnfModelInfo = new ModelInfo();
    vnfModelInfo.setModelType(ModelType.vnf);
    vnfModelInfo.setModelCustomizationId("1");
    ModelInfo serviceModelInfo = new ModelInfo();
    serviceModelInfo.setModelType(ModelType.service);
    serviceModelInfo.setModelVersionId("1");
    vnfInstance.setModelInfo(vnfModelInfo);
    serviceInstance.setModelInfo(serviceModelInfo);
    reqDetails.setRelatedInstanceList(list);
    vnfList.setRelatedInstance(vnfInstance);
    serviceList.setRelatedInstance(serviceInstance);
    ModelInfo vfModuleInfo = new ModelInfo();
    vfModuleInfo.setModelCustomizationId("1");
    reqDetails.setModelInfo(vfModuleInfo);
    BuildingBlock bbAddFabric = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
    ExecuteBuildingBlock ebbAddFabric = new ExecuteBuildingBlock().setBuildingBlock(bbAddFabric);
    WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
    workflowResourceIds.setServiceInstanceId("1");
    workflowResourceIds.setVnfId("1");
    ebbAddFabric.setWorkflowResourceIds(workflowResourceIds);
    ebbAddFabric.setResourceId("1");
    BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
    ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
    ebbActivateVfModule.setWorkflowResourceIds(workflowResourceIds);
    ebbActivateVfModule.setResourceId("1");
    ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
    ebbAddFabric.setConfigurationResourceKeys(configurationResourceKeys);
    ebbActivateVfModule.setRequestDetails(reqDetails);
    ServiceInstance service = new ServiceInstance();
    service.setServiceInstanceName("name");
    service.setModelVersionId("1");
    doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById("1");
    GenericVnf vnf = new GenericVnf();
    vnf.setVnfName("name");
    vnf.setModelCustomizationId("1");
    doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf("1");
    VfModule vfModule = new VfModule();
    vfModule.setVfModuleName("name");
    vfModule.setModelCustomizationId("1");
    doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("1", "1");
    List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>();
    org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
    vnfc.setModelInvariantId("1");
    vnfc.setVnfcName("name");
    vnfc.setModelCustomizationId("2");
    vnfcs.add(vnfc);
    doReturn(vnfcs).when(workflowAction).getRelatedResourcesInVfModule(any(), any(), any(), any());
    CvnfcConfigurationCustomization vfModuleCustomization = new CvnfcConfigurationCustomization();
    ConfigurationResource configuration = new ConfigurationResource();
    configuration.setToscaNodeType("FabricConfiguration");
    configuration.setModelUUID("1");
    vfModuleCustomization.setConfigurationResource(configuration);
    doReturn(vfModuleCustomization).when(catalogDbClient).getCvnfcCustomization("1", "1", "1", "2");
    prepareDelegateExecution();
    List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
    flowsToExecute.add(ebbActivateVfModule);
    ArgumentCaptor<DelegateExecution> executionCaptor = ArgumentCaptor.forClass(DelegateExecution.class);
    ArgumentCaptor<ExecuteBuildingBlock> bbCaptor = ArgumentCaptor.forClass(ExecuteBuildingBlock.class);
    ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
    execution.setVariable("requestAction", "replaceInstance");
    execution.setVariable("completed", true);
    workflowActionBBTasks.postProcessingExecuteBBActivateVfModule(execution, ebbActivateVfModule, flowsToExecute);
    verify(workflowActionBBTasks, times(1)).postProcessingExecuteBBActivateVfModule(executionCaptor.capture(), bbCaptor.capture(), listCaptor.capture());
    assertEquals(false, executionCaptor.getAllValues().get(0).getVariable("completed"));
    assertEquals(2, ((ArrayList) executionCaptor.getAllValues().get(0).getVariable("flowsToExecute")).size());
    assertEquals("2", ((ExecuteBuildingBlock) ((ArrayList) executionCaptor.getAllValues().get(0).getVariable("flowsToExecute")).get(1)).getConfigurationResourceKeys().getCvnfcCustomizationUUID());
}
Also used : ModelInfo(org.onap.so.serviceinstancebeans.ModelInfo) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) BuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock) GenericVnf(org.onap.aai.domain.yang.GenericVnf) RelatedInstanceList(org.onap.so.serviceinstancebeans.RelatedInstanceList) ArrayList(java.util.ArrayList) ServiceInstance(org.onap.aai.domain.yang.ServiceInstance) VfModule(org.onap.aai.domain.yang.VfModule) WorkflowResourceIds(org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) List(java.util.List) RelatedInstanceList(org.onap.so.serviceinstancebeans.RelatedInstanceList) ArrayList(java.util.ArrayList) RelatedInstance(org.onap.so.serviceinstancebeans.RelatedInstance) ConfigurationResource(org.onap.so.db.catalog.beans.ConfigurationResource) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails) ConfigurationResourceKeys(org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) CvnfcConfigurationCustomization(org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization) BaseTaskTest(org.onap.so.bpmn.BaseTaskTest) Test(org.junit.Test)

Example 17 with ServiceInstance

use of org.onap.aai.domain.yang.ServiceInstance in project so by onap.

the class AaiResourceIdValidatorTest method validateResourceIdInAAISIExistsTest.

@Test
public void validateResourceIdInAAISIExistsTest() throws Exception {
    RequestDetails reqDetails = setupRequestDetails();
    reqDetails.getModelInfo().setModelVersionId("1234567");
    ServiceInstance si = new ServiceInstance();
    si.setServiceInstanceId("siId123");
    si.setModelVersionId("1234567");
    ServiceInstances serviceInstances = new ServiceInstances();
    serviceInstances.getServiceInstance().add(si);
    Map<String, String> uriKeys = new HashMap<>();
    uriKeys.put(AAIFluentTypeBuilder.Types.CUSTOMER.getUriParams().globalCustomerId, "globalCustomerId");
    uriKeys.put(AAIFluentTypeBuilder.Types.SERVICE_SUBSCRIPTION.getUriParams().serviceType, "serviceType");
    when(bbInputSetupUtilsMock.getAAIServiceInstancesGloballyByName("siName123")).thenReturn(serviceInstances);
    when(bbInputSetupUtilsMock.getURIKeysFromServiceInstance("siId123")).thenReturn(uriKeys);
    this.expectedException.expect(DuplicateNameException.class);
    this.expectedException.expectMessage(containsString("serviceInstance with name (siName123) and global-customer-id (globalCustomerId), service-type (serviceType), model-version-id (1234567) already exists. The name must be unique."));
    testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "siName123", reqDetails, new WorkflowResourceIds());
}
Also used : ServiceInstances(org.onap.aai.domain.yang.ServiceInstances) HashMap(java.util.HashMap) ServiceInstance(org.onap.aai.domain.yang.ServiceInstance) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails) WorkflowResourceIds(org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds) Test(org.junit.Test)

Example 18 with ServiceInstance

use of org.onap.aai.domain.yang.ServiceInstance in project so by onap.

the class BBInputSetupUtilsTest method getRelatedServiceInstanceFromInstanceGroupMultipleExceptionTest.

@Test
public void getRelatedServiceInstanceFromInstanceGroupMultipleExceptionTest() throws Exception {
    final String instanceGroupId = "ig-001";
    expectedException.expect(MultipleObjectsFoundException.class);
    Optional<ServiceInstances> serviceInstances = Optional.of(new ServiceInstances());
    ServiceInstance si1 = Mockito.mock(ServiceInstance.class);
    ServiceInstance si2 = Mockito.mock(ServiceInstance.class);
    serviceInstances.get().getServiceInstance().add(si1);
    serviceInstances.get().getServiceInstance().add(si2);
    doReturn(serviceInstances).when(MOCK_aaiResourcesClient).get(eq(ServiceInstances.class), any(AAIPluralResourceUri.class));
    this.bbInputSetupUtils.getRelatedServiceInstanceFromInstanceGroup(instanceGroupId);
}
Also used : ServiceInstances(org.onap.aai.domain.yang.ServiceInstances) AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) ServiceInstance(org.onap.aai.domain.yang.ServiceInstance) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 19 with ServiceInstance

use of org.onap.aai.domain.yang.ServiceInstance in project so by onap.

the class BBInputSetupUtilsTest method getAAIServiceInstanceByIdAndCustomerTest.

@Test
public void getAAIServiceInstanceByIdAndCustomerTest() {
    final String globalCustomerId = "globalCustomerId";
    final String serviceType = "serviceType";
    final String serviceInstanceId = "serviceInstanceId";
    ServiceInstance expected = new ServiceInstance();
    expected.setServiceInstanceId(serviceInstanceId);
    doReturn(Optional.of(expected)).when(MOCK_aaiResourcesClient).get(ServiceInstance.class, AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalCustomerId).serviceSubscription(serviceType).serviceInstance(serviceInstanceId)).depth(Depth.TWO));
    assertThat(bbInputSetupUtils.getAAIServiceInstanceByIdAndCustomer(globalCustomerId, serviceType, serviceInstanceId), sameBeanAs(expected));
}
Also used : ServiceInstance(org.onap.aai.domain.yang.ServiceInstance) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 20 with ServiceInstance

use of org.onap.aai.domain.yang.ServiceInstance in project so by onap.

the class UpdateServiceInstanceInAai method getAndSetServiceInstance.

private void getAndSetServiceInstance(final String serviceInstanceId, final String serviceType, final String globalSubscriberId, String modelVersionId) {
    AAIRestClientI restClient = new AAIRestClientImpl();
    Optional<ServiceInstance> optionalSi = restClient.getServiceInstanceById(serviceInstanceId, serviceType, globalSubscriberId);
    if (!optionalSi.isPresent()) {
    // throwExceptionWithWarn(delegateExecution, "Unable to find the service instance: " + serviceInstanceId);
    }
    ServiceInstance serviceInstance = optionalSi.get();
    serviceInstance.setModelVersionId(modelVersionId);
    restClient.updateServiceInstance(serviceInstanceId, serviceType, globalSubscriberId, serviceInstance);
}
Also used : AAIRestClientImpl(org.onap.aaiclient.client.aai.AAIRestClientImpl) AAIRestClientI(org.onap.aaiclient.client.aai.AAIRestClientI) ServiceInstance(org.onap.aai.domain.yang.ServiceInstance)

Aggregations

ServiceInstance (org.onap.aai.domain.yang.ServiceInstance)33 Test (org.junit.Test)27 BaseTaskTest (org.onap.so.bpmn.BaseTaskTest)14 ArrayList (java.util.ArrayList)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 List (java.util.List)12 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)12 ServiceInstances (org.onap.aai.domain.yang.ServiceInstances)11 ExecuteBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock)11 RelationshipList (org.onap.aai.domain.yang.RelationshipList)9 RequestDetails (org.onap.so.serviceinstancebeans.RequestDetails)9 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)8 GenericVnf (org.onap.aai.domain.yang.GenericVnf)8 VfModule (org.onap.aai.domain.yang.VfModule)8 NorthBoundRequest (org.onap.so.db.catalog.beans.macro.NorthBoundRequest)8 OrchestrationFlow (org.onap.so.db.catalog.beans.macro.OrchestrationFlow)8 WorkflowResourceIds (org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds)6 IOException (java.io.IOException)4 DelegateExecution (org.camunda.bpm.engine.delegate.DelegateExecution)4 Relationship (org.onap.aai.domain.yang.Relationship)4