d42717f5c16ae9397c49ade87f64099d65220b97
[so.git] /
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 public class CreateAndActivatePnfResourceTest {
52
53     private static final String TIMEOUT_10_S = "PT10S";
54     @Autowired
55     private RuntimeService runtimeService;
56
57     @Autowired
58     @Rule
59     public ProcessEngineRule processEngineRule;
60
61     @Autowired
62     private AaiConnectionTestImpl aaiConnection;
63
64     @Test
65     @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
66     public void shouldSaveCurrentIpToVariableIfItAlreadyExistsInAai() throws Exception {
67         // given
68         aaiConnection.reset();
69         BpmnAwareTests.init(processEngineRule.getProcessEngine());
70         Map<String, Object> variables = new HashMap<>();
71         variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S);
72         variables.put(CORRELATION_ID, ID_WITH_ENTRY_AND_IP);
73         // when
74         ProcessInstance instance = runtimeService
75                 .startProcessInstanceByKey("CreateAndActivatePnfResource", variables);
76         // then
77         assertThat(instance).isEnded().hasPassedInOrder(
78                 "CreateAndActivatePnf_StartEvent",
79                 "CheckAiiForCorrelationId",
80                 "DoesAaiContainInfoAboutPnf",
81                 "DoesAaiContainInfoAboutIp",
82                 "AaiEntryAlreadyUpToDate"
83         );
84     }
85
86     @Test
87     @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
88     public void shouldWaitForMessageFromDmaapAndUpdateAaiEntryWhenIpIsMissingInAaiEntry() throws Exception {
89         // given
90         aaiConnection.reset();
91         BpmnAwareTests.init(processEngineRule.getProcessEngine());
92         Map<String, Object> variables = new HashMap<>();
93         variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S);
94         variables.put(CORRELATION_ID, ID_WITH_ENTRY_NO_IP);
95         // when
96         ProcessInstance instance = runtimeService
97                 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
98         assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
99         runtimeService.createMessageCorrelation("WorkflowMessage")
100                 .processInstanceBusinessKey("businessKey")
101                 .correlateWithResult();
102         // then
103         assertThat(instance).isEnded().hasPassedInOrder(
104                 "CreateAndActivatePnf_StartEvent",
105                 "CheckAiiForCorrelationId",
106                 "DoesAaiContainInfoAboutPnf",
107                 "DoesAaiContainInfoAboutIp",
108                 "AaiEntryExists",
109                 "InformDmaapClient",
110                 "WaitForDmaapPnfReadyNotification",
111                 "AaiEntryUpdated"
112         );
113     }
114
115     @Test
116     @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
117     public void shouldCreateAaiEntryWaitForMessageFromDmaapAndUpdateAaiEntryWhenNoAaiEntry() throws Exception {
118         // given
119         aaiConnection.reset();
120         BpmnAwareTests.init(processEngineRule.getProcessEngine());
121         Map<String, Object> variables = new HashMap<>();
122         variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S);
123         variables.put(CORRELATION_ID, ID_WITHOUT_ENTRY);
124         // when
125         ProcessInstance instance = runtimeService
126                 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
127         assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
128         runtimeService.createMessageCorrelation("WorkflowMessage")
129                 .processInstanceBusinessKey("businessKey")
130                 .correlateWithResult();
131         // then
132         assertThat(instance).isEnded().hasPassedInOrder(
133                 "CreateAndActivatePnf_StartEvent",
134                 "CheckAiiForCorrelationId",
135                 "DoesAaiContainInfoAboutPnf",
136                 "CreateAndActivatePnf_CreateAaiEntry",
137                 "AaiEntryExists",
138                 "InformDmaapClient",
139                 "WaitForDmaapPnfReadyNotification",
140                 "AaiEntryUpdated"
141         );
142         assertThat(aaiConnection.getCreated()).containsOnlyKeys(ID_WITHOUT_ENTRY);
143     }
144
145     private List<HistoricVariableInstance> getVariables(ProcessInstance instance) {
146         return processEngineRule.getHistoryService().createHistoricVariableInstanceQuery()
147                 .processInstanceId(instance.getProcessInstanceId()).taskIdIn().list();
148     }
149 }