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 static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.assertThat;
24 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
26 import java.util.HashMap;
29 import org.assertj.core.api.Assertions;
30 import org.camunda.bpm.engine.RuntimeService;
31 import org.camunda.bpm.engine.runtime.ProcessInstance;
32 import org.camunda.bpm.engine.test.Deployment;
33 import org.camunda.bpm.engine.test.ProcessEngineRule;
34 import org.junit.Rule;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.test.context.ContextConfiguration;
39 import org.springframework.test.context.junit4.SpringRunner;
41 @RunWith(SpringRunner.class)
42 @ContextConfiguration(locations = "/applicationContext_forPnfTesting.xml")
43 public class CreateAndActivatePnfResourceTest {
45 private static final String TIMEOUT_10_S = "PT10S";
47 private RuntimeService runtimeService;
51 public ProcessEngineRule processEngineRule;
54 private AaiConnectionTestImpl aaiConnection;
57 private DmaapClientTestImpl dmaapClientTestImpl;
60 @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
61 public void shouldWaitForMessageFromDmaapAndUpdateAaiEntryWhenAaiEntryExists() {
63 aaiConnection.reset();
64 Map<String, Object> variables = new HashMap<>();
65 variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S);
66 variables.put(CORRELATION_ID, AaiConnectionTestImpl.ID_WITH_ENTRY);
68 ProcessInstance instance = runtimeService
69 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
70 assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
71 dmaapClientTestImpl.sendMessage();
74 assertThat(instance).isEnded().hasPassedInOrder(
75 "CreateAndActivatePnf_StartEvent",
77 "CheckAiiForCorrelationId",
78 "DoesAaiContainInfoAboutPnf",
81 "WaitForDmaapPnfReadyNotification",
87 @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
88 public void shouldCreateAaiEntryWaitForMessageFromDmaapAndUpdateAaiEntryWhenNoAaiEntryExists() {
90 aaiConnection.reset();
92 Map<String, Object> variables = new HashMap<>();
93 variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S);
94 variables.put(CORRELATION_ID, AaiConnectionTestImpl.ID_WITHOUT_ENTRY);
96 ProcessInstance instance = runtimeService
97 .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
98 assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
99 dmaapClientTestImpl.sendMessage();
102 assertThat(instance).isEnded().hasPassedInOrder(
103 "CreateAndActivatePnf_StartEvent",
105 "CheckAiiForCorrelationId",
106 "DoesAaiContainInfoAboutPnf",
107 "CreateAndActivatePnf_CreateAaiEntry",
110 "WaitForDmaapPnfReadyNotification",
113 Assertions.assertThat(aaiConnection.getCreated()).containsOnlyKeys(AaiConnectionTestImpl.ID_WITHOUT_ENTRY);