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.bpmn.infrastructure.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.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;
50 @RunWith(MockitoJUnitRunner.class)
51 public class ServiceTopologyOperationMapperTest {
54 private GeneralTopologyObjectMapper generalTopologyObjectMapper;
57 private ServiceTopologyOperationMapper mapper = new ServiceTopologyOperationMapper();
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);
70 // prepare Customer object
71 Customer customer = new Customer();
72 customer.setGlobalCustomerId("globalCustomerId");
74 customer.setServiceSubscription(new ServiceSubscription());
75 // set Customer on service instance
76 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
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");
86 GenericResourceApiServiceOperationInformation serviceOpInformation =
87 mapper.reqMapper(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,
88 GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE, serviceInstance, customer,
90 GenericResourceApiServiceOperationInformation serviceOpInformationNullReqContext = mapper.reqMapper(
91 SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,
92 GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE, serviceInstance, customer, null);
94 String jsonToCompare = new String(Files.readAllBytes(
95 Paths.get("src/test/resources/__files/BuildingBlocks/genericResourceApiEcompModelInformation.json")));
97 ObjectMapper omapper = new ObjectMapper();
98 GenericResourceApiOnapmodelinformationOnapModelInformation reqMapper1 =
99 omapper.readValue(jsonToCompare, GenericResourceApiOnapmodelinformationOnapModelInformation.class);
101 assertThat(reqMapper1, sameBeanAs(serviceOpInformation.getServiceInformation().getOnapModelInformation()));
102 assertEquals("MsoRequestId", serviceOpInformation.getRequestInformation().getRequestId());
103 assertNotNull(serviceOpInformationNullReqContext.getRequestInformation().getRequestId());