Move the VNFM Simulator into CSIT
[integration/csit.git] / plans / so / integration-etsi-testing / so-simulators / vnfm-simulator / vnfm-service / src / test / java / org / onap / so / svnfm / simulator / services / VnfmHelperTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2019 Nokia.
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.so.svnfm.simulator.services;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.when;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.CreateVnfRequest;
29 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201;
30 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201.InstantiationStateEnum;
31 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201LinksSelf;
32 import org.onap.so.svnfm.simulator.config.ApplicationConfig;
33 import org.onap.so.svnfm.simulator.constants.Constant;
34 import org.onap.so.svnfm.simulator.model.VnfInstance;
35
36 public class VnfmHelperTest {
37
38     private static final String VNF_INSTANCE_ID = "vnfInstanceTestId";
39     private static final String VNFD_ID = "vnfdTestId";
40     private static final String VNF_INSTANCE_NAME = "vnfInsNameTest";
41     private static final String VNF_INSTANCE_DESCRIPTION = "vnfInstTestDescr";
42     private static final String APPLICATION_CONFIG_BASE_URL = "appConfUrl";
43     private VnfmHelper testedObject;
44     private ApplicationConfig applicationConfigMock;
45
46     @Before
47     public void setup() {
48         applicationConfigMock = mock(ApplicationConfig.class);
49         testedObject = new VnfmHelper(applicationConfigMock);
50     }
51
52     @Test
53     public void createVnfInstance() {
54         // when
55         VnfInstance result = testedObject.createVnfInstance(createVnfRequest(), VNF_INSTANCE_ID);
56         // then
57         assertThat(result.getId()).isEqualTo(VNF_INSTANCE_ID);
58         assertThat(result.getVnfdId()).isEqualTo(VNFD_ID);
59         assertThat(result.getVnfInstanceName()).isEqualTo(VNF_INSTANCE_NAME);
60         assertThat(result.getVnfInstanceDescription()).isEqualTo(VNF_INSTANCE_DESCRIPTION);
61         assertThat(result.getVnfProvider()).isEqualTo(Constant.VNF_PROVIDER);
62         assertThat(result.getVnfProductName()).isEqualTo(Constant.VNF_PROVIDER_NAME);
63     }
64
65     @Test
66     public void getInlineResponse201() throws Exception {
67         // given
68         when(applicationConfigMock.getBaseUrl()).thenReturn(APPLICATION_CONFIG_BASE_URL);
69         // when
70         InlineResponse201 result = testedObject.getInlineResponse201(prepareVnfInstance());
71         // then
72         assertThat(result.getVnfdVersion()).isEqualTo(Constant.VNFD_VERSION);
73         assertThat(result.getVnfSoftwareVersion()).isEqualTo(Constant.VNF_SOFTWARE_VERSION);
74         assertThat(result.getInstantiationState()).isEqualByComparingTo(InstantiationStateEnum.NOT_INSTANTIATED);
75         verifyAdditionalPropertyInlineResponse201(result);
76     }
77
78     private CreateVnfRequest createVnfRequest() {
79         CreateVnfRequest createVnfRequest = new CreateVnfRequest();
80         createVnfRequest.setVnfdId(VNFD_ID);
81         createVnfRequest.setVnfInstanceName(VNF_INSTANCE_NAME);
82         createVnfRequest.setVnfInstanceDescription(VNF_INSTANCE_DESCRIPTION);
83         return createVnfRequest;
84     }
85
86     private VnfInstance prepareVnfInstance() {
87         VnfInstance vnfInstance = new VnfInstance();
88         vnfInstance.setId(VNF_INSTANCE_ID);
89         return vnfInstance;
90     }
91
92     private void verifyAdditionalPropertyInlineResponse201(InlineResponse201 result) {
93         InlineResponse201LinksSelf expectedVnfInstancesLinksSelf = new InlineResponse201LinksSelf();
94         expectedVnfInstancesLinksSelf
95                 .setHref(APPLICATION_CONFIG_BASE_URL + "/vnflcm/v1/vnf_instances/" + VNF_INSTANCE_ID);
96         assertThat(result.getLinks().getSelf()).isEqualTo(expectedVnfInstancesLinksSelf);
97
98         InlineResponse201LinksSelf expectedVnfInstancesLinksSelfInstantiate = new InlineResponse201LinksSelf();
99         expectedVnfInstancesLinksSelfInstantiate.setHref(
100                 (APPLICATION_CONFIG_BASE_URL + "/vnflcm/v1/vnf_instances/" + VNF_INSTANCE_ID + "/instantiate"));
101         assertThat(result.getLinks().getInstantiate()).isEqualTo(expectedVnfInstancesLinksSelfInstantiate);
102     }
103
104 }