Move mock configurations to test area
[portal/ric-dashboard.git] / webapp-backend / src / test / java / org / oransc / ric / portal / dashboard / controller / AppManagerControllerTest.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 AT&T Intellectual Property and Nokia
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 package org.oransc.ric.portal.dashboard.controller;
21
22 import java.lang.invoke.MethodHandles;
23 import java.net.URI;
24
25 import org.junit.jupiter.api.Assertions;
26 import org.junit.jupiter.api.Test;
27 import org.oransc.ric.plt.appmgr.client.model.AllDeployedXapps;
28 import org.oransc.ric.plt.appmgr.client.model.AllXappConfig;
29 import org.oransc.ric.plt.appmgr.client.model.ConfigMetadata;
30 import org.oransc.ric.plt.appmgr.client.model.XAppConfig;
31 import org.oransc.ric.plt.appmgr.client.model.XAppInfo;
32 import org.oransc.ric.plt.appmgr.client.model.Xapp;
33 import org.oransc.ric.portal.dashboard.model.DashboardDeployableXapps;
34 import org.oransc.ric.portal.dashboard.model.SuccessTransport;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.springframework.http.HttpEntity;
38 import org.springframework.http.HttpMethod;
39 import org.springframework.http.ResponseEntity;
40
41 public class AppManagerControllerTest extends AbstractControllerTest {
42
43         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
44
45         @Test
46         public void versionTest() {
47                 URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.VERSION_METHOD);
48                 logger.info("Invoking {}", uri);
49                 SuccessTransport st = restTemplate.getForObject(uri, SuccessTransport.class);
50                 Assertions.assertFalse(st.getData().toString().isEmpty());
51         }
52
53         @Test
54         public void healthAliveTest() {
55                 URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.HEALTH_ALIVE_METHOD);
56                 logger.info("Invoking {}", uri);
57                 ResponseEntity<Void> voidResponse = restTemplate.getForEntity(uri, Void.class);
58                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
59         }
60
61         @Test
62         public void healthReadyTest() {
63                 URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.HEALTH_READY_METHOD);
64                 logger.info("Invoking {}", uri);
65                 ResponseEntity<Void> voidResponse = restTemplate.getForEntity(uri, Void.class);
66                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
67         }
68
69         @Test
70         public void appListTest() {
71                 URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.XAPPS_LIST_METHOD);
72                 logger.info("Invoking {}", uri);
73                 DashboardDeployableXapps apps = testRestTemplateStandardRole().getForObject(uri,
74                                 DashboardDeployableXapps.class);
75                 Assertions.assertFalse(apps.isEmpty());
76         }
77
78         @Test
79         public void appStatusesTest() {
80                 URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.XAPPS_METHOD);
81                 logger.info("Invoking {}", uri);
82                 AllDeployedXapps apps = testRestTemplateStandardRole().getForObject(uri, AllDeployedXapps.class);
83                 Assertions.assertFalse(apps.isEmpty());
84         }
85
86         @Test
87         public void appStatusTest() {
88                 URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.XAPPS_METHOD, "app");
89                 logger.info("Invoking {}", uri);
90                 Xapp app = testRestTemplateStandardRole().getForObject(uri, Xapp.class);
91                 Assertions.assertFalse(app.getName().isEmpty());
92         }
93
94         @Test
95         public void deployAppTest() {
96                 URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.XAPPS_METHOD);
97                 logger.info("Invoking {}", uri);
98                 XAppInfo info = new XAppInfo();
99                 Xapp app = testRestTemplateAdminRole().postForObject(uri, info, Xapp.class);
100                 Assertions.assertFalse(app.getName().isEmpty());
101         }
102
103         @Test
104         public void undeployAppTest() {
105                 URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.XAPPS_METHOD, "app");
106                 logger.info("Invoking {}", uri);
107                 ResponseEntity<Void> voidResponse = testRestTemplateAdminRole().exchange(uri, HttpMethod.DELETE, null,
108                                 Void.class);
109                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
110         }
111
112         @Test
113         public void getConfigTest() {
114                 URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.CONFIG_METHOD);
115                 logger.info("Invoking {}", uri);
116                 AllXappConfig config = testRestTemplateStandardRole().getForObject(uri, AllXappConfig.class);
117                 Assertions.assertFalse(config.isEmpty());
118         }
119
120         @Test
121         public void createConfigTest() {
122                 URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.CONFIG_METHOD);
123                 logger.info("Invoking {}", uri);
124                 XAppConfig newConfig = new XAppConfig();
125                 XAppConfig response = testRestTemplateAdminRole().postForObject(uri, newConfig, XAppConfig.class);
126                 Assertions.assertNotNull(response.getConfig());
127         }
128
129         @Test
130         public void deleteConfigTest() {
131                 URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.CONFIG_METHOD, "app");
132                 logger.info("Invoking {}", uri);
133                 ConfigMetadata delConfig = new ConfigMetadata();
134                 HttpEntity<ConfigMetadata> entity = new HttpEntity<>(delConfig);
135                 ResponseEntity<Void> voidResponse = testRestTemplateAdminRole().exchange(uri, HttpMethod.DELETE, entity,
136                                 Void.class);
137                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
138         }
139
140 }