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