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