Merge "Reorder modifiers"
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / java / org / openecomp / mso / bpmn / infrastructure / pnf / delegate / bpmn / CreateAndActivatePnfResourceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.mso.bpmn.infrastructure.pnf.delegate.bpmn;
22
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;
28
29 import java.util.HashMap;
30 import java.util.List;
31 import java.util.Map;
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;
45
46 @RunWith(SpringRunner.class)
47 @ContextConfiguration(locations = "/applicationContext_forPnfTesting.xml")
48 public class CreateAndActivatePnfResourceTest {
49
50     private static final String TIMEOUT_10_S = "PT10S";
51     @Autowired
52     private RuntimeService runtimeService;
53
54     @Autowired
55     @Rule
56     public ProcessEngineRule processEngineRule;
57
58     @Autowired
59     private AaiConnectionTestImpl aaiConnection;
60
61     @Test
62     @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
63     public void shouldSaveCurrentIpToVariableIfItAlreadyExistsInAai() throws Exception {
64         // given
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);
70         // when
71         ProcessInstance instance = runtimeService
72                 .startProcessInstanceByKey("CreateAndActivatePnfResource", variables);
73         // then
74         assertThat(instance).isEnded().hasPassedInOrder(
75                 "CreateAndActivatePnf_StartEvent",
76                 "CheckAiiForCorrelationId",
77                 "DoesAaiContainInfoAboutPnf",
78                 "DoesAaiContainInfoAboutIp",
79                 "AaiEntryAlreadyUpToDate"
80         );
81     }
82
83     @Test
84     @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
85     public void shouldWaitForMessageFromDmaapAndUpdateAaiEntryWhenIpIsMissingInAaiEntry() throws Exception {
86         // given
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);
92         // when
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();
99         // then
100         assertThat(instance).isEnded().hasPassedInOrder(
101                 "CreateAndActivatePnf_StartEvent",
102                 "CheckAiiForCorrelationId",
103                 "DoesAaiContainInfoAboutPnf",
104                 "DoesAaiContainInfoAboutIp",
105                 "AaiEntryExists",
106                 "InformDmaapClient",
107                 "WaitForDmaapPnfReadyNotification",
108                 "AaiEntryUpdated"
109         );
110     }
111
112     @Test
113     @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
114     public void shouldCreateAaiEntryWaitForMessageFromDmaapAndUpdateAaiEntryWhenNoAaiEntry() throws Exception {
115         // given
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);
121         // when
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();
128         // then
129         assertThat(instance).isEnded().hasPassedInOrder(
130                 "CreateAndActivatePnf_StartEvent",
131                 "CheckAiiForCorrelationId",
132                 "DoesAaiContainInfoAboutPnf",
133                 "CreateAndActivatePnf_CreateAaiEntry",
134                 "AaiEntryExists",
135                 "InformDmaapClient",
136                 "WaitForDmaapPnfReadyNotification",
137                 "AaiEntryUpdated"
138         );
139         assertThat(aaiConnection.getCreated()).containsOnlyKeys(ID_WITHOUT_ENTRY);
140     }
141
142     private List<HistoricVariableInstance> getVariables(ProcessInstance instance) {
143         return processEngineRule.getHistoryService().createHistoricVariableInstanceQuery()
144                 .processInstanceId(instance.getProcessInstanceId()).taskIdIn().list();
145     }
146 }