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