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 |
|
| 23 | package org.onap.osam.controllers;
|
| 24 |
|
| 25 | import org.apache.commons.lang.StringEscapeUtils;
|
| 26 | import org.onap.portalsdk.core.util.SystemProperties;
|
| 27 | import org.onap.osam.domain.mso.RequestInfo;
|
| 28 | import org.onap.osam.factories.MsoRequestFactory;
|
| 29 | import org.onap.osam.mso.rest.Request;
|
| 30 | import org.onap.osam.mso.rest.RequestDetails;
|
| 31 | import org.onap.osam.mso.rest.Task;
|
| 32 | import org.springframework.beans.factory.annotation.Autowired;
|
| 33 | import org.springframework.http.ResponseEntity;
|
| 34 | import org.springframework.test.context.ContextConfiguration;
|
| 35 | import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
|
| 36 | import org.springframework.test.context.web.WebAppConfiguration;
|
| 37 | import org.testng.Assert;
|
| 38 | import org.testng.annotations.Test;
|
| 39 |
|
| 40 | import java.util.List;
|
| 41 |
|
| 42 |
|
| 43 | @WebAppConfiguration
|
| 44 | @ContextConfiguration(classes = {SystemProperties.class, MsoConfig.class})
|
| 45 | public class MsoControllerTest extends AbstractTestNGSpringContextTests {
|
| 46 |
|
| 47 | @Autowired
|
| 48 | MsoRequestFactory msoRequestFactory;
|
| 49 |
|
| 50 | @Test(enabled = false)
|
| 51 | public void testInstanceCreationNew() throws Exception {
|
| 52 |
|
| 53 | RequestDetails requestDetails = msoRequestFactory.createMsoRequest("msoRequest.json");
|
| 54 | MsoController msoController = new MsoController(null);
|
| 55 | //TODO: make ths test to really test something
|
| 56 | //ResponseEntity<String> responseEntityNew = msoController.createSvcInstanceNew(null, requestDetails);
|
| 57 | ResponseEntity<String> responseEntity = msoController.createSvcInstance(null, requestDetails);
|
| 58 | //Assert.assertEquals(responseEntityNew, responseEntity);
|
| 59 |
|
| 60 | }
|
| 61 |
|
| 62 | @Test(enabled = false)
|
| 63 | public void testInstanceCreationLocalWithRest() throws Exception {
|
| 64 |
|
| 65 | RequestDetails requestDetails = msoRequestFactory.createMsoRequest("msoRequest.json");
|
| 66 | MsoController msoController = new MsoController(null);
|
| 67 | ResponseEntity<String> responseEntityNew = msoController.createSvcInstance(null, requestDetails);
|
| 68 | //TODO: make ths test to really test something
|
| 69 | // ResponseEntity<String> responseEntityRest = msoController.createSvcInstanceNewRest(null, requestDetails);
|
| 70 | //
|
| 71 | // Assert.assertEquals(responseEntityNew.getBody(), responseEntityRest.getBody());
|
| 72 |
|
| 73 | }
|
| 74 |
|
| 75 | @Test(enabled = false)
|
| 76 | public void testInstanceCreation() throws Exception {
|
| 77 |
|
| 78 | RequestDetails requestDetails = msoRequestFactory.createMsoRequest("msoRequest.json");
|
| 79 | MsoController msoController = new MsoController(null);
|
| 80 | ResponseEntity<String> responseEntity = msoController.createSvcInstance(null, requestDetails);
|
| 81 |
|
| 82 |
|
| 83 | Assert.assertEquals(responseEntity.getBody(), "{ \"status\": 200, \"entity\": {\n" +
|
| 84 | " \"requestReferences\": {\n" +
|
| 85 | " \"instanceId\": \"ba00de9b-3c3e-4b0a-a1ad-0c5489e711fb\",\n" +
|
| 86 | " \"requestId\": \"311cc766-b673-4a50-b9c5-471f68914586\"\n" +
|
| 87 | " }\n" +
|
| 88 | "}}");
|
| 89 |
|
| 90 | }
|
| 91 |
|
| 92 | @Test(enabled = false)
|
| 93 | public void testGetOrchestrationRequestsForDashboard() throws Exception {
|
| 94 | MsoController msoController = new MsoController(null);
|
| 95 | List<Request> orchestrationRequestsForDashboard = msoController.getOrchestrationRequestsForDashboard();
|
| 96 |
|
| 97 | Assert.assertEquals(orchestrationRequestsForDashboard.size(), 2);
|
| 98 | }
|
| 99 |
|
| 100 | @Test(enabled = false)
|
| 101 | public void testGetManualTasksByRequestId() throws Exception {
|
| 102 | MsoController msoController = new MsoController(null);
|
| 103 | List<Task> orchestrationRequestsForDashboard = msoController.getManualTasksByRequestId("za1234d1-5a33-55df-13ab-12abad84e335");
|
| 104 |
|
| 105 | Assert. assertEquals(orchestrationRequestsForDashboard.get(0).getTaskId(), "daf4dd84-b77a-42da-a051-3239b7a9392c");
|
| 106 | }
|
| 107 |
|
| 108 |
|
| 109 | public void testCompleteManualTask() throws Exception { // TODO not done yet
|
| 110 | RequestInfo requestInfo = new RequestInfo();
|
| 111 | requestInfo.setResponseValue("rollback");
|
| 112 | requestInfo.setRequestorId("abc");
|
| 113 | requestInfo.setSource("VID");
|
| 114 | RequestDetails requestDetails = new RequestDetails();
|
| 115 | requestDetails.setRequestInfo(requestInfo);
|
| 116 | MsoController msoController = new MsoController(null);
|
| 117 | ResponseEntity<String> responseEntity = msoController.manualTaskComplete("daf4dd84-b77a-42da-a051-3239b7a9392c", requestDetails);
|
| 118 | String assertString = "{ \\\"status\\\": 200, \\\"entity\\\": {\\n\" +\n" +
|
| 119 | " \" \\\"taskRequestReference\\\": {\\n\" +\n" +
|
| 120 | " \" \\\"taskId\\\": \\\"daf4dd84-b77a-42da-a051-3239b7a9392c\\\"\\n\" +\n" +
|
| 121 | " \" }\\n\" +\n" +
|
| 122 | " \"}\\n\" +\n" +
|
| 123 | " \"}";
|
| 124 | Assert.assertEquals(responseEntity.getBody(), StringEscapeUtils.unescapeJava(assertString));
|
| 125 | }
|
| 126 |
|
| 127 |
|
| 128 | }
|