Upgrade component API versions to Amber
[portal/ric-dashboard.git] / webapp-backend / src / test / java / org / oransc / ric / portal / dashboard / controller / AdminControllerTest.java
index 018350d..d6f206e 100644 (file)
@@ -2,7 +2,7 @@
  * ========================LICENSE_START=================================
  * O-RAN-SC
  * %%
- * Copyright (C) 2019 AT&T Intellectual Property and Nokia
+ * Copyright (C) 2019 AT&T Intellectual Property
  * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,11 +21,16 @@ package org.oransc.ric.portal.dashboard.controller;
 
 import java.lang.invoke.MethodHandles;
 import java.net.URI;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
-import org.oransc.ric.portal.dashboard.model.DashboardUser;
+import org.onap.portalsdk.core.restful.domain.EcompUser;
+import org.oransc.ric.portal.dashboard.DashboardConstants;
+import org.oransc.ric.portal.dashboard.model.ErrorTransport;
+import org.oransc.ric.portal.dashboard.model.RicInstanceKeyName;
 import org.oransc.ric.portal.dashboard.model.SuccessTransport;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -53,12 +58,22 @@ public class AdminControllerTest extends AbstractControllerTest {
                Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
        }
 
+       @Test
+       public void getInstancesTest() {
+               URI uri = buildUri(null, AdminController.CONTROLLER_PATH, AdminController.INSTANCE_METHOD);
+               logger.info("Invoking {}", uri);
+               ResponseEntity<List<RicInstanceKeyName>> response = testRestTemplateStandardRole().exchange(uri, HttpMethod.GET,
+                               null, new ParameterizedTypeReference<List<RicInstanceKeyName>>() {
+                               });
+               Assertions.assertFalse(response.getBody().isEmpty());
+       }
+
        @Test
        public void getUsersTest() {
                URI uri = buildUri(null, AdminController.CONTROLLER_PATH, AdminController.USER_METHOD);
                logger.info("Invoking {}", uri);
-               ResponseEntity<List<DashboardUser>> response = testRestTemplateAdminRole().exchange(uri, HttpMethod.GET, null,
-                               new ParameterizedTypeReference<List<DashboardUser>>() {
+               ResponseEntity<List<EcompUser>> response = testRestTemplateAdminRole().exchange(uri, HttpMethod.GET, null,
+                               new ParameterizedTypeReference<List<EcompUser>>() {
                                });
                Assertions.assertFalse(response.getBody().isEmpty());
        }
@@ -72,4 +87,30 @@ public class AdminControllerTest extends AbstractControllerTest {
                Assertions.assertTrue(response.getStatusCode().is4xxClientError());
        }
 
+       @Test
+       public void getxAppMetricsUrlTest() {
+               Map<String, String> metricsQueryParms = new HashMap<String, String>();
+               metricsQueryParms.put("app", DashboardConstants.APP_NAME_AC);
+               URI uri = buildUri(metricsQueryParms, AdminController.CONTROLLER_PATH, AdminController.XAPPMETRICS_METHOD);
+               logger.debug("Invoking {}", uri);
+               ResponseEntity<SuccessTransport> successResponse = testRestTemplateStandardRole().exchange(uri, HttpMethod.GET,
+                               null, SuccessTransport.class);
+               Assertions.assertFalse(successResponse.getBody().getData().toString().isEmpty());
+               Assertions.assertTrue(successResponse.getStatusCode().is2xxSuccessful());
+       }
+
+       @Test
+       public void getxAppMetricsUrlTestFail() {
+               Map<String, String> metricsQueryParms = new HashMap<String, String>();
+               // Providing a bogus value for application name in query parameter to test
+               // failure
+               metricsQueryParms.put("app", "ABCD");
+               URI uri = buildUri(metricsQueryParms, AdminController.CONTROLLER_PATH, AdminController.XAPPMETRICS_METHOD);
+               logger.debug("Invoking {}", uri);
+               ResponseEntity<ErrorTransport> errorResponse = testRestTemplateStandardRole().exchange(uri, HttpMethod.GET,
+                               null, ErrorTransport.class);
+               logger.debug("{}", errorResponse.getBody().getError().toString());
+               Assertions.assertTrue(errorResponse.getStatusCode().is4xxClientError());
+       }
+
 }