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",
79 "AaiEntryAlreadyUpToDate"
84 @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
85 public void shouldWaitForMessageFromDmaapAndUpdateAaiEntryWhenIpIsMissingInAaiEntry() throws Exception {
87 aaiConnection.reset();
88 BpmnAwareTests.init(processEngineRule.getProcessEngine());
89 Map<String, Object> variables = new HashMap<>();
90 variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S);
91 variables.put(CORRELATION_ID, ID_WITH_ENTRY_NO_IP);
93 ProcessInstance instance = runtimeService
94 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
95 assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
96 runtimeService.createMessageCorrelation("WorkflowMessage")
97 .processInstanceBusinessKey("businessKey")
98 .correlateWithResult();
100 assertThat(instance).isEnded().hasPassedInOrder(
101 "CreateAndActivatePnf_StartEvent",
102 "CheckAiiForCorrelationId",
103 "DoesAaiContainInfoAboutPnf",
104 "DoesAaiContainInfoAboutIp",
107 "WaitForDmaapPnfReadyNotification",
113 @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
114 public void shouldCreateAaiEntryWaitForMessageFromDmaapAndUpdateAaiEntryWhenNoAaiEntry() throws Exception {
116 aaiConnection.reset();
117 BpmnAwareTests.init(processEngineRule.getProcessEngine());
118 Map<String, Object> variables = new HashMap<>();
119 variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S);
120 variables.put(CORRELATION_ID, ID_WITHOUT_ENTRY);
122 ProcessInstance instance = runtimeService
123 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
124 assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
125 runtimeService.createMessageCorrelation("WorkflowMessage")
126 .processInstanceBusinessKey("businessKey")
127 .correlateWithResult();
129 assertThat(instance).isEnded().hasPassedInOrder(
130 "CreateAndActivatePnf_StartEvent",
131 "CheckAiiForCorrelationId",
132 "DoesAaiContainInfoAboutPnf",
133 "CreateAndActivatePnf_CreateAaiEntry",
136 "WaitForDmaapPnfReadyNotification",
139 assertThat(aaiConnection.getCreated()).containsOnlyKeys(ID_WITHOUT_ENTRY);
142 private List<HistoricVariableInstance> getVariables(ProcessInstance instance) {
143 return processEngineRule.getHistoryService().createHistoricVariableInstanceQuery()
144 .processInstanceId(instance.getProcessInstanceId()).taskIdIn().list();