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