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.openecomp.mso.bpmn.infrastructure.pnf.delegate.bpmn;
23 import static org.camunda.bpm.engine.test.assertions.ProcessEngineAssertions.assertThat;
24 import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITHOUT_ENTRY;
25 import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_AND_IP;
26 import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_NO_IP;
27 import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
29 import java.util.HashMap;
30 import java.util.List;
32 import org.camunda.bpm.engine.RuntimeService;
33 import org.camunda.bpm.engine.history.HistoricVariableInstance;
34 import org.camunda.bpm.engine.runtime.ProcessInstance;
35 import org.camunda.bpm.engine.test.Deployment;
36 import org.camunda.bpm.engine.test.ProcessEngineRule;
37 import org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests;
38 import org.junit.Rule;
39 import org.junit.Test;
40 import org.junit.runner.RunWith;
41 import org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl;
42 import org.springframework.beans.factory.annotation.Autowired;
43 import org.springframework.test.context.ContextConfiguration;
44 import org.springframework.test.context.junit4.SpringRunner;
46 @RunWith(SpringRunner.class)
47 @ContextConfiguration(locations = "/applicationContext_forPnfTesting.xml")
48 public class CreateAndActivatePnfResourceTest {
50 private static final String TIMEOUT_10_S = "PT10S";
52 private RuntimeService runtimeService;
56 public ProcessEngineRule processEngineRule;
59 private AaiConnectionTestImpl aaiConnection;
62 @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
63 public void shouldSaveCurrentIpToVariableIfItAlreadyExistsInAai() throws Exception {
65 aaiConnection.reset();
66 BpmnAwareTests.init(processEngineRule.getProcessEngine());
67 Map<String, Object> variables = new HashMap<>();
68 variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S);
69 variables.put(CORRELATION_ID, ID_WITH_ENTRY_AND_IP);
71 ProcessInstance instance = runtimeService
72 .startProcessInstanceByKey("CreateAndActivatePnfResource", variables);
74 assertThat(instance).isEnded().hasPassedInOrder(
75 "CreateAndActivatePnf_StartEvent",
76 "CheckAiiForCorrelationId",
77 "DoesAaiContainInfoAboutPnf",
78 "DoesAaiContainInfoAboutIp"
83 @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
84 public void shouldWaitForMessageFromDmaapAndUpdateAaiEntryWhenIpIsMissingInAaiEntry() throws Exception {
86 aaiConnection.reset();
87 BpmnAwareTests.init(processEngineRule.getProcessEngine());
88 Map<String, Object> variables = new HashMap<>();
89 variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S);
90 variables.put(CORRELATION_ID, ID_WITH_ENTRY_NO_IP);
92 ProcessInstance instance = runtimeService
93 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
94 assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
95 runtimeService.createMessageCorrelation("WorkflowMessage")
96 .processInstanceBusinessKey("businessKey")
97 .correlateWithResult();
99 assertThat(instance).isEnded().hasPassedInOrder(
100 "CreateAndActivatePnf_StartEvent",
101 "CheckAiiForCorrelationId",
102 "DoesAaiContainInfoAboutPnf",
103 "DoesAaiContainInfoAboutIp",
105 "WaitForDmaapPnfReadyNotification"
110 @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
111 public void shouldCreateAaiEntryWaitForMessageFromDmaapAndUpdateAaiEntryWhenNoAaiEntry() throws Exception {
113 aaiConnection.reset();
114 BpmnAwareTests.init(processEngineRule.getProcessEngine());
115 Map<String, Object> variables = new HashMap<>();
116 variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S);
117 variables.put(CORRELATION_ID, ID_WITHOUT_ENTRY);
119 ProcessInstance instance = runtimeService
120 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
121 assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
122 runtimeService.createMessageCorrelation("WorkflowMessage")
123 .processInstanceBusinessKey("businessKey")
124 .correlateWithResult();
126 assertThat(instance).isEnded().hasPassedInOrder(
127 "CreateAndActivatePnf_StartEvent",
128 "CheckAiiForCorrelationId",
129 "DoesAaiContainInfoAboutPnf",
130 "CreateAndActivatePnf_CreateAaiEntry",
132 "WaitForDmaapPnfReadyNotification"
134 assertThat(aaiConnection.getCreated()).containsExactly(ID_WITHOUT_ENTRY);
137 private List<HistoricVariableInstance> getVariables(ProcessInstance instance) {
138 return processEngineRule.getHistoryService().createHistoricVariableInstanceQuery()
139 .processInstanceId(instance.getProcessInstanceId()).taskIdIn().list();