Merge "Use spring auto deployment"
[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.bpmn.BpmnAwareAssertions.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.runtime.ProcessInstance;
31 import org.junit.Test;
32 import org.onap.so.BaseIntegrationTest;
33 import org.springframework.beans.factory.annotation.Autowired;
34
35 public class CreateAndActivatePnfResourceTest extends BaseIntegrationTest {
36
37     private static final String TIMEOUT_10_S = "PT10S";
38
39     @Autowired
40     private AaiConnectionTestImpl aaiConnection;
41
42     @Autowired
43     private DmaapClientTestImpl dmaapClientTestImpl;
44
45     @Test
46     public void shouldWaitForMessageFromDmaapAndUpdateAaiEntryWhenAaiEntryExists() {
47         // given
48         aaiConnection.reset();       
49         Map<String, Object> variables = new HashMap<>();
50         variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S);
51         variables.put(CORRELATION_ID, AaiConnectionTestImpl.ID_WITH_ENTRY);
52         // when
53         ProcessInstance instance = runtimeService
54                 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
55         assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
56         dmaapClientTestImpl.sendMessage();
57
58         // then
59         assertThat(instance).isEnded().hasPassedInOrder(
60                 "CreateAndActivatePnf_StartEvent",
61                 "CheckInputs",
62                 "CheckAiiForCorrelationId",
63                 "DoesAaiContainInfoAboutPnf",
64                 "AaiEntryExists",
65                 "InformDmaapClient",
66                 "WaitForDmaapPnfReadyNotification",
67                 "AaiEntryUpdated"
68         );
69     }
70
71     @Test
72     public void shouldCreateAaiEntryWaitForMessageFromDmaapAndUpdateAaiEntryWhenNoAaiEntryExists() {
73         // given
74         aaiConnection.reset();
75        
76         Map<String, Object> variables = new HashMap<>();
77         variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S);
78         variables.put(CORRELATION_ID, AaiConnectionTestImpl.ID_WITHOUT_ENTRY);
79         // when
80         ProcessInstance instance = runtimeService
81                 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
82         assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
83         dmaapClientTestImpl.sendMessage();
84
85         // then
86         assertThat(instance).isEnded().hasPassedInOrder(
87                 "CreateAndActivatePnf_StartEvent",
88                 "CheckInputs",
89                 "CheckAiiForCorrelationId",
90                 "DoesAaiContainInfoAboutPnf",
91                 "CreateAndActivatePnf_CreateAaiEntry",
92                 "AaiEntryExists",
93                 "InformDmaapClient",
94                 "WaitForDmaapPnfReadyNotification",
95                 "AaiEntryUpdated"
96         );
97         Assertions.assertThat(aaiConnection.getCreated()).containsOnlyKeys(AaiConnectionTestImpl.ID_WITHOUT_ENTRY);
98     }
99 }