Merge "Bug fix for getInstnaceId" into casablanca
[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  * Modifications Copyright 2018 Nokia
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.infrastructure.pnf.delegate;
24
25 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
26 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
27
28 import java.util.HashMap;
29 import java.util.Map;
30 import java.util.UUID;
31 import org.assertj.core.api.Assertions;
32 import org.camunda.bpm.engine.RuntimeService;
33 import org.camunda.bpm.engine.runtime.ProcessInstance;
34 import org.camunda.bpm.engine.test.Deployment;
35 import org.camunda.bpm.engine.test.ProcessEngineRule;
36 import org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions;
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.springframework.beans.factory.annotation.Autowired;
42 import org.springframework.test.context.ContextConfiguration;
43 import org.springframework.test.context.junit4.SpringRunner;
44
45 @RunWith(SpringRunner.class)
46 @ContextConfiguration(locations = "/applicationContext_forPnfTesting.xml")
47 public class CreateAndActivatePnfResourceTest {
48
49     private static final String TIMEOUT_10_S = "PT10S";
50     @Autowired
51     private RuntimeService runtimeService;
52
53     @Autowired
54     @Rule
55     public ProcessEngineRule processEngineRule;
56     private static final String VALID_UUID = UUID.nameUUIDFromBytes("testUuid".getBytes()).toString();
57
58     @Autowired
59     private AaiConnectionTestImpl aaiConnection;
60
61     @Autowired
62     private DmaapClientTestImpl dmaapClientTestImpl;
63
64     @Test
65     @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
66     public void shouldWaitForMessageFromDmaapAndUpdateAaiEntryWhenAaiEntryExists() {
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, AaiConnectionTestImpl.ID_WITH_ENTRY);
73         variables.put(PNF_UUID, VALID_UUID);
74         // when
75         ProcessInstance instance = runtimeService
76                 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
77         BpmnAwareAssertions.assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
78         dmaapClientTestImpl.sendMessage();
79
80         // then
81         BpmnAwareAssertions.assertThat(instance).isEnded().hasPassedInOrder(
82                 "CreateAndActivatePnf_StartEvent",
83                 "CheckInputs",
84                 "CheckAiiForCorrelationId",
85                 "DoesAaiContainInfoAboutPnf",
86                 "AaiEntryExists",
87                 "InformDmaapClient",
88                 "WaitForDmaapPnfReadyNotification",
89                 "AaiEntryUpdated"
90         );
91     }
92
93     @Test
94     @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
95     public void shouldCreateAaiEntryWaitForMessageFromDmaapAndUpdateAaiEntryWhenNoAaiEntryExists() {
96         // given
97         aaiConnection.reset();
98         BpmnAwareTests.init(processEngineRule.getProcessEngine());
99         Map<String, Object> variables = new HashMap<>();
100         variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S);
101         variables.put(CORRELATION_ID, AaiConnectionTestImpl.ID_WITHOUT_ENTRY);
102         variables.put(PNF_UUID, VALID_UUID);
103         // when
104         ProcessInstance instance = runtimeService
105                 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
106         BpmnAwareAssertions.assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
107         dmaapClientTestImpl.sendMessage();
108
109         // then
110         BpmnAwareAssertions.assertThat(instance).isEnded().hasPassedInOrder(
111                 "CreateAndActivatePnf_StartEvent",
112                 "CheckInputs",
113                 "CheckAiiForCorrelationId",
114                 "DoesAaiContainInfoAboutPnf",
115                 "CreatePnfEntryInAai",
116                 "AaiEntryExists",
117                 "InformDmaapClient",
118                 "WaitForDmaapPnfReadyNotification",
119                 "AaiEntryUpdated"
120         );
121         Assertions.assertThat(aaiConnection.getCreated()).containsOnlyKeys(AaiConnectionTestImpl.ID_WITHOUT_ENTRY);
122     }
123 }