Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 1 | /*-
|
| 2 | * ============LICENSE_START=======================================================
|
| 3 | * OSAM
|
| 4 | * ================================================================================
|
| 5 | * Copyright (C) 2018 AT&T
|
| 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 |
|
| 22 | package org.onap.osam.mso.rest;
|
| 23 |
|
| 24 | import com.fasterxml.jackson.databind.ObjectMapper;
|
| 25 | import org.json.JSONObject;
|
| 26 | import org.junit.Assert;
|
| 27 | import org.onap.osam.client.SyncRestClient;
|
| 28 | import org.onap.osam.domain.mso.CloudConfiguration;
|
| 29 | import org.onap.osam.domain.mso.ModelInfo;
|
| 30 | import org.onap.osam.domain.mso.RequestInfo;
|
| 31 | import org.onap.osam.domain.mso.RequestParameters;
|
| 32 | import org.onap.osam.mso.MsoBusinessLogic;
|
| 33 | import org.onap.osam.mso.MsoBusinessLogicImpl;
|
| 34 | import org.onap.osam.controllers.LocalWebConfig;
|
| 35 | import org.onap.portalsdk.core.util.SystemProperties;
|
| 36 | import org.springframework.test.context.ContextConfiguration;
|
| 37 | import org.springframework.test.context.web.WebAppConfiguration;
|
| 38 | import org.testng.annotations.Test;
|
| 39 |
|
| 40 |
|
| 41 | @ContextConfiguration(classes = {LocalWebConfig.class, SystemProperties.class})
|
| 42 | @WebAppConfiguration
|
| 43 | public class MsoRestClientTest {
|
| 44 |
|
| 45 |
|
| 46 | private MsoBusinessLogic msoBusinessLogic = new MsoBusinessLogicImpl(new MsoRestClientNew(new SyncRestClient(), ""), null);
|
| 47 | private ObjectMapper om = new ObjectMapper();
|
| 48 |
|
| 49 | @Test
|
| 50 | public void createInPlaceMsoRequest() {
|
| 51 | String result = null;
|
| 52 | try {
|
| 53 | RequestDetails requestDetails = generateMockMsoRequest();
|
| 54 | result = om.writeValueAsString(msoBusinessLogic.generateInPlaceMsoRequest(requestDetails));
|
| 55 | } catch (Exception e) {
|
| 56 | e.printStackTrace();
|
| 57 | }
|
| 58 | if (result == null) {
|
| 59 | Assert.fail("Failed to create mso request");
|
| 60 | }
|
| 61 | JSONObject jsonObj = new JSONObject(result);
|
| 62 | Assert.assertNotNull(jsonObj.getJSONObject("requestDetails"));
|
| 63 | }
|
| 64 |
|
| 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);
|
| 89 |
|
| 90 | requestDetails.setRequestParameters(requestParameters);
|
| 91 | return requestDetails;
|
| 92 | }
|
| 93 | }
|