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