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