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.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions.assertThat;
26 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID;
27 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.assertj.core.data.MapEntry;
33 import org.camunda.bpm.engine.runtime.ProcessInstance;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.onap.so.BaseIntegrationTest;
37 import org.springframework.beans.factory.annotation.Autowired;
39 public class CreateAndActivatePnfResourceTest extends BaseIntegrationTest {
41 private static final String VALID_UUID = UUID.nameUUIDFromBytes("testUuid".getBytes()).toString();
42 private static final String SERVICE_INSTANCE_ID = "serviceForInstance";
44 private Map<String, Object> variables;
47 private PnfManagementTestImpl pnfManagementTest;
50 private DmaapClientTestImpl dmaapClientTestImpl;
54 pnfManagementTest.reset();
55 variables = new HashMap<>();
56 variables.put("serviceInstanceId", SERVICE_INSTANCE_ID);
57 variables.put(PNF_UUID, VALID_UUID);
61 public void shouldWaitForMessageFromDmaapAndUpdateAaiEntryWhenAaiEntryExists() {
63 variables.put(PNF_CORRELATION_ID, PnfManagementTestImpl.ID_WITH_ENTRY);
65 ProcessInstance instance =
66 runtimeService.startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
67 assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
68 dmaapClientTestImpl.sendMessage();
71 assertThat(instance).isEnded().hasPassedInOrder("CreateAndActivatePnf_StartEvent", "CheckInputs",
72 "CheckAiiForPnfCorrelationId", "DoesAaiContainInfoAboutPnf", "AaiEntryExists", "InformDmaapClient",
73 "WaitForDmaapPnfReadyNotification", "CreateRelationId", "AaiEntryUpdated");
74 Assertions.assertThat(pnfManagementTest.getServiceAndPnfRelationMap())
75 .containsOnly(MapEntry.entry(SERVICE_INSTANCE_ID, PnfManagementTestImpl.ID_WITH_ENTRY));
79 public void shouldCreateAaiEntryWaitForMessageFromDmaapAndUpdateAaiEntryWhenNoAaiEntryExists() {
81 variables.put(PNF_CORRELATION_ID, PnfManagementTestImpl.ID_WITHOUT_ENTRY);
83 ProcessInstance instance =
84 runtimeService.startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
85 assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
86 dmaapClientTestImpl.sendMessage();
89 assertThat(instance).isEnded().hasPassedInOrder("CreateAndActivatePnf_StartEvent", "CheckInputs",
90 "CheckAiiForPnfCorrelationId", "DoesAaiContainInfoAboutPnf", "CreatePnfEntryInAai", "AaiEntryExists",
91 "InformDmaapClient", "WaitForDmaapPnfReadyNotification", "CreateRelationId", "AaiEntryUpdated");
92 Assertions.assertThat(pnfManagementTest.getCreated()).containsOnlyKeys(PnfManagementTestImpl.ID_WITHOUT_ENTRY);
93 Assertions.assertThat(pnfManagementTest.getServiceAndPnfRelationMap())
94 .containsOnly(MapEntry.entry(SERVICE_INSTANCE_ID, PnfManagementTestImpl.ID_WITHOUT_ENTRY));