Merge "Correct logging for DeactivateSDNCNetwork"
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / client / sdnc / mapper / GeneralTopologyObjectMapperTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
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.client.sdnc.mapper;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
26
27 import java.util.HashMap;
28
29 import org.junit.After;
30 import org.junit.Before;
31 import org.junit.Rule;
32 import org.junit.Test;
33 import org.junit.rules.ExpectedException;
34 import org.mockito.InjectMocks;
35 import org.onap.so.bpmn.common.data.TestDataSetup;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription;
41 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
42 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoConfiguration;
43 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
44 import org.onap.so.client.sdnc.beans.SDNCSvcAction;
45
46 import org.onap.sdnc.northbound.client.model.GenericResourceApiConfigurationinformationConfigurationInformation;
47 import org.onap.sdnc.northbound.client.model.GenericResourceApiGcrequestinputGcRequestInput;
48 import org.onap.sdnc.northbound.client.model.GenericResourceApiParam;
49 import org.onap.sdnc.northbound.client.model.GenericResourceApiParamParam;
50 import org.onap.sdnc.northbound.client.model.GenericResourceApiSdncrequestheaderSdncRequestHeader;
51 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceinformationServiceInformation;
52 import org.onap.sdnc.northbound.client.model.GenericResourceApiSvcActionEnumeration;
53 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfinformationVnfInformation;
54
55
56 public class GeneralTopologyObjectMapperTest  extends TestDataSetup{
57         @InjectMocks
58         private GeneralTopologyObjectMapper genObjMapper = new GeneralTopologyObjectMapper();
59
60         @Rule
61         public ExpectedException expectedException = ExpectedException.none();
62
63         @Before
64         public void before() {
65
66         }
67
68         @After
69         public void after() {
70
71         }
72
73         @Test
74         public void testBuildServiceInformation() {
75                 // prepare and set service instance
76                 ServiceInstance serviceInstance = new ServiceInstance();
77                 serviceInstance.setServiceInstanceId("serviceInstanceId");
78                 ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance();
79                 modelInfoServiceInstance.setModelInvariantUuid("serviceModelInvariantUuid");
80                 modelInfoServiceInstance.setModelName("serviceModelName");
81                 modelInfoServiceInstance.setModelUuid("serviceModelUuid");
82                 modelInfoServiceInstance.setModelVersion("serviceModelVersion");
83
84                 serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance);
85                 // prepare Customer object
86                 Customer customer = new Customer();
87                 customer.setGlobalCustomerId("globalCustomerId");
88                 ServiceSubscription serviceSubscription = new ServiceSubscription();
89                 serviceSubscription.setServiceType("productFamilyId");
90                 customer.setServiceSubscription(serviceSubscription);
91                 // set Customer on service instance
92                 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
93                 //
94                 RequestContext requestContext = new RequestContext();
95                 HashMap<String, String> userParams = new HashMap<String, String>();
96                 userParams.put("key1", "value1");
97                 requestContext.setUserParams(userParams);
98                 requestContext.setProductFamilyId("productFamilyId");
99
100                 GenericResourceApiServiceinformationServiceInformation serviceInfo = genObjMapper.buildServiceInformation(serviceInstance, requestContext, customer, true);
101
102                 assertEquals("serviceModelInvariantUuid", serviceInfo.getOnapModelInformation().getModelInvariantUuid());
103                 assertEquals("serviceModelName", serviceInfo.getOnapModelInformation().getModelName());
104                 assertEquals("serviceModelUuid", serviceInfo.getOnapModelInformation().getModelUuid());
105                 assertEquals("serviceModelVersion", serviceInfo.getOnapModelInformation().getModelVersion());
106                 assertNull(serviceInfo.getOnapModelInformation().getModelCustomizationUuid());
107                 assertEquals("serviceInstanceId", serviceInfo.getServiceInstanceId());
108                 assertEquals("serviceInstanceId", serviceInfo.getServiceId());
109                 assertEquals("globalCustomerId", serviceInfo.getGlobalCustomerId());
110                 assertEquals("productFamilyId", serviceInfo.getSubscriptionServiceType());
111         }
112
113         @Test
114         public void buildSdncRequestHeaderActivateTest() {
115                 GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = genObjMapper.buildSdncRequestHeader(SDNCSvcAction.ACTIVATE, "sdncReqId");
116
117                 assertEquals(GenericResourceApiSvcActionEnumeration.ACTIVATE, requestHeader.getSvcAction());
118                 assertEquals("sdncReqId", requestHeader.getSvcRequestId());
119         }
120
121         @Test
122         public void buildSdncRequestHeaderAssignTest() {
123                 GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = genObjMapper.buildSdncRequestHeader(SDNCSvcAction.ASSIGN, "sdncReqId");
124
125                 assertEquals(GenericResourceApiSvcActionEnumeration.ASSIGN, requestHeader.getSvcAction());
126                 assertEquals("sdncReqId", requestHeader.getSvcRequestId());
127         }
128
129         @Test
130         public void buildSdncRequestHeaderDeactivateTest() {
131                 GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = genObjMapper.buildSdncRequestHeader(SDNCSvcAction.DEACTIVATE, "sdncReqId");
132
133                 assertEquals(GenericResourceApiSvcActionEnumeration.DEACTIVATE, requestHeader.getSvcAction());
134                 assertEquals("sdncReqId", requestHeader.getSvcRequestId());
135         }
136
137         @Test
138         public void buildSdncRequestHeaderDeleteTest() {
139                 GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = genObjMapper.buildSdncRequestHeader(SDNCSvcAction.DELETE, "sdncReqId");
140
141                 assertEquals(GenericResourceApiSvcActionEnumeration.DELETE, requestHeader.getSvcAction());
142                 assertEquals("sdncReqId", requestHeader.getSvcRequestId());
143         }
144
145         @Test
146         public void buildSdncRequestHeaderChangeAssignTest() {
147                 GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = genObjMapper.buildSdncRequestHeader(SDNCSvcAction.CHANGE_ASSIGN, "sdncReqId");
148
149                 assertEquals(GenericResourceApiSvcActionEnumeration.CHANGEASSIGN, requestHeader.getSvcAction());
150                 assertEquals("sdncReqId", requestHeader.getSvcRequestId());
151         }
152
153         @Test
154         public void buildConfigurationInformationTest_excludesOnapModelInfo() {
155                 Configuration configuration = new Configuration();
156                 configuration.setConfigurationId("testConfigurationId");
157                 configuration.setConfigurationType("VNR");
158                 configuration.setConfigurationName("VNRCONF");
159                 GenericResourceApiConfigurationinformationConfigurationInformation configurationInformation =genObjMapper.buildConfigurationInformation(configuration,false);
160                 assertEquals(configuration.getConfigurationId(),configurationInformation.getConfigurationId());
161                 assertEquals(configuration.getConfigurationType(),configurationInformation.getConfigurationType());
162                 assertEquals(configuration.getConfigurationName(),configurationInformation.getConfigurationName());
163                 assertNull(configurationInformation.getOnapModelInformation());
164         }
165
166         @Test
167         public void buildConfigurationInformationTest_includesOnapModelInfo() {
168                 Configuration configuration = new Configuration();
169                 configuration.setConfigurationId("testConfigurationId");
170                 configuration.setConfigurationType("VNR");
171                 configuration.setConfigurationName("VNRCONF");
172                 ModelInfoConfiguration modelInfoConfiguration = new ModelInfoConfiguration();
173                 modelInfoConfiguration.setModelVersionId("modelVersionId");
174                 modelInfoConfiguration.setModelInvariantId("modelInvariantId");
175                 modelInfoConfiguration.setModelCustomizationId("modelCustomizationId");
176                 configuration.setModelInfoConfiguration(modelInfoConfiguration);
177
178                 GenericResourceApiConfigurationinformationConfigurationInformation configurationInformation = genObjMapper.buildConfigurationInformation(configuration,true);
179
180                 assertEquals(configuration.getConfigurationId(),configurationInformation.getConfigurationId());
181                 assertEquals(configuration.getConfigurationType(),configurationInformation.getConfigurationType());
182                 assertEquals(configuration.getConfigurationName(),configurationInformation.getConfigurationName());
183                 assertNotNull(configurationInformation.getOnapModelInformation());
184                 assertEquals(configuration.getModelInfoConfiguration().getModelVersionId(),configurationInformation.getOnapModelInformation().getModelUuid());
185                 assertEquals(configuration.getModelInfoConfiguration().getModelInvariantId(),configurationInformation.getOnapModelInformation().getModelInvariantUuid());
186                 assertEquals(configuration.getModelInfoConfiguration().getModelCustomizationId(),configurationInformation.getOnapModelInformation().getModelCustomizationUuid());
187
188         }
189
190         @Test
191         public void buildGcRequestInformationTest() {
192                 GenericVnf vnf = new GenericVnf();
193                 vnf.setVnfId("TestVnfId");
194                 GenericResourceApiGcrequestinputGcRequestInput gcRequestInput = genObjMapper.buildGcRequestInformation(vnf,null);
195                 assertNotNull(gcRequestInput);
196                 assertEquals(vnf.getVnfId(),gcRequestInput.getVnfId());
197                 assertNull(gcRequestInput.getInputParameters());
198         }
199
200         @Test
201         public void buildGcRequestInformationTest_withInputParams() {
202                 GenericVnf vnf = new GenericVnf();
203                 vnf.setVnfId("TestVnfId");
204                 GenericResourceApiParam  genericResourceApiParam =new GenericResourceApiParam();
205                 genericResourceApiParam.addParamItem(new GenericResourceApiParamParam());
206                 GenericResourceApiGcrequestinputGcRequestInput gcRequestInput = genObjMapper.buildGcRequestInformation(vnf,genericResourceApiParam);
207                 assertNotNull(gcRequestInput);
208                 assertEquals(vnf.getVnfId(),gcRequestInput.getVnfId());
209                 assertNotNull(gcRequestInput.getInputParameters());
210         }
211         
212         @Test
213         public void buildVnfInformationTest_withNullData() {
214                 GenericVnf vnf = new GenericVnf();
215                 vnf.setVnfId("TestVnfId");
216                 ServiceInstance serviceInstance = new ServiceInstance();
217                 serviceInstance.setServiceInstanceId("serviceInstanceId");
218                 GenericResourceApiVnfinformationVnfInformation gcRequestInput = genObjMapper.buildVnfInformation(vnf,serviceInstance,true);
219                 assertNotNull(gcRequestInput);
220                 assertNull(vnf.getModelInfoGenericVnf());
221                 assertNull(gcRequestInput.getOnapModelInformation());
222                 assertEquals(vnf.getVnfId(),gcRequestInput.getVnfId());
223                 assertNotNull(gcRequestInput.getVnfId());
224         }
225 }