2b067b287a9b20da803f643a436f68ee77a7d12f
[vid.git] / vid-app-common / src / test / java / org / onap / vid / mso / rest / MsoRestClientTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21 package org.onap.vid.mso.rest;
22
23 import com.fasterxml.jackson.databind.ObjectMapper;
24 import org.json.JSONObject;
25 import org.junit.Assert;
26 import org.onap.vid.changeManagement.RequestDetails;
27 import org.onap.vid.client.SyncRestClient;
28 import org.onap.vid.domain.mso.CloudConfiguration;
29 import org.onap.vid.domain.mso.ModelInfo;
30 import org.onap.vid.domain.mso.RequestInfo;
31 import org.onap.vid.domain.mso.RequestParameters;
32 import org.onap.vid.mso.MsoBusinessLogic;
33 import org.onap.vid.mso.MsoBusinessLogicImpl;
34 import org.onap.vid.mso.rest.MsoRestClientNew;
35 import org.onap.vid.controllers.LocalWebConfig;
36 import org.onap.portalsdk.core.util.SystemProperties;
37 import org.springframework.test.context.ContextConfiguration;
38 import org.springframework.test.context.web.WebAppConfiguration;
39 import org.testng.annotations.Test;
40 import org.togglz.core.manager.FeatureManager;
41
42
43 @ContextConfiguration(classes = {LocalWebConfig.class, SystemProperties.class})
44 @WebAppConfiguration
45 public class MsoRestClientTest {
46
47
48     private MsoBusinessLogic msoBusinessLogic = new MsoBusinessLogicImpl(new MsoRestClientNew(new SyncRestClient(), ""), null);
49     private ObjectMapper om = new ObjectMapper();
50
51     @Test
52     public void createInPlaceMsoRequest() {
53         String result = null;
54         try {
55             RequestDetails requestDetails = generateMockMsoRequest();
56             result = om.writeValueAsString(msoBusinessLogic.generateInPlaceMsoRequest(requestDetails));
57         } catch (Exception e) {
58             e.printStackTrace();
59         }
60         if (result == null) {
61             Assert.fail("Failed to create mso request");
62         }
63         JSONObject jsonObj = new JSONObject(result);
64         Assert.assertNotNull(jsonObj.getJSONObject("requestDetails"));
65     }
66
67     private RequestDetails generateMockMsoRequest() {
68         RequestDetails requestDetails = new RequestDetails();
69         requestDetails.setVnfInstanceId("vnf-instance-id");
70         requestDetails.setVnfName("vnf-name");
71         CloudConfiguration cloudConfiguration = new CloudConfiguration();
72         cloudConfiguration.setTenantId("tenant-id");
73         cloudConfiguration.setLcpCloudRegionId("lcp-region");
74         requestDetails.setCloudConfiguration(cloudConfiguration);
75         ModelInfo modelInfo = new ModelInfo();
76         modelInfo.setModelInvariantId("model-invarient-id");
77         modelInfo.setModelCustomizationName("modelCustomizationName");
78         requestDetails.setModelInfo(modelInfo);
79         RequestInfo requestInfo = new RequestInfo();
80         requestInfo.setRequestorId("ok883e");
81         requestInfo.setSource("VID");
82         requestDetails.setRequestInfo(requestInfo);
83         RequestParameters requestParameters = new RequestParameters();
84         requestParameters.setSubscriptionServiceType("subscriber-service-type");
85         requestParameters.setAdditionalProperty("a", 1);
86         requestParameters.setAdditionalProperty("b", 2);
87         requestParameters.setAdditionalProperty("c", 3);
88         requestParameters.setAdditionalProperty("d", 4);
89         String payload = "{\"existing_software_version\": \"3.1\",\"new_software_version\": \"3.2\", \"operations_timeout\": \"3600\"}";
90         requestParameters.setAdditionalProperty("payload", payload);
91
92         requestDetails.setRequestParameters(requestParameters);
93         return requestDetails;
94     }
95 }