Merge "PNF PnP now always waits"
[so.git] / bpmn / mso-infrastructure-bpmn / src / test / java / org / onap / so / bpmn / infrastructure / pnf / delegate / 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;
22
23 import org.assertj.core.api.Assertions;
24 import org.camunda.bpm.engine.RuntimeService;
25 import org.camunda.bpm.engine.runtime.ProcessInstance;
26 import org.camunda.bpm.engine.test.Deployment;
27 import org.camunda.bpm.engine.test.ProcessEngineRule;
28 import org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions;
29 import org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests;
30 import org.junit.Rule;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.test.context.ContextConfiguration;
35 import org.springframework.test.context.junit4.SpringRunner;
36
37 import java.util.HashMap;
38 import java.util.Map;
39
40 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
41
42 @RunWith(SpringRunner.class)
43 @ContextConfiguration(locations = "/applicationContext_forPnfTesting.xml")
44 public class CreateAndActivatePnfResourceTest {
45
46     private static final String TIMEOUT_10_S = "PT10S";
47     @Autowired
48     private RuntimeService runtimeService;
49
50     @Autowired
51     @Rule
52     public ProcessEngineRule processEngineRule;
53
54     @Autowired
55     private AaiConnectionTestImpl aaiConnection;
56
57     @Autowired
58     private DmaapClientTestImpl dmaapClientTestImpl;
59
60     @Test
61     @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
62     public void shouldWaitForMessageFromDmaapAndUpdateAaiEntryWhenAaiEntryExists() {
63         // given
64         aaiConnection.reset();
65         BpmnAwareTests.init(processEngineRule.getProcessEngine());
66         Map<String, Object> variables = new HashMap<>();
67         variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S);
68         variables.put(CORRELATION_ID, AaiConnectionTestImpl.ID_WITH_ENTRY);
69         // when
70         ProcessInstance instance = runtimeService
71                 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
72         BpmnAwareAssertions.assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
73         dmaapClientTestImpl.sendMessage();
74
75         // then
76         BpmnAwareAssertions.assertThat(instance).isEnded().hasPassedInOrder(
77                 "CreateAndActivatePnf_StartEvent",
78                 "CheckInputs",
79                 "CheckAiiForCorrelationId",
80                 "DoesAaiContainInfoAboutPnf",
81                 "AaiEntryExists",
82                 "InformDmaapClient",
83                 "WaitForDmaapPnfReadyNotification",
84                 "AaiEntryUpdated"
85         );
86     }
87
88     @Test
89     @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
90     public void shouldCreateAaiEntryWaitForMessageFromDmaapAndUpdateAaiEntryWhenNoAaiEntryExists() {
91         // given
92         aaiConnection.reset();
93         BpmnAwareTests.init(processEngineRule.getProcessEngine());
94         Map<String, Object> variables = new HashMap<>();
95         variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S);
96         variables.put(CORRELATION_ID, AaiConnectionTestImpl.ID_WITHOUT_ENTRY);
97         // when
98         ProcessInstance instance = runtimeService
99                 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
100         BpmnAwareAssertions.assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
101         dmaapClientTestImpl.sendMessage();
102
103         // then
104         BpmnAwareAssertions.assertThat(instance).isEnded().hasPassedInOrder(
105                 "CreateAndActivatePnf_StartEvent",
106                 "CheckInputs",
107                 "CheckAiiForCorrelationId",
108                 "DoesAaiContainInfoAboutPnf",
109                 "CreateAndActivatePnf_CreateAaiEntry",
110                 "AaiEntryExists",
111                 "InformDmaapClient",
112                 "WaitForDmaapPnfReadyNotification",
113                 "AaiEntryUpdated"
114         );
115         Assertions.assertThat(aaiConnection.getCreated()).containsOnlyKeys(AaiConnectionTestImpl.ID_WITHOUT_ENTRY);
116     }
117 }