2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.so.bpmn.infrastructure.pnf.delegate;
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;
28 import java.util.HashMap;
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;
45 @RunWith(SpringRunner.class)
46 @ContextConfiguration(locations = "/applicationContext_forPnfTesting.xml")
47 public class CreateAndActivatePnfResourceTest {
49 private static final String TIMEOUT_10_S = "PT10S";
51 private RuntimeService runtimeService;
55 public ProcessEngineRule processEngineRule;
56 private static final String VALID_UUID = UUID.nameUUIDFromBytes("testUuid".getBytes()).toString();
59 private AaiConnectionTestImpl aaiConnection;
62 private DmaapClientTestImpl dmaapClientTestImpl;
65 @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
66 public void shouldWaitForMessageFromDmaapAndUpdateAaiEntryWhenAaiEntryExists() {
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);
75 ProcessInstance instance = runtimeService
76 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
77 BpmnAwareAssertions.assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
78 dmaapClientTestImpl.sendMessage();
81 BpmnAwareAssertions.assertThat(instance).isEnded().hasPassedInOrder(
82 "CreateAndActivatePnf_StartEvent",
84 "CheckAiiForCorrelationId",
85 "DoesAaiContainInfoAboutPnf",
88 "WaitForDmaapPnfReadyNotification",
94 @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
95 public void shouldCreateAaiEntryWaitForMessageFromDmaapAndUpdateAaiEntryWhenNoAaiEntryExists() {
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);
104 ProcessInstance instance = runtimeService
105 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
106 BpmnAwareAssertions.assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
107 dmaapClientTestImpl.sendMessage();
110 BpmnAwareAssertions.assertThat(instance).isEnded().hasPassedInOrder(
111 "CreateAndActivatePnf_StartEvent",
113 "CheckAiiForCorrelationId",
114 "DoesAaiContainInfoAboutPnf",
115 "CreatePnfEntryInAai",
118 "WaitForDmaapPnfReadyNotification",
121 Assertions.assertThat(aaiConnection.getCreated()).containsOnlyKeys(AaiConnectionTestImpl.ID_WITHOUT_ENTRY);