2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.onap.so.bpmn.infrastructure.pnf.delegate;
22 import org.camunda.bpm.engine.delegate.DelegateExecution;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.mockito.InjectMocks;
26 import org.mockito.Mock;
27 import org.onap.aai.domain.yang.Pnf;
28 import org.onap.so.bpmn.infrastructure.pnf.management.PnfManagement;
29 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
30 import static org.junit.Assert.*;
31 import java.io.IOException;
32 import java.util.Optional;
33 import static org.assertj.core.api.Assertions.assertThat;
34 import static org.mockito.ArgumentMatchers.anyString;
35 import static org.mockito.ArgumentMatchers.eq;
36 import static org.mockito.BDDMockito.given;
37 import static org.mockito.Mockito.*;
38 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID;
39 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
40 import static org.onap.so.client.cds.PayloadConstants.PRC_TARGET_SOFTWARE_VERSION;
42 @RunWith(SpringJUnit4ClassRunner.class)
43 public class UpdatePnfEntryInAaiTest {
46 private UpdatePnfEntryInAai updatePnfEntryInAai;
49 private PnfManagement pnfManagementTest;
51 private DelegateExecution execution;
56 public void shouldSetSwVersion() throws Exception {
62 updatePnfEntryInAai.execute(execution);
65 Optional<Pnf> modifiedEntry = pnfManagementTest.getEntryFor("testPnfCorrelationId");
66 assertNotNull(modifiedEntry.get());
67 assertThat(modifiedEntry.get().getPnfId()).isEqualTo("testtest");
68 assertThat(modifiedEntry.get().getPnfName()).isEqualTo("testPnfCorrelationId");
69 assertThat(modifiedEntry.get().getSwVersion()).isEqualTo("demo-1.2");
70 verify(pnfManagementTest, times(2)).getEntryFor(anyString());
73 private void setupPnf() {
76 pnf.setSwVersion("1");
77 pnf.setPnfId("testtest");
78 pnf.setPnfName("testPnfCorrelationId");
79 doReturn(Optional.of(pnf)).when(pnfManagementTest).getEntryFor(anyString());
80 } catch (IOException e) {
85 private void setupExecution() {
86 execution = mock(DelegateExecution.class);
87 given(execution.getVariable(eq(PNF_CORRELATION_ID))).willReturn("testPnfCorrelationId");
88 given(execution.getVariable(eq(PNF_UUID))).willReturn("testtest");
89 given(execution.getVariable(eq(PRC_TARGET_SOFTWARE_VERSION))).willReturn("demo-1.2");