Merge "workflow action should read config for max retries"
[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.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions.assertThat;
26 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
27 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
28
29 import java.util.HashMap;
30 import java.util.Map;
31
32 import java.util.UUID;
33 import org.assertj.core.api.Assertions;
34 import org.assertj.core.data.MapEntry;
35 import org.camunda.bpm.engine.runtime.ProcessInstance;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.onap.so.BaseIntegrationTest;
39 import org.springframework.beans.factory.annotation.Autowired;
40
41 public class CreateAndActivatePnfResourceTest extends BaseIntegrationTest {
42
43     private static final String VALID_UUID = UUID.nameUUIDFromBytes("testUuid".getBytes()).toString();
44     private static final String SERVICE_INSTANCE_ID = "serviceForInstance";
45
46     private Map<String, Object> variables;
47
48     @Autowired
49     private AaiConnectionTestImpl aaiConnection;
50
51     @Autowired
52     private DmaapClientTestImpl dmaapClientTestImpl;
53
54     @Before
55     public void setup() {
56         aaiConnection.reset();
57         variables = new HashMap<>();
58         variables.put("serviceInstanceId", SERVICE_INSTANCE_ID);
59         variables.put(PNF_UUID, VALID_UUID);
60     }
61
62     @Test
63     public void shouldWaitForMessageFromDmaapAndUpdateAaiEntryWhenAaiEntryExists() {
64         // given
65         variables.put(CORRELATION_ID, AaiConnectionTestImpl.ID_WITH_ENTRY);
66         // when
67         ProcessInstance instance = runtimeService
68                 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
69         assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
70         dmaapClientTestImpl.sendMessage();
71
72         // then
73         assertThat(instance).isEnded().hasPassedInOrder(
74                 "CreateAndActivatePnf_StartEvent",
75                 "CheckInputs",
76                 "CheckAiiForCorrelationId",
77                 "DoesAaiContainInfoAboutPnf",
78                 "AaiEntryExists",
79                 "InformDmaapClient",
80                 "WaitForDmaapPnfReadyNotification",
81                 "CreateRelationId",
82                 "AaiEntryUpdated"
83         );
84         Assertions.assertThat(aaiConnection.getServiceAndPnfRelationMap()).
85                 containsOnly(MapEntry.entry(SERVICE_INSTANCE_ID,AaiConnectionTestImpl.ID_WITH_ENTRY));
86     }
87
88     @Test
89     public void shouldCreateAaiEntryWaitForMessageFromDmaapAndUpdateAaiEntryWhenNoAaiEntryExists() {
90         // given
91         variables.put(CORRELATION_ID, AaiConnectionTestImpl.ID_WITHOUT_ENTRY);
92         // when
93         ProcessInstance instance = runtimeService
94                 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
95         assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
96         dmaapClientTestImpl.sendMessage();
97
98         // then
99         assertThat(instance).isEnded().hasPassedInOrder(
100                 "CreateAndActivatePnf_StartEvent",
101                 "CheckInputs",
102                 "CheckAiiForCorrelationId",
103                 "DoesAaiContainInfoAboutPnf",
104                 "CreatePnfEntryInAai",
105                 "AaiEntryExists",
106                 "InformDmaapClient",
107                 "WaitForDmaapPnfReadyNotification",
108                 "CreateRelationId",
109                 "AaiEntryUpdated"
110         );
111         Assertions.assertThat(aaiConnection.getCreated()).containsOnlyKeys(AaiConnectionTestImpl.ID_WITHOUT_ENTRY);
112         Assertions.assertThat(aaiConnection.getServiceAndPnfRelationMap()).
113                 containsOnly(MapEntry.entry(SERVICE_INSTANCE_ID,AaiConnectionTestImpl.ID_WITHOUT_ENTRY));
114     }
115 }