2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.client.sdnc.mapper;
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;
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 import org.onap.sdnc.northbound.client.model.GenericResourceApiOnapmodelinformationOnapModelInformation;
44 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration;
45 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
46 import com.fasterxml.jackson.databind.ObjectMapper;
48 @RunWith(MockitoJUnitRunner.class)
49 public class ServiceTopologyOperationMapperTest {
52 private GeneralTopologyObjectMapper generalTopologyObjectMapper;
55 private ServiceTopologyOperationMapper mapper = new ServiceTopologyOperationMapper();
58 public void reqMapperTest() throws Exception {
59 // prepare and set service instance
60 ServiceInstance serviceInstance = new ServiceInstance();
61 ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance();
62 modelInfoServiceInstance.setModelInvariantUuid("modelInvariantUuid");
63 modelInfoServiceInstance.setModelName("modelName");
64 modelInfoServiceInstance.setModelUuid("modelUuid");
65 modelInfoServiceInstance.setModelVersion("modelVersion");
66 serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance);
68 // prepare Customer object
69 Customer customer = new Customer();
70 customer.setGlobalCustomerId("globalCustomerId");
72 customer.setServiceSubscription(new ServiceSubscription());
73 // set Customer on service instance
74 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
76 // prepare RequestContext
77 RequestContext requestContext = new RequestContext();
78 Map<String, Object> userParams = new HashMap<>();
79 userParams.put("key1", "value1");
80 requestContext.setUserParams(userParams);
81 requestContext.setProductFamilyId("productFamilyId");
82 requestContext.setMsoRequestId("MsoRequestId");
84 GenericResourceApiServiceOperationInformation serviceOpInformation =
85 mapper.reqMapper(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,
86 GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE, serviceInstance, customer,
88 GenericResourceApiServiceOperationInformation serviceOpInformationNullReqContext = mapper.reqMapper(
89 SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,
90 GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE, serviceInstance, customer, null);
92 String jsonToCompare = new String(Files.readAllBytes(
93 Paths.get("src/test/resources/__files/BuildingBlocks/genericResourceApiEcompModelInformation.json")));
95 ObjectMapper omapper = new ObjectMapper();
96 GenericResourceApiOnapmodelinformationOnapModelInformation reqMapper1 =
97 omapper.readValue(jsonToCompare, GenericResourceApiOnapmodelinformationOnapModelInformation.class);
99 assertThat(reqMapper1, sameBeanAs(serviceOpInformation.getServiceInformation().getOnapModelInformation()));
100 assertEquals("MsoRequestId", serviceOpInformation.getRequestInformation().getRequestId());
101 assertNotNull(serviceOpInformationNullReqContext.getRequestInformation().getRequestId());