2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.infrastructure.pnf.delegate;
23 import org.assertj.core.api.Assertions;
24 import org.camunda.bpm.engine.RuntimeService;
25 import org.camunda.bpm.engine.runtime.ProcessInstance;
26 import org.camunda.bpm.engine.test.Deployment;
27 import org.camunda.bpm.engine.test.ProcessEngineRule;
28 import org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions;
29 import org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests;
30 import org.junit.Rule;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.test.context.ContextConfiguration;
35 import org.springframework.test.context.junit4.SpringRunner;
37 import java.util.HashMap;
40 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
42 @RunWith(SpringRunner.class)
43 @ContextConfiguration(locations = "/applicationContext_forPnfTesting.xml")
44 public class CreateAndActivatePnfResourceTest {
46 private static final String TIMEOUT_10_S = "PT10S";
48 private RuntimeService runtimeService;
52 public ProcessEngineRule processEngineRule;
55 private AaiConnectionTestImpl aaiConnection;
58 private DmaapClientTestImpl dmaapClientTestImpl;
61 @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
62 public void shouldWaitForMessageFromDmaapAndUpdateAaiEntryWhenAaiEntryExists() {
64 aaiConnection.reset();
65 BpmnAwareTests.init(processEngineRule.getProcessEngine());
66 Map<String, Object> variables = new HashMap<>();
67 variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S);
68 variables.put(CORRELATION_ID, AaiConnectionTestImpl.ID_WITH_ENTRY);
70 ProcessInstance instance = runtimeService
71 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
72 BpmnAwareAssertions.assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
73 dmaapClientTestImpl.sendMessage();
76 BpmnAwareAssertions.assertThat(instance).isEnded().hasPassedInOrder(
77 "CreateAndActivatePnf_StartEvent",
79 "CheckAiiForCorrelationId",
80 "DoesAaiContainInfoAboutPnf",
83 "WaitForDmaapPnfReadyNotification",
89 @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
90 public void shouldCreateAaiEntryWaitForMessageFromDmaapAndUpdateAaiEntryWhenNoAaiEntryExists() {
92 aaiConnection.reset();
93 BpmnAwareTests.init(processEngineRule.getProcessEngine());
94 Map<String, Object> variables = new HashMap<>();
95 variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S);
96 variables.put(CORRELATION_ID, AaiConnectionTestImpl.ID_WITHOUT_ENTRY);
98 ProcessInstance instance = runtimeService
99 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
100 BpmnAwareAssertions.assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
101 dmaapClientTestImpl.sendMessage();
104 BpmnAwareAssertions.assertThat(instance).isEnded().hasPassedInOrder(
105 "CreateAndActivatePnf_StartEvent",
107 "CheckAiiForCorrelationId",
108 "DoesAaiContainInfoAboutPnf",
109 "CreateAndActivatePnf_CreateAaiEntry",
112 "WaitForDmaapPnfReadyNotification",
115 Assertions.assertThat(aaiConnection.getCreated()).containsOnlyKeys(AaiConnectionTestImpl.ID_WITHOUT_ENTRY);