aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn
diff options
context:
space:
mode:
authorJoanna Jeremicz <joanna.jeremicz@nokia.com>2020-01-21 13:30:45 +0100
committerJoanna Jeremicz <joanna.jeremicz@nokia.com>2020-01-29 07:57:39 +0100
commit76a37d03413fd1798e50274c57566c0ed3d752e4 (patch)
tree73aa936f3c01f9e890d9460749e7c8faa5b85f3b /bpmn
parent48cb43adc20ac10fa6f22c0e03fe2b6775d45b87 (diff)
AssignPnfBB connects PNF and service instance in AAI
Change-Id: I92ab4b45acb120d647ea3de7a455e2e873c12a72 Issue-ID: SO-2605 Signed-off-by: Joanna Jeremicz <joanna.jeremicz@nokia.com>
Diffstat (limited to 'bpmn')
-rw-r--r--bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignPnfBB.bpmn102
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationId.java45
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAai.java34
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfBaseTasks.java29
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationIdTest.java129
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAaiTest.java50
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfTasksUtils.java17
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java18
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/aai/mapper/AAIObjectMapper.java6
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java52
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java6
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java18
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java86
13 files changed, 208 insertions, 384 deletions
diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignPnfBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignPnfBB.bpmn
index 930f666bf0..c8600586ce 100644
--- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignPnfBB.bpmn
+++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignPnfBB.bpmn
@@ -1,68 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
-<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_1a52v2f" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.5.0">
+<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_1a52v2f" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="2.0.3">
<bpmn:collaboration id="Collaboration_0go8wi3">
<bpmn:participant id="Participant_1dwc5st" name="SO&#10;Assign PNF" processRef="AssignPnfBB" />
<bpmn:participant id="Participant_0gycee4" name="AAI" />
<bpmn:messageFlow id="MessageFlow_0xh6bkn" sourceRef="CreatePnfEntryInAai" targetRef="Participant_0gycee4" />
- <bpmn:messageFlow id="MessageFlow_0cnehf5" sourceRef="Participant_0gycee4" targetRef="CheckAaiForPnfCorrelationId" />
- <bpmn:messageFlow id="MessageFlow_1e1pjve" sourceRef="CheckAaiForPnfCorrelationId" targetRef="Participant_0gycee4" />
</bpmn:collaboration>
<bpmn:process id="AssignPnfBB" name="AssignPnfBB" isExecutable="true">
- <bpmn:startEvent id="AssignPnf_StartEvent">
- <bpmn:outgoing>SequenceFlow_1fu9o4x</bpmn:outgoing>
- </bpmn:startEvent>
- <bpmn:serviceTask id="CheckAaiForPnfCorrelationId" name="Check AAI for pnf_correlation_id" camunda:expression="${CheckAaiForPnfCorrelationId.execute(InjectExecution.execute(execution, execution.getVariable(&#34;gBuildingBlockExecution&#34;)))}">
- <bpmn:incoming>SequenceFlow_1fu9o4x</bpmn:incoming>
- <bpmn:outgoing>SequenceFlow_081rs5d</bpmn:outgoing>
- </bpmn:serviceTask>
- <bpmn:exclusiveGateway id="DoesAaiContainInfoAboutPnf" name="Does AAI contain info about pnf?">
- <bpmn:incoming>SequenceFlow_081rs5d</bpmn:incoming>
- <bpmn:outgoing>SequenceFlow_0fn5kgz</bpmn:outgoing>
- <bpmn:outgoing>SequenceFlow_1ewfz8r</bpmn:outgoing>
- </bpmn:exclusiveGateway>
- <bpmn:serviceTask id="CreatePnfEntryInAai" name="Create Pnf entry in AAI" camunda:expression="${CreatePnfEntryInAai.execute(InjectExecution.execute(execution, execution.getVariable(&#34;gBuildingBlockExecution&#34;)))}">
- <bpmn:incoming>SequenceFlow_0fn5kgz</bpmn:incoming>
- <bpmn:outgoing>SequenceFlow_0l6rtzy</bpmn:outgoing>
- </bpmn:serviceTask>
+ <bpmn:sequenceFlow id="SequenceFlow_0l6rtzy" sourceRef="CreatePnfEntryInAai" targetRef="AaiEntryExists" />
+ <bpmn:sequenceFlow id="SequenceFlow_1fu9o4x" sourceRef="AssignPnf_StartEvent" targetRef="CreatePnfEntryInAai" />
<bpmn:endEvent id="AaiEntryExists" name="AAI entry exists">
- <bpmn:incoming>SequenceFlow_1ewfz8r</bpmn:incoming>
<bpmn:incoming>SequenceFlow_0l6rtzy</bpmn:incoming>
</bpmn:endEvent>
- <bpmn:sequenceFlow id="SequenceFlow_081rs5d" sourceRef="CheckAaiForPnfCorrelationId" targetRef="DoesAaiContainInfoAboutPnf" />
- <bpmn:sequenceFlow id="SequenceFlow_0fn5kgz" name="No" sourceRef="DoesAaiContainInfoAboutPnf" targetRef="CreatePnfEntryInAai">
- <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{!aaiContainsInfoAboutPnf}</bpmn:conditionExpression>
- </bpmn:sequenceFlow>
- <bpmn:sequenceFlow id="SequenceFlow_1ewfz8r" name="Yes&#10;&#10;" sourceRef="DoesAaiContainInfoAboutPnf" targetRef="AaiEntryExists">
- <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{aaiContainsInfoAboutPnf}</bpmn:conditionExpression>
- </bpmn:sequenceFlow>
- <bpmn:sequenceFlow id="SequenceFlow_0l6rtzy" sourceRef="CreatePnfEntryInAai" targetRef="AaiEntryExists" />
- <bpmn:sequenceFlow id="SequenceFlow_1fu9o4x" sourceRef="AssignPnf_StartEvent" targetRef="CheckAaiForPnfCorrelationId" />
+ <bpmn:serviceTask id="CreatePnfEntryInAai" name="Create Pnf entry in AAI" camunda:expression="${AAICreateTasks.createPnf(InjectExecution.execute(execution, execution.getVariable(&#34;gBuildingBlockExecution&#34;)))}">
+ <bpmn:incoming>SequenceFlow_1fu9o4x</bpmn:incoming>
+ <bpmn:outgoing>SequenceFlow_0l6rtzy</bpmn:outgoing>
+ </bpmn:serviceTask>
+ <bpmn:startEvent id="AssignPnf_StartEvent">
+ <bpmn:outgoing>SequenceFlow_1fu9o4x</bpmn:outgoing>
+ </bpmn:startEvent>
+ <bpmn:association id="Association_1le3nwi" sourceRef="AssignPnf_StartEvent" targetRef="TextAnnotation_184cxp4" />
<bpmn:textAnnotation id="TextAnnotation_184cxp4">
<bpmn:text>Inputs:
- - pnfCorrelationId - String
- - uuid - String</bpmn:text>
+ - pnfName - String
+</bpmn:text>
</bpmn:textAnnotation>
- <bpmn:association id="Association_1le3nwi" sourceRef="AssignPnf_StartEvent" targetRef="TextAnnotation_184cxp4" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_0go8wi3">
<bpmndi:BPMNShape id="Participant_1dwc5st_di" bpmnElement="Participant_1dwc5st" isHorizontal="true">
- <dc:Bounds x="160" y="80" width="1100" height="390" />
+ <dc:Bounds x="160" y="80" width="646" height="391" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Participant_0gycee4_di" bpmnElement="Participant_0gycee4" isHorizontal="true">
- <dc:Bounds x="590" y="570" width="502" height="60" />
+ <dc:Bounds x="260" y="567" width="502" height="60" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="ServiceTask_1ix8822_di" bpmnElement="CreatePnfEntryInAai">
- <dc:Bounds x="920" y="247" width="100" height="80" />
- </bpmndi:BPMNShape>
- <bpmndi:BPMNShape id="ExclusiveGateway_1l92fkt_di" bpmnElement="DoesAaiContainInfoAboutPnf" isMarkerVisible="true">
- <dc:Bounds x="795" y="262" width="50" height="50" />
- <bpmndi:BPMNLabel>
- <dc:Bounds x="777" y="322" width="85" height="27" />
- </bpmndi:BPMNLabel>
- </bpmndi:BPMNShape>
- <bpmndi:BPMNShape id="ServiceTask_0ebur3y_di" bpmnElement="CheckAaiForPnfCorrelationId">
- <dc:Bounds x="640" y="247" width="100" height="80" />
+ <dc:Bounds x="461" y="247" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="StartEvent_1g3euow_di" bpmnElement="AssignPnf_StartEvent">
<dc:Bounds x="219" y="269" width="36" height="36" />
@@ -70,55 +42,27 @@
<bpmndi:BPMNShape id="TextAnnotation_184cxp4_di" bpmnElement="TextAnnotation_184cxp4">
<dc:Bounds x="236" y="150" width="243" height="53" />
</bpmndi:BPMNShape>
- <bpmndi:BPMNEdge id="SequenceFlow_081rs5d_di" bpmnElement="SequenceFlow_081rs5d">
- <di:waypoint x="740" y="287" />
- <di:waypoint x="795" y="287" />
- </bpmndi:BPMNEdge>
- <bpmndi:BPMNEdge id="SequenceFlow_0fn5kgz_di" bpmnElement="SequenceFlow_0fn5kgz">
- <di:waypoint x="845" y="287" />
- <di:waypoint x="920" y="287" />
- <bpmndi:BPMNLabel>
- <dc:Bounds x="854" y="290" width="15" height="14" />
- </bpmndi:BPMNLabel>
- </bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="MessageFlow_0xh6bkn_di" bpmnElement="MessageFlow_0xh6bkn">
- <di:waypoint x="970" y="327" />
- <di:waypoint x="970" y="570" />
- </bpmndi:BPMNEdge>
- <bpmndi:BPMNEdge id="MessageFlow_0cnehf5_di" bpmnElement="MessageFlow_0cnehf5">
- <di:waypoint x="710" y="570" />
- <di:waypoint x="710" y="327" />
- </bpmndi:BPMNEdge>
- <bpmndi:BPMNEdge id="MessageFlow_1e1pjve_di" bpmnElement="MessageFlow_1e1pjve">
- <di:waypoint x="671" y="327" />
- <di:waypoint x="671" y="570" />
+ <di:waypoint x="511" y="327" />
+ <di:waypoint x="511" y="567" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Association_1le3nwi_di" bpmnElement="Association_1le3nwi">
<di:waypoint x="237" y="269" />
<di:waypoint x="237" y="203" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="EndEvent_1wfgsdz_di" bpmnElement="AaiEntryExists">
- <dc:Bounds x="1152" y="269" width="36" height="36" />
+ <dc:Bounds x="722" y="269" width="36" height="36" />
<bpmndi:BPMNLabel>
- <dc:Bounds x="1133" y="312" width="77" height="14" />
+ <dc:Bounds x="703" y="312" width="77" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
- <bpmndi:BPMNEdge id="SequenceFlow_1ewfz8r_di" bpmnElement="SequenceFlow_1ewfz8r">
- <di:waypoint x="820" y="262" />
- <di:waypoint x="820" y="170" />
- <di:waypoint x="1170" y="170" />
- <di:waypoint x="1170" y="269" />
- <bpmndi:BPMNLabel>
- <dc:Bounds x="822" y="240" width="19" height="40" />
- </bpmndi:BPMNLabel>
- </bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="SequenceFlow_0l6rtzy_di" bpmnElement="SequenceFlow_0l6rtzy">
- <di:waypoint x="1020" y="287" />
- <di:waypoint x="1152" y="287" />
+ <di:waypoint x="561" y="287" />
+ <di:waypoint x="722" y="287" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="SequenceFlow_1fu9o4x_di" bpmnElement="SequenceFlow_1fu9o4x">
<di:waypoint x="255" y="287" />
- <di:waypoint x="640" y="287" />
+ <di:waypoint x="461" y="287" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationId.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationId.java
deleted file mode 100644
index 29914252d8..0000000000
--- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationId.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package org.onap.so.bpmn.infrastructure.pnf.tasks;
-
-import joptsimple.internal.Strings;
-import org.onap.so.bpmn.common.BuildingBlockExecution;
-import org.onap.so.client.exception.BBObjectNotFoundException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Component;
-import java.io.IOException;
-import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_PNF;
-import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID;
-
-@Component
-public class CheckAaiForPnfCorrelationId extends PnfBaseTasks {
- private static final Logger logger = LoggerFactory.getLogger(CheckAaiForPnfCorrelationId.class);
-
- @Override
- public void execute(BuildingBlockExecution execution) {
- try {
- String pnfCorrelationId = extractPnf(execution).getPnfName();
- checkIfPnfCorrelationIdPresent(execution, pnfCorrelationId);
- checkIfPnfExistsInAai(execution, pnfCorrelationId);
- } catch (BBObjectNotFoundException e) {
- exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e);
- }
-
- }
-
- private void checkIfPnfCorrelationIdPresent(BuildingBlockExecution execution, String pnfCorrelationId) {
- if (Strings.isNullOrEmpty(pnfCorrelationId)) {
- exceptionUtil.buildAndThrowWorkflowException(execution, 500, PNF_CORRELATION_ID + " is not set");
- }
- }
-
- private void checkIfPnfExistsInAai(BuildingBlockExecution execution, String pnfCorrelationId) {
- try {
- boolean isEntry = pnfManagement.getEntryFor(pnfCorrelationId).isPresent();
- logger.debug("AAI entry is found for pnf correlation id {}: {}", PNF_CORRELATION_ID, isEntry);
- execution.setVariable(AAI_CONTAINS_INFO_ABOUT_PNF, isEntry);
- } catch (IOException e) {
- logger.error("Exception in check AAI for pnf_correlation_id execution", e);
- exceptionUtil.buildAndThrowWorkflowException(execution, 9999, e);
- }
- }
-}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAai.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAai.java
deleted file mode 100644
index 6e86ad619e..0000000000
--- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAai.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package org.onap.so.bpmn.infrastructure.pnf.tasks;
-
-import org.onap.aai.domain.yang.Pnf;
-import org.onap.so.bpmn.common.BuildingBlockExecution;
-import org.onap.so.client.exception.BBObjectNotFoundException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Component;
-
-@Component
-public class CreatePnfEntryInAai extends PnfBaseTasks {
- private static final Logger logger = LoggerFactory.getLogger(CreatePnfEntryInAai.class);
-
- @Override
- public void execute(BuildingBlockExecution execution) throws Exception {
- try {
- org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf pnf = extractPnf(execution);
- String pnfCorrelationId = pnf.getPnfName();
- pnfManagement.createEntry(pnfCorrelationId, preparePnfForAai(pnf));
- logger.debug("AAI entry is created for pnf correlation id: {}, pnf uuid: {}", pnfCorrelationId,
- pnf.getPnfId());
- } catch (BBObjectNotFoundException e) {
- exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e);
- }
- }
-
- private Pnf preparePnfForAai(org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf pnf) {
- Pnf pnfAai = new Pnf();
- pnfAai.setPnfId(pnf.getPnfId());
- pnfAai.setPnfName(pnf.getPnfName());
- return pnfAai;
- }
-
-}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfBaseTasks.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfBaseTasks.java
deleted file mode 100644
index d8e3379afb..0000000000
--- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfBaseTasks.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.onap.so.bpmn.infrastructure.pnf.tasks;
-
-import org.onap.so.bpmn.common.BuildingBlockExecution;
-import org.onap.so.bpmn.infrastructure.pnf.management.PnfManagement;
-import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
-import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
-import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
-import org.onap.so.client.exception.BBObjectNotFoundException;
-import org.onap.so.client.exception.ExceptionBuilder;
-import org.springframework.beans.factory.annotation.Autowired;
-
-public abstract class PnfBaseTasks {
- protected PnfManagement pnfManagement;
- @Autowired
- protected ExceptionBuilder exceptionUtil;
- @Autowired
- protected ExtractPojosForBB extractPojosForBB;
-
- @Autowired
- public void setPnfManagement(PnfManagement pnfManagement) {
- this.pnfManagement = pnfManagement;
- }
-
- public abstract void execute(BuildingBlockExecution execution) throws Exception;
-
- protected Pnf extractPnf(BuildingBlockExecution execution) throws BBObjectNotFoundException {
- return extractPojosForBB.extractByKey(execution, ResourceKey.PNF);
- }
-}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationIdTest.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationIdTest.java
deleted file mode 100644
index 3fa9fbf3b5..0000000000
--- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationIdTest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-package org.onap.so.bpmn.infrastructure.pnf.tasks;
-
-import org.camunda.bpm.engine.delegate.BpmnError;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.runners.Enclosed;
-import org.junit.rules.ExpectedException;
-import org.junit.runner.RunWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.so.bpmn.common.BuildingBlockExecution;
-import org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl;
-import org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementThrowingException;
-import org.onap.so.bpmn.infrastructure.pnf.management.PnfManagement;
-import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
-import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
-import org.onap.so.client.exception.ExceptionBuilder;
-import java.io.IOException;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.anyInt;
-import static org.mockito.Mockito.anyString;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_PNF;
-import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID;
-import static org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl.ID_WITHOUT_ENTRY;
-import static org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl.ID_WITH_ENTRY;
-import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.PNF_UUID;
-import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.preparePnf;
-
-@RunWith(Enclosed.class)
-public class CheckAaiForPnfCorrelationIdTest {
-
- @RunWith(MockitoJUnitRunner.class)
- public static class ConnectionOkTests {
-
- @Mock
- private ExtractPojosForBB extractPojosForBB;
- @Mock
- private ExceptionBuilder exceptionUtil;
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
- @InjectMocks
- private CheckAaiForPnfCorrelationId task = new CheckAaiForPnfCorrelationId();
- private PnfManagement pnfManagementTest = new PnfManagementTestImpl();
-
- @Before
- public void setUp() {
- task.setPnfManagement(pnfManagementTest);
- }
-
- @Test
- public void shouldThrowExceptionWhenPnfCorrelationIdIsNotSet() throws Exception {
- // given
- when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF))).thenReturn(preparePnf(null, PNF_UUID));
- BuildingBlockExecution execution = mock(BuildingBlockExecution.class);
- doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(eq(execution),
- anyInt(), anyString());
- // when, then
- expectedException.expect(BpmnError.class);
- task.execute(execution);
- verify(exceptionUtil).buildAndThrowWorkflowException(eq(execution), anyInt(), anyString());
- }
-
- @Test
- public void shouldSetCorrectVariablesWhenAaiDoesNotContainInfoAboutPnf() throws Exception {
- // given
- when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF)))
- .thenReturn(preparePnf(ID_WITHOUT_ENTRY, PNF_UUID));
- BuildingBlockExecution execution = mock(BuildingBlockExecution.class);
- // when
- task.execute(execution);
- // then
- verify(execution).setVariable(AAI_CONTAINS_INFO_ABOUT_PNF, false);
- }
-
- @Test
- public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnfWithoutIp() throws Exception {
- // given
- when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF)))
- .thenReturn(preparePnf(ID_WITH_ENTRY, PNF_UUID));
- BuildingBlockExecution execution = mock(BuildingBlockExecution.class);
- // when
- task.execute(execution);
- // then
- verify(execution).setVariable(AAI_CONTAINS_INFO_ABOUT_PNF, true);
- }
- }
-
- @RunWith(MockitoJUnitRunner.class)
- public static class NoConnectionTests {
-
- @Mock
- private ExtractPojosForBB extractPojosForBB;
- @Mock
- private ExceptionBuilder exceptionUtil;
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
- @InjectMocks
- private CheckAaiForPnfCorrelationId task = new CheckAaiForPnfCorrelationId();
- private PnfManagement pnfManagementTest = new PnfManagementThrowingException();
-
- @Before
- public void setUp() throws Exception {
- task.setPnfManagement(pnfManagementTest);
- when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF)))
- .thenReturn(preparePnf(PNF_CORRELATION_ID, PNF_UUID));
- }
-
- @Test
- public void shouldThrowExceptionWhenIoExceptionOnConnectionToAai() {
- // given
- BuildingBlockExecution execution = mock(BuildingBlockExecution.class);
- doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(eq(execution),
- anyInt(), any(IOException.class));
- // when, then
- expectedException.expect(BpmnError.class);
- task.execute(execution);
- verify(exceptionUtil).buildAndThrowWorkflowException(eq(execution), anyInt(), any(IOException.class));
- }
- }
-}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAaiTest.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAaiTest.java
deleted file mode 100644
index ed8dd82efb..0000000000
--- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAaiTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package org.onap.so.bpmn.infrastructure.pnf.tasks;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.aai.domain.yang.Pnf;
-import org.onap.so.bpmn.common.BuildingBlockExecution;
-import org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl;
-import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
-import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.PNF_CORRELATION_ID;
-import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.PNF_UUID;
-import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.preparePnf;
-
-@RunWith(MockitoJUnitRunner.class)
-public class CreatePnfEntryInAaiTest {
-
- @Mock
- private ExtractPojosForBB extractPojosForBB;
- @InjectMocks
- private CreatePnfEntryInAai task = new CreatePnfEntryInAai();
- private PnfManagementTestImpl pnfManagementTest = new PnfManagementTestImpl();
-
- @Before
- public void setUp() throws Exception {
- task.setPnfManagement(pnfManagementTest);
- when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF)))
- .thenReturn(preparePnf(PNF_CORRELATION_ID, PNF_UUID));
- }
-
- @Test
- public void shouldSetPnfIdAndPnfName() throws Exception {
- // when
- task.execute(mock(BuildingBlockExecution.class));
- // then
- Pnf createdEntry = pnfManagementTest.getCreated().get(PNF_CORRELATION_ID);
- assertThat(createdEntry.getPnfId()).isEqualTo(PNF_UUID);
- assertThat(createdEntry.getPnfName()).isEqualTo(PNF_CORRELATION_ID);
- assertThat(createdEntry.isInMaint()).isNull();
- }
-
-}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfTasksUtils.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfTasksUtils.java
deleted file mode 100644
index 49fe96c3d9..0000000000
--- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfTasksUtils.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package org.onap.so.bpmn.infrastructure.pnf.tasks;
-
-import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
-import java.util.UUID;
-
-public class PnfTasksUtils {
- static final String PNF_UUID = UUID.nameUUIDFromBytes("testUuid".getBytes()).toString();
- static final String PNF_CORRELATION_ID = "testPnfCorrelationId";
-
- public static Pnf preparePnf(String pnfName, String pnfUuid) {
- Pnf pnf = new Pnf();
- pnf.setPnfName(pnfName);
- pnf.setPnfId(pnfUuid);
- return pnf;
- }
-
-}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java
index b9f73f3f0e..22089dae1f 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java
@@ -6,6 +6,8 @@
* ================================================================================
* Modifications Copyright (c) 2019 Samsung
* ================================================================================
+ * Modifications Copyright (c) 2020 Nokia
+ * ================================================================================
* 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
@@ -29,6 +31,7 @@ import java.util.TreeSet;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import org.onap.so.client.orchestration.AAIPnfResources;
import org.onap.so.logger.LoggingAnchor;
import org.camunda.bpm.engine.delegate.BpmnError;
import org.onap.so.bpmn.common.BuildingBlockExecution;
@@ -43,6 +46,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness;
import org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy;
import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity;
import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
import org.onap.so.bpmn.servicedecomposition.bbobjects.Project;
import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
@@ -50,7 +54,6 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
-import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException;
import org.onap.so.client.aai.AAIObjectPlurals;
import org.onap.so.client.aai.entities.uri.AAIResourceUri;
import org.onap.so.client.aai.entities.uri.AAIUriFactory;
@@ -87,6 +90,8 @@ public class AAICreateTasks {
@Autowired
private AAIVnfResources aaiVnfResources;
@Autowired
+ private AAIPnfResources aaiPnfResources;
+ @Autowired
private ExceptionBuilder exceptionUtil;
@Autowired
private ExtractPojosForBB extractPojosForBB;
@@ -252,6 +257,17 @@ public class AAICreateTasks {
}
}
+ public void createPnf(BuildingBlockExecution execution) {
+ try {
+ Pnf pnf = extractPojosForBB.extractByKey(execution, ResourceKey.PNF);
+ ServiceInstance serviceInstance =
+ extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
+ aaiPnfResources.createPnfAndConnectServiceInstance(pnf, serviceInstance);
+ } catch (BBObjectNotFoundException e) {
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e);
+ }
+ }
+
/**
* This method is used for separating (,) from the string.
*
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/aai/mapper/AAIObjectMapper.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/aai/mapper/AAIObjectMapper.java
index 06f6550d51..11a7b83259 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/aai/mapper/AAIObjectMapper.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/aai/mapper/AAIObjectMapper.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright (c) 2020 Nokia
+ * ================================================================================
* 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
@@ -87,6 +89,10 @@ public class AAIObjectMapper {
return modelMapper.map(vnf, org.onap.aai.domain.yang.GenericVnf.class);
}
+ public org.onap.aai.domain.yang.Pnf mapPnf(Pnf pnf) {
+ return modelMapper.map(pnf, org.onap.aai.domain.yang.Pnf.class);
+ }
+
public org.onap.aai.domain.yang.VfModule mapVfModule(VfModule vfModule) {
if (modelMapper.getTypeMap(VfModule.class, org.onap.aai.domain.yang.VfModule.class) == null) {
modelMapper.addMappings(new PropertyMap<VfModule, org.onap.aai.domain.yang.VfModule>() {
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java
new file mode 100644
index 0000000000..9dd44c43e9
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Nokia Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.client.orchestration;
+
+import java.util.Optional;
+import org.onap.so.bpmn.common.InjectionHelper;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.client.aai.AAIObjectType;
+import org.onap.so.client.aai.entities.uri.AAIResourceUri;
+import org.onap.so.client.aai.entities.uri.AAIUriFactory;
+import org.onap.so.client.aai.mapper.AAIObjectMapper;
+import org.onap.so.db.catalog.beans.OrchestrationStatus;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class AAIPnfResources {
+
+ @Autowired
+ private InjectionHelper injectionHelper;
+
+ @Autowired
+ private AAIObjectMapper aaiObjectMapper;
+
+ public void createPnfAndConnectServiceInstance(Pnf pnf, ServiceInstance serviceInstance) {
+ AAIResourceUri pnfURI = AAIUriFactory.createResourceUri(AAIObjectType.PNF, pnf.getPnfName());
+ pnf.setOrchestrationStatus(OrchestrationStatus.INVENTORIED);
+ AAIResourceUri serviceInstanceURI =
+ AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance.getServiceInstanceId());
+ injectionHelper.getAaiClient().createIfNotExists(pnfURI, Optional.of(aaiObjectMapper.mapPnf(pnf)))
+ .connect(pnfURI, serviceInstanceURI);
+ }
+}
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java
index 39efa6dc76..73896d7d6d 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright (c) 2020 Nokia
+ * ================================================================================
* 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
@@ -40,6 +42,7 @@ import org.onap.so.client.orchestration.AAICollectionResources;
import org.onap.so.client.orchestration.AAIConfigurationResources;
import org.onap.so.client.orchestration.AAIInstanceGroupResources;
import org.onap.so.client.orchestration.AAINetworkResources;
+import org.onap.so.client.orchestration.AAIPnfResources;
import org.onap.so.client.orchestration.AAIServiceInstanceResources;
import org.onap.so.client.orchestration.AAIVfModuleResources;
import org.onap.so.client.orchestration.AAIVnfResources;
@@ -69,6 +72,9 @@ public abstract class BaseTaskTest extends TestDataSetup {
protected AAIVnfResources aaiVnfResources;
@Mock
+ protected AAIPnfResources aaiPnfResources;
+
+ @Mock
protected AAIVfModuleResources aaiVfModuleResources;
@Mock
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java
index a8550d8df9..a8f47fc763 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright (c) 2020 Nokia
+ * ================================================================================
* 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
@@ -55,6 +57,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness;
import org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy;
import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
@@ -74,6 +77,7 @@ public class AAICreateTasksTest extends BaseTaskTest {
private ServiceInstance serviceInstance;
private L3Network network;
private GenericVnf genericVnf;
+ private Pnf pnf;
private VolumeGroup volumeGroup;
private CloudRegion cloudRegion;
private VfModule vfModule;
@@ -93,6 +97,7 @@ public class AAICreateTasksTest extends BaseTaskTest {
serviceInstance = setServiceInstance();
network = setL3Network();
genericVnf = setGenericVnf();
+ pnf = buildPnf();
volumeGroup = setVolumeGroup();
cloudRegion = setCloudRegion();
vfModule = setVfModule();
@@ -324,6 +329,19 @@ public class AAICreateTasksTest extends BaseTaskTest {
verify(aaiVnfResources, times(1)).createVnfandConnectServiceInstance(genericVnf, serviceInstance);
}
+ @Test
+ public void createPnfShouldCallCreatePnfAndConnectServiceInstance() throws BBObjectNotFoundException {
+ when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.PNF))).thenReturn(pnf);
+ aaiCreateTasks.createPnf(execution);
+ verify(aaiPnfResources, times(1)).createPnfAndConnectServiceInstance(pnf, serviceInstance);
+ }
+
+ @Test
+ public void createPnfShouldThrowBpmnErrorWhenPnfIsNotFound() throws BBObjectNotFoundException {
+ expectedException.expect(BpmnError.class);
+ doThrow(BBObjectNotFoundException.class).when(extractPojosForBB).extractByKey(execution, ResourceKey.PNF);
+ aaiCreateTasks.createPnf(execution);
+ }
@Test
public void createVfModuleTest() throws Exception {
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java
new file mode 100644
index 0000000000..a929f256ac
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java
@@ -0,0 +1,86 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Nokia Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.client.orchestration;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import java.util.Optional;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.bpmn.common.InjectionHelper;
+import org.onap.so.bpmn.common.data.TestDataSetup;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.client.aai.AAIResourcesClient;
+import org.onap.so.client.aai.entities.uri.AAIResourceUri;
+import org.onap.so.client.aai.mapper.AAIObjectMapper;
+import org.onap.so.db.catalog.beans.OrchestrationStatus;
+
+@RunWith(MockitoJUnitRunner.Silent.class)
+public class AAIPnfResourcesTest extends TestDataSetup {
+
+ private Pnf pnf;
+ private ServiceInstance serviceInstance;
+
+ @Mock
+ protected AAIObjectMapper aaiObjectMapperMock;
+
+ @Mock
+ protected InjectionHelper injectionHelperMock;
+
+ @Mock
+ protected AAIResourcesClient aaiResourcesClientMock;
+
+ @InjectMocks
+ AAIPnfResources aaiPnfResources = new AAIPnfResources();
+
+ @Before
+ public void setUp() {
+ pnf = buildPnf();
+ pnf.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
+ serviceInstance = buildServiceInstance();
+
+ doReturn(aaiResourcesClientMock).when(injectionHelperMock).getAaiClient();
+ }
+
+ @Test
+ public void createPnfAndConnectServiceInstanceShouldSetInventoriedStatusAndCallConnectMethod() {
+ org.onap.aai.domain.yang.Pnf pnfYang = new org.onap.aai.domain.yang.Pnf();
+
+ doReturn(pnfYang).when(aaiObjectMapperMock).mapPnf(pnf);
+ doReturn(aaiResourcesClientMock).when(aaiResourcesClientMock).createIfNotExists(any(AAIResourceUri.class),
+ eq(Optional.of(pnfYang)));
+
+ aaiPnfResources.createPnfAndConnectServiceInstance(pnf, serviceInstance);
+
+ assertEquals(OrchestrationStatus.INVENTORIED, pnf.getOrchestrationStatus());
+ verify(aaiResourcesClientMock, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
+ }
+
+}