2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property and Nokia
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.test.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.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;
42 public class AppManagerControllerTest extends AbstractControllerTest {
44 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
47 public void versionTest() {
48 URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.VERSION_METHOD);
49 logger.info("Invoking {}", uri);
50 SuccessTransport st = restTemplate.getForObject(uri, SuccessTransport.class);
51 Assertions.assertFalse(st.getData().toString().isEmpty());
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 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
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 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
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 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 = restTemplate.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 = restTemplate.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 = restTemplate.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 = restTemplate.exchange(uri, HttpMethod.DELETE, null, Void.class);
108 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
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 Assertions.assertFalse(config.isEmpty());
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 Assertions.assertNotNull(response.getConfig());
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 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());