50bdf456edd36508cf17197c0e03ab245cf8c37d
[portal/ric-dashboard.git] / webapp-backend / src / test / java / org / oransc / ric / portal / dashboard / 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;
21
22 import java.lang.invoke.MethodHandles;
23 import java.net.URI;
24
25 import org.junit.Assert;
26 import org.junit.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.controller.AppManagerController;
34 import org.oransc.ric.portal.dashboard.model.DashboardDeployableXapps;
35 import org.oransc.ric.portal.dashboard.model.SuccessTransport;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38 import org.springframework.http.HttpEntity;
39 import org.springframework.http.HttpMethod;
40 import org.springframework.http.ResponseEntity;
41
42 public class AppManagerControllerTest extends AbstractControllerTest {
43
44         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
45
46         @Test
47         public void versionTest() {
48                 URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, DashboardConstants.VERSION_METHOD);
49                 logger.info("Invoking {}", uri);
50                 SuccessTransport st = restTemplate.getForObject(uri, SuccessTransport.class);
51                 Assert.assertFalse(st.getData().toString().isEmpty());
52         }
53
54         @Test
55         public void healthAliveTest() {
56                 URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.HEALTH_ALIVE_METHOD);
57                 logger.info("Invoking {}", uri);
58                 ResponseEntity<Void> voidResponse = restTemplate.getForEntity(uri, Void.class);
59                 Assert.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
60         }
61
62         @Test
63         public void healthReadyTest() {
64                 URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.HEALTH_READY_METHOD);
65                 logger.info("Invoking {}", uri);
66                 ResponseEntity<Void> voidResponse = restTemplate.getForEntity(uri, Void.class);
67                 Assert.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
68         }
69
70         @Test
71         public void appListTest() {
72                 URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.XAPPS_LIST_METHOD);
73                 logger.info("Invoking {}", uri);
74                 DashboardDeployableXapps apps = restTemplate.getForObject(uri, DashboardDeployableXapps.class);
75                 Assert.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 = restTemplate.getForObject(uri, AllDeployedXapps.class);
83                 Assert.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 = restTemplate.getForObject(uri, Xapp.class);
91                 Assert.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 = restTemplate.postForObject(uri, info, Xapp.class);
100                 Assert.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 = restTemplate.exchange(uri, HttpMethod.DELETE, null, Void.class);
108                 Assert.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
109         }
110
111         @Test
112         public void getConfigTest() {
113                 URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.CONFIG_METHOD);
114                 logger.info("Invoking {}", uri);
115                 AllXappConfig config = restTemplate.getForObject(uri, AllXappConfig.class);
116                 Assert.assertFalse(config.isEmpty());
117         }
118
119         @Test
120         public void createConfigTest() {
121                 URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.CONFIG_METHOD);
122                 logger.info("Invoking {}", uri);
123                 XAppConfig newConfig = new XAppConfig();
124                 XAppConfig response = restTemplate.postForObject(uri, newConfig, XAppConfig.class);
125                 Assert.assertNotNull(response.getConfig());
126         }
127
128         @Test
129         public void deleteConfigTest() {
130                 URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.CONFIG_METHOD, "app");
131                 logger.info("Invoking {}", uri);
132                 ConfigMetadata delConfig = new ConfigMetadata();
133                 HttpEntity<ConfigMetadata> entity = new HttpEntity<>(delConfig);
134                 ResponseEntity<Void> voidResponse = restTemplate.exchange(uri, HttpMethod.DELETE, entity, Void.class);
135                 Assert.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
136         }
137
138 }