bddfe5b180039fdacaa62e0adef046327ac6e631
[so.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.bpmn.infrastructure.pnf.delegate;
21
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;
41
42 @RunWith(SpringJUnit4ClassRunner.class)
43 public class UpdatePnfEntryInAaiTest {
44
45     @InjectMocks
46     private UpdatePnfEntryInAai updatePnfEntryInAai;
47
48     @Mock
49     private PnfManagement pnfManagementTest;
50
51     private DelegateExecution execution;
52
53
54
55     @Test
56     public void shouldSetSwVersion() throws Exception {
57         // given
58         setupPnf();
59         setupExecution();
60
61         // when
62         updatePnfEntryInAai.execute(execution);
63
64         // verify
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());
71     }
72
73     private void setupPnf() {
74         try {
75             Pnf pnf = new Pnf();
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) {
81             e.printStackTrace();
82         }
83     }
84
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");
90     }
91 }