2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.pnf.delegate.bpmn;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.camunda.bpm.engine.test.assertions.ProcessEngineAssertions.assertThat;
25 import static org.onap.so.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITHOUT_ENTRY;
26 import static org.onap.so.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_AND_IP;
27 import static org.onap.so.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_NO_IP;
28 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
30 import java.util.HashMap;
31 import java.util.List;
33 import org.camunda.bpm.engine.RuntimeService;
34 import org.camunda.bpm.engine.history.HistoricVariableInstance;
35 import org.camunda.bpm.engine.runtime.ProcessInstance;
36 import org.camunda.bpm.engine.test.Deployment;
37 import org.camunda.bpm.engine.test.ProcessEngineRule;
38 import org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests;
39 import org.junit.Rule;
40 import org.junit.Test;
41 import org.junit.runner.RunWith;
42 import org.onap.so.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl;
43 import org.onap.so.bpmn.infrastructure.pnf.delegate.DmaapClientTestImpl;
44 import org.springframework.beans.factory.annotation.Autowired;
45 import org.springframework.test.context.ContextConfiguration;
46 import org.springframework.test.context.junit4.SpringRunner;
48 @RunWith(SpringRunner.class)
49 @ContextConfiguration(locations = "/applicationContext_forPnfTesting.xml")
50 public class CreateAndActivatePnfResourceTest {
52 private static final String TIMEOUT_10_S = "PT10S";
54 private RuntimeService runtimeService;
58 public ProcessEngineRule processEngineRule;
61 private AaiConnectionTestImpl aaiConnection;
64 private DmaapClientTestImpl dmaapClientTestImpl;
67 @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
68 public void shouldSaveCurrentIpToVariableIfItAlreadyExistsInAai() throws Exception {
70 aaiConnection.reset();
71 BpmnAwareTests.init(processEngineRule.getProcessEngine());
72 Map<String, Object> variables = new HashMap<>();
73 variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S);
74 variables.put(CORRELATION_ID, ID_WITH_ENTRY_AND_IP);
76 ProcessInstance instance = runtimeService
77 .startProcessInstanceByKey("CreateAndActivatePnfResource", variables);
79 assertThat(instance).isEnded().hasPassedInOrder(
80 "CreateAndActivatePnf_StartEvent",
81 "CheckAiiForCorrelationId",
82 "DoesAaiContainInfoAboutPnf",
83 "DoesAaiContainInfoAboutIp",
84 "AaiEntryAlreadyUpToDate"
89 @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
90 public void shouldWaitForMessageFromDmaapAndUpdateAaiEntryWhenIpIsMissingInAaiEntry() throws Exception {
92 aaiConnection.reset();
93 BpmnAwareTests.init(processEngineRule.getProcessEngine());
94 Map<String, Object> variables = new HashMap<>();
95 variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S);
96 variables.put(CORRELATION_ID, ID_WITH_ENTRY_NO_IP);
98 ProcessInstance instance = runtimeService
99 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
100 assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
101 dmaapClientTestImpl.sendMessage();
104 assertThat(instance).isEnded().hasPassedInOrder(
105 "CreateAndActivatePnf_StartEvent",
106 "CheckAiiForCorrelationId",
107 "DoesAaiContainInfoAboutPnf",
108 "DoesAaiContainInfoAboutIp",
111 "WaitForDmaapPnfReadyNotification",
117 @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
118 public void shouldCreateAaiEntryWaitForMessageFromDmaapAndUpdateAaiEntryWhenNoAaiEntry() throws Exception {
120 aaiConnection.reset();
121 BpmnAwareTests.init(processEngineRule.getProcessEngine());
122 Map<String, Object> variables = new HashMap<>();
123 variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S);
124 variables.put(CORRELATION_ID, ID_WITHOUT_ENTRY);
126 ProcessInstance instance = runtimeService
127 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
128 assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
129 dmaapClientTestImpl.sendMessage();
132 assertThat(instance).isEnded().hasPassedInOrder(
133 "CreateAndActivatePnf_StartEvent",
134 "CheckAiiForCorrelationId",
135 "DoesAaiContainInfoAboutPnf",
136 "CreateAndActivatePnf_CreateAaiEntry",
139 "WaitForDmaapPnfReadyNotification",
142 assertThat(aaiConnection.getCreated()).containsOnlyKeys(ID_WITHOUT_ENTRY);
145 private List<HistoricVariableInstance> getVariables(ProcessInstance instance) {
146 return processEngineRule.getHistoryService().createHistoricVariableInstanceQuery()
147 .processInstanceId(instance.getProcessInstanceId()).taskIdIn().list();