2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2018 Nokia. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.vid.mso.rest;
23 import com.fasterxml.jackson.databind.ObjectMapper;
24 import org.json.JSONObject;
25 import org.junit.Assert;
26 import org.onap.portalsdk.core.util.SystemProperties;
27 import org.onap.vid.changeManagement.RequestDetails;
28 import org.onap.vid.client.SyncRestClient;
29 import org.onap.vid.controller.LocalWebConfig;
30 import org.onap.vid.mso.MsoBusinessLogic;
31 import org.onap.vid.mso.MsoBusinessLogicImpl;
32 import org.onap.vid.mso.model.CloudConfiguration;
33 import org.onap.vid.mso.model.ModelInfo;
34 import org.onap.vid.mso.model.RequestInfo;
35 import org.onap.vid.mso.model.RequestParameters;
36 import org.springframework.test.context.ContextConfiguration;
37 import org.springframework.test.context.web.WebAppConfiguration;
38 import org.testng.annotations.Test;
41 @ContextConfiguration(classes = {LocalWebConfig.class, SystemProperties.class})
43 public class MsoRestClientTest {
46 private MsoBusinessLogic msoBusinessLogic = new MsoBusinessLogicImpl(new MsoRestClientNew(new SyncRestClient(), ""), null);
47 private ObjectMapper om = new ObjectMapper();
50 public void createInPlaceMsoRequest() {
53 RequestDetails requestDetails = generateMockMsoRequest();
54 result = om.writeValueAsString(msoBusinessLogic.generateInPlaceMsoRequest(requestDetails));
55 } catch (Exception e) {
59 Assert.fail("Failed to create mso request");
61 JSONObject jsonObj = new JSONObject(result);
62 Assert.assertNotNull(jsonObj.getJSONObject("requestDetails"));
65 private RequestDetails generateMockMsoRequest() {
66 RequestDetails requestDetails = new RequestDetails();
67 requestDetails.setVnfInstanceId("vnf-instance-id");
68 requestDetails.setVnfName("vnf-name");
69 CloudConfiguration cloudConfiguration = new CloudConfiguration();
70 cloudConfiguration.setTenantId("tenant-id");
71 cloudConfiguration.setLcpCloudRegionId("lcp-region");
72 requestDetails.setCloudConfiguration(cloudConfiguration);
73 ModelInfo modelInfo = new ModelInfo();
74 modelInfo.setModelInvariantId("model-invarient-id");
75 modelInfo.setModelCustomizationName("modelCustomizationName");
76 requestDetails.setModelInfo(modelInfo);
77 RequestInfo requestInfo = new RequestInfo();
78 requestInfo.setRequestorId("ok883e");
79 requestInfo.setSource("VID");
80 requestDetails.setRequestInfo(requestInfo);
81 RequestParameters requestParameters = new RequestParameters();
82 requestParameters.setSubscriptionServiceType("subscriber-service-type");
83 requestParameters.setAdditionalProperty("a", 1);
84 requestParameters.setAdditionalProperty("b", 2);
85 requestParameters.setAdditionalProperty("c", 3);
86 requestParameters.setAdditionalProperty("d", 4);
87 String payload = "{\"existing_software_version\": \"3.1\",\"new_software_version\": \"3.2\", \"operations_timeout\": \"3600\"}";
88 requestParameters.setAdditionalProperty("payload", payload);
90 requestDetails.setRequestParameters(requestParameters);
91 return requestDetails;