2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===================================
20 package org.oransc.ric.portal.dashboard.controller;
22 import java.lang.invoke.MethodHandles;
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;
41 public class AppManagerControllerTest extends AbstractControllerTest {
43 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
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());
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());
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());
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());
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());
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());
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());
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,
109 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
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());
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());
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,
137 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());