Containerization feature of SO
[so.git] / bpmn / mso-infrastructure-bpmn / src / test / java / org / onap / so / 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.onap.so.bpmn.infrastructure.pnf.delegate.bpmn;
22
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;
29
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33
34 import org.camunda.bpm.engine.RuntimeService;
35 import org.camunda.bpm.engine.history.HistoricVariableInstance;
36 import org.camunda.bpm.engine.runtime.ProcessInstance;
37 import org.camunda.bpm.engine.test.Deployment;
38 import org.camunda.bpm.engine.test.ProcessEngineRule;
39 import org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests;
40 import org.junit.Ignore;
41 import org.junit.Rule;
42 import org.junit.Test;
43 import org.junit.runner.RunWith;
44 import org.onap.so.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl;
45 import org.springframework.beans.factory.annotation.Autowired;
46 import org.springframework.test.context.ContextConfiguration;
47 import org.springframework.test.context.junit4.SpringRunner;
48
49 @RunWith(SpringRunner.class)
50 @ContextConfiguration(locations = "/applicationContext_forPnfTesting.xml")
51 @Ignore
52 public class CreateAndActivatePnfResourceTest {
53
54     private static final String TIMEOUT_10_S = "PT10S";
55     @Autowired
56     private RuntimeService runtimeService;
57
58     @Autowired
59     @Rule
60     public ProcessEngineRule processEngineRule;
61
62     @Autowired
63     private AaiConnectionTestImpl aaiConnection;
64
65     @Test
66     @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
67     public void shouldSaveCurrentIpToVariableIfItAlreadyExistsInAai() throws Exception {
68         // given
69         aaiConnection.reset();
70         BpmnAwareTests.init(processEngineRule.getProcessEngine());
71         Map<String, Object> variables = new HashMap<>();
72         variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S);
73         variables.put(CORRELATION_ID, ID_WITH_ENTRY_AND_IP);
74         // when
75         ProcessInstance instance = runtimeService
76                 .startProcessInstanceByKey("CreateAndActivatePnfResource", variables);
77         // then
78         assertThat(instance).isEnded().hasPassedInOrder(
79                 "CreateAndActivatePnf_StartEvent",
80                 "CheckAiiForCorrelationId",
81                 "DoesAaiContainInfoAboutPnf",
82                 "DoesAaiContainInfoAboutIp",
83                 "AaiEntryAlreadyUpToDate"
84         );
85     }
86
87     @Test
88     @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
89     public void shouldWaitForMessageFromDmaapAndUpdateAaiEntryWhenIpIsMissingInAaiEntry() throws Exception {
90         // given
91         aaiConnection.reset();
92         BpmnAwareTests.init(processEngineRule.getProcessEngine());
93         Map<String, Object> variables = new HashMap<>();
94         variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S);
95         variables.put(CORRELATION_ID, ID_WITH_ENTRY_NO_IP);
96         // when
97         ProcessInstance instance = runtimeService
98                 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
99         assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
100         runtimeService.createMessageCorrelation("WorkflowMessage")
101                 .processInstanceBusinessKey("businessKey")
102                 .correlateWithResult();
103         // then
104         assertThat(instance).isEnded().hasPassedInOrder(
105                 "CreateAndActivatePnf_StartEvent",
106                 "CheckAiiForCorrelationId",
107                 "DoesAaiContainInfoAboutPnf",
108                 "DoesAaiContainInfoAboutIp",
109                 "AaiEntryExists",
110                 "InformDmaapClient",
111                 "WaitForDmaapPnfReadyNotification",
112                 "AaiEntryUpdated"
113         );
114     }
115
116     @Test
117     @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
118     public void shouldCreateAaiEntryWaitForMessageFromDmaapAndUpdateAaiEntryWhenNoAaiEntry() throws Exception {
119         // given
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);
125         // when
126         ProcessInstance instance = runtimeService
127                 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
128         assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
129         runtimeService.createMessageCorrelation("WorkflowMessage")
130                 .processInstanceBusinessKey("businessKey")
131                 .correlateWithResult();
132         // then
133         assertThat(instance).isEnded().hasPassedInOrder(
134                 "CreateAndActivatePnf_StartEvent",
135                 "CheckAiiForCorrelationId",
136                 "DoesAaiContainInfoAboutPnf",
137                 "CreateAndActivatePnf_CreateAaiEntry",
138                 "AaiEntryExists",
139                 "InformDmaapClient",
140                 "WaitForDmaapPnfReadyNotification",
141                 "AaiEntryUpdated"
142         );
143         assertThat(aaiConnection.getCreated()).containsOnlyKeys(ID_WITHOUT_ENTRY);
144     }
145
146     private List<HistoricVariableInstance> getVariables(ProcessInstance instance) {
147         return processEngineRule.getHistoryService().createHistoricVariableInstanceQuery()
148                 .processInstanceId(instance.getProcessInstanceId()).taskIdIn().list();
149     }
150 }