1919ef437b523707c0463e8bbc5998f6fc50fc45
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / client / sdnc / mapper / ServiceTopologyOperationMapperTest.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 com.shazam.shazamcrest.MatcherAssert.assertThat;
24 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotNull;
27
28 import java.nio.file.Files;
29 import java.nio.file.Paths;
30 import java.util.HashMap;
31 import java.util.Map;
32
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.mockito.InjectMocks;
36 import org.mockito.Spy;
37 import org.mockito.junit.MockitoJUnitRunner;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
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.ModelInfoServiceInstance;
43 import org.onap.so.client.sdnc.beans.SDNCSvcAction;
44 import org.onap.so.client.sdnc.beans.SDNCSvcOperation;
45
46 import org.onap.sdnc.northbound.client.model.GenericResourceApiOnapmodelinformationOnapModelInformation;
47 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration;
48 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
49 import com.fasterxml.jackson.databind.ObjectMapper;
50
51 @RunWith(MockitoJUnitRunner.class)
52 public class ServiceTopologyOperationMapperTest {
53
54         @Spy
55         private GeneralTopologyObjectMapper generalTopologyObjectMapper;
56         
57         @InjectMocks
58         private ServiceTopologyOperationMapper mapper = new ServiceTopologyOperationMapper();
59
60         @Test
61         public void reqMapperTest() throws Exception {
62                 // prepare and set service instance
63                 ServiceInstance serviceInstance = new ServiceInstance();
64                 ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance();
65                 modelInfoServiceInstance.setModelInvariantUuid("modelInvariantUuid");
66                 modelInfoServiceInstance.setModelName("modelName");
67                 modelInfoServiceInstance.setModelUuid("modelUuid");
68                 modelInfoServiceInstance.setModelVersion("modelVersion");
69                 serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance);
70
71                 // prepare Customer object
72                 Customer customer = new Customer();
73                 customer.setGlobalCustomerId("globalCustomerId");
74
75                 customer.setServiceSubscription(new ServiceSubscription());
76                 // set Customer on service instance
77                 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
78
79                 //prepare RequestContext
80                 RequestContext requestContext = new RequestContext();
81                 Map<String, Object> userParams = new HashMap<>();
82                 userParams.put("key1", "value1");
83                 requestContext.setUserParams(userParams);
84                 requestContext.setProductFamilyId("productFamilyId");
85                 requestContext.setMsoRequestId("MsoRequestId");
86
87                 GenericResourceApiServiceOperationInformation serviceOpInformation = mapper.reqMapper(
88                                 SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE, serviceInstance, customer,
89                                 requestContext);
90                 GenericResourceApiServiceOperationInformation serviceOpInformationNullReqContext = mapper.reqMapper(
91                                 SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE, serviceInstance, customer,
92                                 null);
93
94                 String jsonToCompare = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/BuildingBlocks/genericResourceApiEcompModelInformation.json")));
95
96                 ObjectMapper omapper = new ObjectMapper();
97                 GenericResourceApiOnapmodelinformationOnapModelInformation reqMapper1 = omapper.readValue(jsonToCompare,
98                                 GenericResourceApiOnapmodelinformationOnapModelInformation.class);
99
100                 assertThat(reqMapper1, sameBeanAs(serviceOpInformation.getServiceInformation().getOnapModelInformation()));
101                 assertEquals("MsoRequestId", serviceOpInformation.getRequestInformation().getRequestId());
102                 assertNotNull(serviceOpInformationNullReqContext.getRequestInformation().getRequestId());
103         }
104 }