From 3340ea073fd56431b2d1231bda17cd98765fd8eb Mon Sep 17 00:00:00 2001 From: "Lott, Christopher (cl778h)" Date: Fri, 5 Jul 2019 13:03:32 -0400 Subject: [PATCH] Add JUnit tests of backend controllers Change-Id: I98be18b47d5b14154d4bed018f51f86b89b9ce15 Signed-off-by: Lott, Christopher (cl778h) --- docs/release-notes.rst | 3 +- .../ric/portal/dashboard/DashboardConstants.java | 8 +- .../config/AppManagerMockConfiguration.java | 9 +- .../dashboard/controller/AcXappController.java | 13 +- .../dashboard/controller/AdminController.java | 13 +- .../dashboard/controller/AnrXappController.java | 35 +++--- .../dashboard/controller/AppManagerController.java | 39 +++--- .../dashboard/controller/E2ManagerController.java | 32 +++-- .../portal/dashboard/AbstractControllerTest.java | 97 +++++++++++++++ .../ric/portal/dashboard/AcXappControllerTest.java | 69 +++++++++++ .../ric/portal/dashboard/AdminControllerTest.java | 67 ++++++++++ .../portal/dashboard/AnrXappControllerTest.java | 101 +++++++++++++++ .../portal/dashboard/AppManagerControllerTest.java | 138 +++++++++++++++++++++ ...pplicationTest.java => DefaultContextTest.java} | 12 +- .../portal/dashboard/E2ManagerControllerTest.java | 117 +++++++++++++++++ 15 files changed, 695 insertions(+), 58 deletions(-) create mode 100644 webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/AbstractControllerTest.java create mode 100644 webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/AcXappControllerTest.java create mode 100644 webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/AdminControllerTest.java create mode 100644 webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/AnrXappControllerTest.java create mode 100644 webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/AppManagerControllerTest.java rename webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/{DashboardApplicationTest.java => DefaultContextTest.java} (74%) create mode 100644 webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/E2ManagerControllerTest.java diff --git a/docs/release-notes.rst b/docs/release-notes.rst index 7a9e784c..aefe7179 100644 --- a/docs/release-notes.rst +++ b/docs/release-notes.rst @@ -28,8 +28,9 @@ Version 1.0.5, 5 July 2019 * Update E2 manager client to spec version 20190703 * Add configuration-driven mock of E2 getNodebIdList * Revise front-end components to use prefix 'rd' -* Revise the notification service to allow multiple * Improve error handling in BE and FE code +* Revise the notification service to display multiple notifications +* Add JUnit test cases for controller methods Version 1.0.4, 27 June 2019 --------------------------- diff --git a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/DashboardConstants.java b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/DashboardConstants.java index 67826ded..9b80864f 100644 --- a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/DashboardConstants.java +++ b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/DashboardConstants.java @@ -25,9 +25,9 @@ public abstract class DashboardConstants { // Sonar insists on hiding the constructor } - public static final String ENDPOINT_PREFIX = "/api/"; - public static final String HEALTHCHECK_PATH = "health"; - public static final String VERSION_PATH = "version"; - public static final String USER_PATH = "user"; + public static final String ENDPOINT_PREFIX = "/api"; + + // Factor out method names used in multiple controllers + public static final String VERSION_METHOD = "version"; } diff --git a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/AppManagerMockConfiguration.java b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/AppManagerMockConfiguration.java index 10517e88..2dfb8149 100644 --- a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/AppManagerMockConfiguration.java +++ b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/AppManagerMockConfiguration.java @@ -108,22 +108,21 @@ public class AppManagerMockConfiguration { when(mockApi.getAllXappConfig()).thenReturn(allXappConfigs); - when(mockApi.createXappConfig(any(XAppConfig.class))).thenReturn(new XAppConfig()); + when(mockApi.createXappConfig(any(XAppConfig.class))).thenReturn(allXappConfigs.get(0)); - when(mockApi.modifyXappConfig(any(XAppConfig.class))).thenReturn(new XAppConfig()); + when(mockApi.modifyXappConfig(any(XAppConfig.class))).thenReturn(allXappConfigs.get(0)); doAnswer(i -> { return null; }).when(mockApi).deleteXappConfig(any(ConfigMetadata.class)); - when(mockApi.deployXapp(any(XAppInfo.class))).thenReturn(new Xapp()); + when(mockApi.deployXapp(any(XAppInfo.class))).thenReturn(deployedXapps.get(0)); when(mockApi.listAllXapps()).thenReturn(availXapps); when(mockApi.getAllXapps()).thenReturn(deployedXapps); - Xapp xappByName = new Xapp().name("name").status(StatusEnum.UNKNOWN).version("v1"); - when(mockApi.getXappByName(any(String.class))).thenReturn(xappByName); + when(mockApi.getXappByName(any(String.class))).thenReturn(deployedXapps.get(0)); doAnswer(i -> { return null; diff --git a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AcXappController.java b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AcXappController.java index 46a4aab0..2fa3eebf 100644 --- a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AcXappController.java +++ b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AcXappController.java @@ -49,11 +49,16 @@ import io.swagger.annotations.ApiParam; * gateway. */ @RestController -@RequestMapping(value = DashboardConstants.ENDPOINT_PREFIX + "/xapp/ac", produces = MediaType.APPLICATION_JSON_VALUE) +@RequestMapping(value = AcXappController.CONTROLLER_PATH, produces = MediaType.APPLICATION_JSON_VALUE) public class AcXappController { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + // Publish paths in constants so tests are easy to write + public static final String CONTROLLER_PATH = DashboardConstants.ENDPOINT_PREFIX + "/xapp/ac"; + // Endpoints + public static final String ADMCTRL_METHOD = "/admctrl"; + // A "control" is an element in the XApp descriptor private static final String AC_CONTROL_NAME = "admission_control_policy"; @@ -69,7 +74,7 @@ public class AcXappController { } @ApiOperation(value = "Gets the A1 client library MANIFEST.MF property Implementation-Version.", response = SuccessTransport.class) - @RequestMapping(value = DashboardConstants.VERSION_PATH, method = RequestMethod.GET) + @RequestMapping(value = DashboardConstants.VERSION_METHOD, method = RequestMethod.GET) public SuccessTransport getA1MediatorClientVersion() { return new SuccessTransport(200, DashboardApplication.getImplementationVersion(A1MediatorApi.class)); } @@ -78,7 +83,7 @@ public class AcXappController { * GET policy is not supported at present by A1 Mediator! Always returns 501. */ @ApiOperation(value = "Gets the admission control policy for AC xApp via the A1 Mediator") - @RequestMapping(value = "admctrl", method = RequestMethod.GET) + @RequestMapping(value = ADMCTRL_METHOD, method = RequestMethod.GET) public Object getAdmissionControlPolicy(HttpServletResponse response) { logger.debug("getAdmissionControlPolicy"); response.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED); @@ -90,7 +95,7 @@ public class AcXappController { * fields are defined in the ACAdmissionIntervalControl Typescript interface. */ @ApiOperation(value = "Sets the admission control policy for AC xApp via the A1 Mediator") - @RequestMapping(value = "catime", method = RequestMethod.PUT) + @RequestMapping(value = ADMCTRL_METHOD, method = RequestMethod.PUT) public void setAdmissionControlPolicy(@ApiParam(value = "Admission control policy") @RequestBody JsonNode acPolicy, // HttpServletResponse response) { logger.debug("setAdmissionControlPolicy {}", acPolicy); diff --git a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AdminController.java b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AdminController.java index ed4837d8..2f141480 100644 --- a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AdminController.java +++ b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AdminController.java @@ -38,11 +38,16 @@ import io.swagger.annotations.ApiOperation; * Answers REST requests for admin services like version, health etc. */ @RestController -@RequestMapping(value = DashboardConstants.ENDPOINT_PREFIX + "/admin", produces = MediaType.APPLICATION_JSON_VALUE) +@RequestMapping(value = AdminController.CONTROLLER_PATH, produces = MediaType.APPLICATION_JSON_VALUE) public class AdminController { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + // Publish paths in constants so tests are easy to write + public static final String CONTROLLER_PATH = DashboardConstants.ENDPOINT_PREFIX + "/admin"; + public static final String USER_METHOD = "user"; + public static final String HEALTH_METHOD = "health"; + private final DashboardUser[] users; public AdminController() { @@ -56,7 +61,7 @@ public class AdminController { } @ApiOperation(value = "Gets the Dashboard MANIFEST.MF property Implementation-Version.", response = SuccessTransport.class) - @RequestMapping(value = DashboardConstants.VERSION_PATH, method = RequestMethod.GET) + @RequestMapping(value = DashboardConstants.VERSION_METHOD, method = RequestMethod.GET) public SuccessTransport getVersion() { logger.debug("getVersion"); return new SuccessTransport(200, @@ -64,14 +69,14 @@ public class AdminController { } @ApiOperation(value = "Checks the health of the application.", response = SuccessTransport.class) - @RequestMapping(value = DashboardConstants.HEALTHCHECK_PATH, method = RequestMethod.GET) + @RequestMapping(value = HEALTH_METHOD, method = RequestMethod.GET) public SuccessTransport getHealth() { logger.debug("getHealth"); return new SuccessTransport(200, "Dashboard is healthy!"); } @ApiOperation(value = "Gets the list of application users.", response = DashboardUser.class, responseContainer = "List") - @RequestMapping(value = DashboardConstants.USER_PATH, method = RequestMethod.GET) + @RequestMapping(value = USER_METHOD, method = RequestMethod.GET) public DashboardUser[] getUsers() { logger.debug("getUsers"); return users; diff --git a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AnrXappController.java b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AnrXappController.java index 2449caa9..e33b355c 100644 --- a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AnrXappController.java +++ b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AnrXappController.java @@ -52,18 +52,25 @@ import io.swagger.annotations.ApiOperation; */ @Configuration @RestController -@RequestMapping(value = DashboardConstants.ENDPOINT_PREFIX + "/xapp/anr", produces = MediaType.APPLICATION_JSON_VALUE) +@RequestMapping(value = AnrXappController.CONTROLLER_PATH, produces = MediaType.APPLICATION_JSON_VALUE) public class AnrXappController { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - // Query parameters - private static final String QP_NODEB = "ggnodeb"; - private static final String QP_SERVING = "servingCellNrcgi"; - private static final String QP_NEIGHBOR = "neighborCellNrpci"; + // Publish paths in constants so tests are easy to write + public static final String CONTROLLER_PATH = DashboardConstants.ENDPOINT_PREFIX + "/xapp/anr"; + // Endpoints + public static final String HEALTH_ALIVE_METHOD = "/health/alive"; + public static final String HEALTH_READY_METHOD = "/health/ready"; + public static final String GNODEBS_METHOD = "/gnodebs"; + public static final String NCRT_METHOD = "/ncrt"; // Path parameters - private static final String PP_SERVING = "servingcells"; - private static final String PP_NEIGHBOR = "neighborcells"; + public static final String PP_SERVING = "servingcells"; + public static final String PP_NEIGHBOR = "neighborcells"; + // Query parameters + public static final String QP_NODEB = "ggnodeb"; + public static final String QP_SERVING = "servingCellNrcgi"; + public static final String QP_NEIGHBOR = "neighborCellNrpci"; // Populated by the autowired constructor private final HealthApi healthApi; @@ -81,13 +88,13 @@ public class AnrXappController { } @ApiOperation(value = "Gets the ANR client library MANIFEST.MF property Implementation-Version.", response = SuccessTransport.class) - @RequestMapping(value = DashboardConstants.VERSION_PATH, method = RequestMethod.GET) + @RequestMapping(value = DashboardConstants.VERSION_METHOD, method = RequestMethod.GET) public SuccessTransport getAnrXappClientVersion() { return new SuccessTransport(200, DashboardApplication.getImplementationVersion(HealthApi.class)); } @ApiOperation(value = "Performs a liveness probe on the ANR xApp, result expressed as the response code.") - @RequestMapping(value = "/health/alive", method = RequestMethod.GET) + @RequestMapping(value = HEALTH_ALIVE_METHOD, method = RequestMethod.GET) public void getHealthAlive(HttpServletResponse response) { logger.debug("getHealthAlive"); healthApi.getHealthAlive(); @@ -95,7 +102,7 @@ public class AnrXappController { } @ApiOperation(value = "Performs a readiness probe on the ANR xApp, result expressed as the response code.") - @RequestMapping(value = "/health/ready", method = RequestMethod.GET) + @RequestMapping(value = HEALTH_READY_METHOD, method = RequestMethod.GET) public void getHealthReady(HttpServletResponse response) { logger.debug("getHealthReady"); healthApi.getHealthReady(); @@ -103,14 +110,14 @@ public class AnrXappController { } @ApiOperation(value = "Returns list of gNodeB IDs based on NCRT in ANR", response = GgNodeBTable.class) - @RequestMapping(value = "/gnodebs", method = RequestMethod.GET) + @RequestMapping(value = GNODEBS_METHOD, method = RequestMethod.GET) public GgNodeBTable getGnodebs() { logger.debug("getGnodebs"); return ncrtApi.getgNodeB(); } @ApiOperation(value = "Returns neighbor cell relation table for all gNodeBs or based on query parameters", response = NeighborCellRelationTable.class) - @RequestMapping(value = "/ncrt", method = RequestMethod.GET) + @RequestMapping(value = NCRT_METHOD, method = RequestMethod.GET) public NeighborCellRelationTable getNcrt( // @RequestParam(name = QP_NODEB, required = false) String ggnbId, // @RequestParam(name = QP_SERVING, required = false) String servingCellNrcgi, // @@ -122,7 +129,7 @@ public class AnrXappController { // /ncrt/servingcells/{servCellNrcgi}/neighborcells/{neighCellNrpci} : @ApiOperation(value = "Modify neighbor cell relation based on Serving Cell NRCGI and Neighbor Cell NRPCI") - @RequestMapping(value = "/ncrt/" + PP_SERVING + "/{" + PP_SERVING + "}/" + PP_NEIGHBOR + "/{" + PP_NEIGHBOR + @RequestMapping(value = NCRT_METHOD + "/" + PP_SERVING + "/{" + PP_SERVING + "}/" + PP_NEIGHBOR + "/{" + PP_NEIGHBOR + "}", method = RequestMethod.PUT) public void modifyNcrt(@PathVariable(PP_SERVING) String servingCellNrcgi, // @PathVariable(PP_NEIGHBOR) String neighborCellNrpci, // @@ -134,7 +141,7 @@ public class AnrXappController { } @ApiOperation(value = "Delete neighbor cell relation based on Serving Cell NRCGI and Neighbor Cell NRPCI") - @RequestMapping(value = "/ncrt/" + PP_SERVING + "/{" + PP_SERVING + "}/" + PP_NEIGHBOR + "/{" + PP_NEIGHBOR + @RequestMapping(value = NCRT_METHOD + "/" + PP_SERVING + "/{" + PP_SERVING + "}/" + PP_NEIGHBOR + "/{" + PP_NEIGHBOR + "}", method = RequestMethod.DELETE) public void deleteNcrt(@PathVariable(PP_SERVING) String servingCellNrcgi, // @PathVariable(PP_NEIGHBOR) String neighborCellNrpci, // diff --git a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AppManagerController.java b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AppManagerController.java index 9c356ca0..ddef5b42 100644 --- a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AppManagerController.java +++ b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AppManagerController.java @@ -58,11 +58,22 @@ import io.swagger.annotations.ApiOperation; */ @Configuration @RestController -@RequestMapping(value = DashboardConstants.ENDPOINT_PREFIX + "/appmgr", produces = MediaType.APPLICATION_JSON_VALUE) +@RequestMapping(value = AppManagerController.CONTROLLER_PATH, produces = MediaType.APPLICATION_JSON_VALUE) public class AppManagerController { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + // Publish paths in constants so tests are easy to write + public static final String CONTROLLER_PATH = DashboardConstants.ENDPOINT_PREFIX + "/appmgr"; + // Endpoints + public static final String HEALTH_ALIVE_METHOD = "/health/alive"; + public static final String HEALTH_READY_METHOD = "/health/ready"; + public static final String CONFIG_METHOD = "/config"; + public static final String XAPPS_METHOD = "/xapps"; + public static final String XAPPS_LIST_METHOD = XAPPS_METHOD + "/list"; + // Path parameters + public static final String PP_XAPP_NAME = "xAppName"; + // Populated by the autowired constructor private final HealthApi healthApi; private final XappApi xappApi; @@ -79,13 +90,13 @@ public class AppManagerController { } @ApiOperation(value = "Gets the XApp manager client library MANIFEST.MF property Implementation-Version.", response = SuccessTransport.class) - @RequestMapping(value = DashboardConstants.VERSION_PATH, method = RequestMethod.GET) + @RequestMapping(value = DashboardConstants.VERSION_METHOD, method = RequestMethod.GET) public SuccessTransport getXappManagerClientVersion() { return new SuccessTransport(200, DashboardApplication.getImplementationVersion(HealthApi.class)); } @ApiOperation(value = "Health check of xApp Manager - Liveness probe.") - @RequestMapping(value = "/health/alive", method = RequestMethod.GET) + @RequestMapping(value = HEALTH_ALIVE_METHOD, method = RequestMethod.GET) public void getHealth(HttpServletResponse response) { logger.debug("getHealthAlive"); healthApi.getHealthAlive(); @@ -93,7 +104,7 @@ public class AppManagerController { } @ApiOperation(value = "Readiness check of xApp Manager - Readiness probe.") - @RequestMapping(value = "/health/ready", method = RequestMethod.GET) + @RequestMapping(value = HEALTH_READY_METHOD, method = RequestMethod.GET) public void getHealthReady(HttpServletResponse response) { logger.debug("getHealthReady"); healthApi.getHealthReady(); @@ -101,28 +112,28 @@ public class AppManagerController { } @ApiOperation(value = "Returns the configuration of all xapps.", response = AllXappConfig.class) - @RequestMapping(value = "/config", method = RequestMethod.GET) + @RequestMapping(value = CONFIG_METHOD, method = RequestMethod.GET) public AllXappConfig getAllXappConfig() { logger.debug("getAllXappConfig"); return xappApi.getAllXappConfig(); } @ApiOperation(value = "Create xApp config.", response = XAppConfig.class) - @RequestMapping(value = "/config", method = RequestMethod.POST) + @RequestMapping(value = CONFIG_METHOD, method = RequestMethod.POST) public XAppConfig createXappConfig(@RequestBody XAppConfig xAppConfig) { logger.debug("createXappConfig {}", xAppConfig); return xappApi.createXappConfig(xAppConfig); } @ApiOperation(value = "Modify xApp config.", response = XAppConfig.class) - @RequestMapping(value = "/config", method = RequestMethod.PUT) + @RequestMapping(value = CONFIG_METHOD, method = RequestMethod.PUT) public XAppConfig modifyXappConfig(@RequestBody XAppConfig xAppConfig) { logger.debug("modifyXappConfig {}", xAppConfig); return xappApi.modifyXappConfig(xAppConfig); } @ApiOperation(value = "Delete xApp configuration.") - @RequestMapping(value = "/config/{xAppName}", method = RequestMethod.DELETE) + @RequestMapping(value = CONFIG_METHOD + "/{" + PP_XAPP_NAME + "}", method = RequestMethod.DELETE) public void deleteXappConfig(@RequestBody ConfigMetadata configMetadata, HttpServletResponse response) { logger.debug("deleteXappConfig {}", configMetadata); xappApi.deleteXappConfig(configMetadata); @@ -130,8 +141,8 @@ public class AppManagerController { } @ApiOperation(value = "Returns a list of deployable xapps.", response = DashboardDeployableXapps.class) - @RequestMapping(value = "/xapps/list", method = RequestMethod.GET) - public DashboardDeployableXapps getAvailableXapps() { + @RequestMapping(value = XAPPS_LIST_METHOD, method = RequestMethod.GET) + public Object getAvailableXapps() { logger.debug("getAvailableXapps"); AllDeployableXapps appNames = xappApi.listAllXapps(); // Answer a collection of structure instead of string @@ -144,28 +155,28 @@ public class AppManagerController { } @ApiOperation(value = "Returns the status of all deployed xapps.", response = AllDeployedXapps.class) - @RequestMapping(value = "/xapps", method = RequestMethod.GET) + @RequestMapping(value = XAPPS_METHOD, method = RequestMethod.GET) public AllDeployedXapps getDeployedXapps() { logger.debug("getDeployedXapps"); return xappApi.getAllXapps(); } @ApiOperation(value = "Returns the status of a given xapp.", response = Xapp.class) - @RequestMapping(value = "/xapps/{xAppName}", method = RequestMethod.GET) + @RequestMapping(value = XAPPS_METHOD + "/{" + PP_XAPP_NAME + "}", method = RequestMethod.GET) public Xapp getXapp(@PathVariable("xAppName") String xAppName) { logger.debug("getXapp {}", xAppName); return xappApi.getXappByName(xAppName); } @ApiOperation(value = "Deploy a xapp.", response = Xapp.class) - @RequestMapping(value = "/xapps", method = RequestMethod.POST) + @RequestMapping(value = XAPPS_METHOD, method = RequestMethod.POST) public Xapp deployXapp(@RequestBody XAppInfo xAppInfo) { logger.debug("deployXapp {}", xAppInfo); return xappApi.deployXapp(xAppInfo); } @ApiOperation(value = "Undeploy an existing xapp.") - @RequestMapping(value = "/xapps/{xAppName}", method = RequestMethod.DELETE) + @RequestMapping(value = XAPPS_METHOD + "/{" + PP_XAPP_NAME + "}", method = RequestMethod.DELETE) public void undeployXapp(@PathVariable("xAppName") String xAppName, HttpServletResponse response) { logger.debug("undeployXapp {}", xAppName); xappApi.undeployXapp(xAppName); diff --git a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/E2ManagerController.java b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/E2ManagerController.java index a4533b64..3d52b8c2 100644 --- a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/E2ManagerController.java +++ b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/E2ManagerController.java @@ -62,13 +62,20 @@ import io.swagger.annotations.ApiOperation; */ @Configuration @RestController -@RequestMapping(value = DashboardConstants.ENDPOINT_PREFIX + "/e2mgr", produces = MediaType.APPLICATION_JSON_VALUE) +@RequestMapping(value = E2ManagerController.CONTROLLER_PATH, produces = MediaType.APPLICATION_JSON_VALUE) public class E2ManagerController { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private final List mockNodebIdList; - + // Publish paths in constants so tests are easy to write + public static final String CONTROLLER_PATH = DashboardConstants.ENDPOINT_PREFIX + "/e2mgr"; + // Endpoints + public static final String HEALTH_METHOD = "health"; + public static final String NODEB_METHOD = "/nodeb"; + public static final String NODEB_LIST_METHOD = "/nodeb-ids"; + public static final String RAN_METHOD = "/ran"; + public static final String ENDC_SETUP_METHOD = "/endcSetup"; + public static final String X2_SETUP_METHOD = "/x2Setup"; // Path parameters private static final String PP_RANNAME = "ranName"; @@ -76,6 +83,9 @@ public class E2ManagerController { private final HealthCheckApi e2HealthCheckApi; private final NodebApi e2NodebApi; + // TODO: remove this when E2 delivers the feature + private final List mockNodebIdList; + @Autowired public E2ManagerController(final HealthCheckApi e2HealthCheckApi, final NodebApi e2NodebApi, @Value("${e2mgr.mock.rannames:#{null}}") final String mockRanNames) { @@ -94,13 +104,13 @@ public class E2ManagerController { } @ApiOperation(value = "Gets the E2 manager client library MANIFEST.MF property Implementation-Version.", response = SuccessTransport.class) - @RequestMapping(value = DashboardConstants.VERSION_PATH, method = RequestMethod.GET) + @RequestMapping(value = DashboardConstants.VERSION_METHOD, method = RequestMethod.GET) public SuccessTransport getE2ManagerClientVersion() { return new SuccessTransport(200, DashboardApplication.getImplementationVersion(HealthCheckApi.class)); } @ApiOperation(value = "Gets the health from the E2 manager, expressed as the response code.") - @RequestMapping(value = "/health", method = RequestMethod.GET) + @RequestMapping(value = HEALTH_METHOD, method = RequestMethod.GET) public void healthGet(HttpServletResponse response) { logger.debug("healthGet"); e2HealthCheckApi.healthGet(); @@ -109,7 +119,7 @@ public class E2ManagerController { // This calls other methods to simplify the task of the front-end. @ApiOperation(value = "Gets all RAN identities and statuses from the E2 manager.", response = RanDetailsTransport.class, responseContainer = "List") - @RequestMapping(value = "/ran", method = RequestMethod.GET) + @RequestMapping(value = RAN_METHOD, method = RequestMethod.GET) public List getRanDetails() { logger.debug("getRanDetails"); // TODO: remove mock when e2mgr delivers the getNodebIdList() method @@ -131,21 +141,21 @@ public class E2ManagerController { } @ApiOperation(value = "Get RAN identities list.", response = NodebIdentity.class, responseContainer = "List") - @RequestMapping(value = "/nodeb-ids", method = RequestMethod.GET) + @RequestMapping(value = NODEB_LIST_METHOD, method = RequestMethod.GET) public List getNodebIdList() { logger.debug("getNodebIdList"); return e2NodebApi.getNodebIdList(); } @ApiOperation(value = "Get RAN by name.", response = GetNodebResponse.class) - @RequestMapping(value = "/nodeb/{" + PP_RANNAME + "}", method = RequestMethod.GET) + @RequestMapping(value = NODEB_METHOD + "/{" + PP_RANNAME + "}", method = RequestMethod.GET) public GetNodebResponse getNb(@PathVariable(PP_RANNAME) String ranName) { logger.debug("getNb {}", ranName); return e2NodebApi.getNb(ranName); } @ApiOperation(value = "Close all connections to the RANs and delete the data from the nodeb-rnib DB.") - @RequestMapping(value = "/nodeb", method = RequestMethod.DELETE) + @RequestMapping(value = NODEB_METHOD, method = RequestMethod.DELETE) public void nodebDelete(HttpServletResponse response) { logger.debug("nodebDelete"); e2NodebApi.nodebDelete(); @@ -153,7 +163,7 @@ public class E2ManagerController { } @ApiOperation(value = "Sets up an EN-DC RAN connection via the E2 manager.") - @RequestMapping(value = "/endcSetup", method = RequestMethod.POST) + @RequestMapping(value = ENDC_SETUP_METHOD, method = RequestMethod.POST) public void endcSetup(@RequestBody SetupRequest setupRequest, HttpServletResponse response) { logger.debug("endcSetup {}", setupRequest); e2NodebApi.endcSetup(setupRequest); @@ -161,7 +171,7 @@ public class E2ManagerController { } @ApiOperation(value = "Sets up an X2 RAN connection via the E2 manager.") - @RequestMapping(value = "/x2Setup", method = RequestMethod.POST) + @RequestMapping(value = X2_SETUP_METHOD, method = RequestMethod.POST) public void x2Setup(@RequestBody SetupRequest setupRequest, HttpServletResponse response) { logger.debug("x2Setup {}", setupRequest); e2NodebApi.x2Setup(setupRequest); diff --git a/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/AbstractControllerTest.java b/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/AbstractControllerTest.java new file mode 100644 index 00000000..80fd9776 --- /dev/null +++ b/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/AbstractControllerTest.java @@ -0,0 +1,97 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * Copyright (C) 2019 AT&T Intellectual Property and Nokia + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================LICENSE_END=================================== + */ +package org.oransc.ric.portal.dashboard; + +import java.lang.invoke.MethodHandles; +import java.net.URI; +import java.util.Map; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.util.UriComponentsBuilder; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +// Need the fake answers from the backend +@ActiveProfiles("mock") +public class AbstractControllerTest { + + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + // Created by Spring black magic + // https://spring.io/guides/gs/testing-web/ + @LocalServerPort + private int localServerPort; + + @Autowired + protected TestRestTemplate restTemplate; + + /** + * Flexible URI builder. + * + * @param queryParams + * Map of string-string query parameters + * @param path + * Array of path components. If a component has an + * embedded slash, the string is split and each + * subcomponent is added individually. + * @return URI + */ + protected URI buildUri(final Map queryParams, final String... path) { + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:" + localServerPort + "/"); + for (int p = 0; p < path.length; ++p) { + if (path[p] == null || path[p].isEmpty()) { + throw new IllegalArgumentException("Unexpected null or empty at path index " + Integer.toString(p)); + } else if (path[p].contains("/")) { + String[] subpaths = path[p].split("/"); + for (String s : subpaths) + if (!s.isEmpty()) + builder.pathSegment(s); + } else { + builder.pathSegment(path[p]); + } + } + if (queryParams != null && queryParams.size() > 0) { + for (Map.Entry entry : queryParams.entrySet()) { + if (entry.getKey() == null || entry.getValue() == null) + throw new IllegalArgumentException("Unexpected null key or value"); + else + builder.queryParam(entry.getKey(), entry.getValue()); + } + } + return builder.build().encode().toUri(); + } + + // Must have at least one test here + @Test + public void contextLoads() { + logger.info("Context loads on mock profile"); + } + +} diff --git a/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/AcXappControllerTest.java b/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/AcXappControllerTest.java new file mode 100644 index 00000000..2910d86e --- /dev/null +++ b/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/AcXappControllerTest.java @@ -0,0 +1,69 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * Copyright (C) 2019 AT&T Intellectual Property and Nokia + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================LICENSE_END=================================== + */ +package org.oransc.ric.portal.dashboard; + +import java.io.IOException; +import java.lang.invoke.MethodHandles; +import java.net.URI; + +import org.junit.Assert; +import org.junit.Test; +import org.oransc.ric.portal.dashboard.controller.AcXappController; +import org.oransc.ric.portal.dashboard.model.SuccessTransport; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class AcXappControllerTest extends AbstractControllerTest { + + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + @Test + public void versionTest() { + URI uri = buildUri(null, AcXappController.CONTROLLER_PATH, DashboardConstants.VERSION_METHOD); + logger.info("Invoking {}", uri); + SuccessTransport st = restTemplate.getForObject(uri, SuccessTransport.class); + Assert.assertFalse(st.getData().toString().isEmpty()); + } + + @Test + public void getTest() throws IOException { + // Always returns 501; surprised that no exception is thrown. + URI uri = buildUri(null, AcXappController.CONTROLLER_PATH, AcXappController.ADMCTRL_METHOD); + logger.info("Invoking {}", uri); + restTemplate.getForObject(uri, String.class); + } + + @Test + public void putTest() throws IOException { + ObjectMapper mapper = new ObjectMapper(); + JsonNode body = mapper.readTree("{ \"policy\" : true }"); + URI uri = buildUri(null, AcXappController.CONTROLLER_PATH, AcXappController.ADMCTRL_METHOD); + HttpEntity entity = new HttpEntity<>(body); + ResponseEntity voidResponse = restTemplate.exchange(uri, HttpMethod.PUT, entity, Void.class); + Assert.assertTrue(voidResponse.getStatusCode().is2xxSuccessful()); + } + +} diff --git a/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/AdminControllerTest.java b/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/AdminControllerTest.java new file mode 100644 index 00000000..1a84c5a2 --- /dev/null +++ b/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/AdminControllerTest.java @@ -0,0 +1,67 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * Copyright (C) 2019 AT&T Intellectual Property and Nokia + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================LICENSE_END=================================== + */ +package org.oransc.ric.portal.dashboard; + +import java.lang.invoke.MethodHandles; +import java.net.URI; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.oransc.ric.portal.dashboard.controller.AdminController; +import org.oransc.ric.portal.dashboard.model.DashboardUser; +import org.oransc.ric.portal.dashboard.model.SuccessTransport; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; + +public class AdminControllerTest extends AbstractControllerTest { + + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + @Test + public void versionTest() { + URI uri = buildUri(null, AdminController.CONTROLLER_PATH, DashboardConstants.VERSION_METHOD); + logger.info("Invoking {}", uri); + SuccessTransport st = restTemplate.getForObject(uri, SuccessTransport.class); + Assert.assertFalse(st.getData().toString().isEmpty()); + } + + @Test + public void healthTest() { + URI uri = buildUri(null, AdminController.CONTROLLER_PATH, AdminController.HEALTH_METHOD); + logger.info("Invoking {}", uri); + ResponseEntity voidResponse = restTemplate.getForEntity(uri, Void.class); + Assert.assertTrue(voidResponse.getStatusCode().is2xxSuccessful()); + } + + @Test + public void usersTest() { + URI uri = buildUri(null, AdminController.CONTROLLER_PATH, AdminController.USER_METHOD); + logger.info("Invoking {}", uri); + ResponseEntity> response = restTemplate.exchange(uri, HttpMethod.GET, null, + new ParameterizedTypeReference>() { + }); + Assert.assertFalse(response.getBody().isEmpty()); + } + +} diff --git a/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/AnrXappControllerTest.java b/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/AnrXappControllerTest.java new file mode 100644 index 00000000..43fc0805 --- /dev/null +++ b/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/AnrXappControllerTest.java @@ -0,0 +1,101 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * Copyright (C) 2019 AT&T Intellectual Property and Nokia + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================LICENSE_END=================================== + */ +package org.oransc.ric.portal.dashboard; + +import java.lang.invoke.MethodHandles; +import java.net.URI; + +import org.junit.Assert; +import org.junit.Test; +import org.oransc.ric.anrxapp.client.model.GgNodeBTable; +import org.oransc.ric.anrxapp.client.model.NeighborCellRelationMod; +import org.oransc.ric.anrxapp.client.model.NeighborCellRelationTable; +import org.oransc.ric.portal.dashboard.controller.AnrXappController; +import org.oransc.ric.portal.dashboard.model.SuccessTransport; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; + +public class AnrXappControllerTest extends AbstractControllerTest { + + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + @Test + public void versionTest() { + URI uri = buildUri(null, AnrXappController.CONTROLLER_PATH, DashboardConstants.VERSION_METHOD); + logger.info("Invoking {}", uri); + SuccessTransport st = restTemplate.getForObject(uri, SuccessTransport.class); + Assert.assertFalse(st.getData().toString().isEmpty()); + } + + @Test + public void healthAliveTest() { + URI uri = buildUri(null, AnrXappController.CONTROLLER_PATH, AnrXappController.HEALTH_ALIVE_METHOD); + logger.info("Invoking {}", uri); + ResponseEntity voidResponse = restTemplate.getForEntity(uri, Void.class); + Assert.assertTrue(voidResponse.getStatusCode().is2xxSuccessful()); + } + + @Test + public void healthReadyTest() { + URI uri = buildUri(null, AnrXappController.CONTROLLER_PATH, AnrXappController.HEALTH_READY_METHOD); + logger.info("Invoking {}", uri); + ResponseEntity voidResponse = restTemplate.getForEntity(uri, Void.class); + Assert.assertTrue(voidResponse.getStatusCode().is2xxSuccessful()); + } + + @Test + public void gnodebsTest() { + URI uri = buildUri(null, AnrXappController.CONTROLLER_PATH, AnrXappController.GNODEBS_METHOD); + logger.info("Invoking {}", uri); + GgNodeBTable list = restTemplate.getForObject(uri, GgNodeBTable.class); + Assert.assertFalse(list.getGNodeBIds().isEmpty()); + } + + @Test + public void ncrtGetTest() { + URI uri = buildUri(null, AnrXappController.CONTROLLER_PATH, AnrXappController.NCRT_METHOD); + logger.info("Invoking {}", uri); + NeighborCellRelationTable table = restTemplate.getForObject(uri, NeighborCellRelationTable.class); + Assert.assertFalse(table.getNcrtRelations().isEmpty()); + } + + @Test + public void ncrtPutTest() { + URI uri = buildUri(null, AnrXappController.CONTROLLER_PATH, AnrXappController.NCRT_METHOD, + AnrXappController.PP_SERVING, "serving", AnrXappController.PP_NEIGHBOR, "neighbor"); + logger.info("Invoking {}", uri); + HttpEntity entity = new HttpEntity<>(new NeighborCellRelationMod()); + ResponseEntity voidResponse = restTemplate.exchange(uri, HttpMethod.PUT, entity, Void.class); + Assert.assertTrue(voidResponse.getStatusCode().is2xxSuccessful()); + } + + @Test + public void ncrtDeleteTest() { + URI uri = buildUri(null, AnrXappController.CONTROLLER_PATH, AnrXappController.NCRT_METHOD, + AnrXappController.PP_SERVING, "serving", AnrXappController.PP_NEIGHBOR, "neighbor"); + logger.info("Invoking {}", uri); + ResponseEntity voidResponse = restTemplate.exchange(uri, HttpMethod.DELETE, null, Void.class); + Assert.assertTrue(voidResponse.getStatusCode().is2xxSuccessful()); + } + +} diff --git a/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/AppManagerControllerTest.java b/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/AppManagerControllerTest.java new file mode 100644 index 00000000..50bdf456 --- /dev/null +++ b/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/AppManagerControllerTest.java @@ -0,0 +1,138 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * Copyright (C) 2019 AT&T Intellectual Property and Nokia + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================LICENSE_END=================================== + */ +package org.oransc.ric.portal.dashboard; + +import java.lang.invoke.MethodHandles; +import java.net.URI; + +import org.junit.Assert; +import org.junit.Test; +import org.oransc.ric.plt.appmgr.client.model.AllDeployedXapps; +import org.oransc.ric.plt.appmgr.client.model.AllXappConfig; +import org.oransc.ric.plt.appmgr.client.model.ConfigMetadata; +import org.oransc.ric.plt.appmgr.client.model.XAppConfig; +import org.oransc.ric.plt.appmgr.client.model.XAppInfo; +import org.oransc.ric.plt.appmgr.client.model.Xapp; +import org.oransc.ric.portal.dashboard.controller.AppManagerController; +import org.oransc.ric.portal.dashboard.model.DashboardDeployableXapps; +import org.oransc.ric.portal.dashboard.model.SuccessTransport; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; + +public class AppManagerControllerTest extends AbstractControllerTest { + + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + @Test + public void versionTest() { + URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, DashboardConstants.VERSION_METHOD); + logger.info("Invoking {}", uri); + SuccessTransport st = restTemplate.getForObject(uri, SuccessTransport.class); + Assert.assertFalse(st.getData().toString().isEmpty()); + } + + @Test + public void healthAliveTest() { + URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.HEALTH_ALIVE_METHOD); + logger.info("Invoking {}", uri); + ResponseEntity voidResponse = restTemplate.getForEntity(uri, Void.class); + Assert.assertTrue(voidResponse.getStatusCode().is2xxSuccessful()); + } + + @Test + public void healthReadyTest() { + URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.HEALTH_READY_METHOD); + logger.info("Invoking {}", uri); + ResponseEntity voidResponse = restTemplate.getForEntity(uri, Void.class); + Assert.assertTrue(voidResponse.getStatusCode().is2xxSuccessful()); + } + + @Test + public void appListTest() { + URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.XAPPS_LIST_METHOD); + logger.info("Invoking {}", uri); + DashboardDeployableXapps apps = restTemplate.getForObject(uri, DashboardDeployableXapps.class); + Assert.assertFalse(apps.isEmpty()); + } + + @Test + public void appStatusesTest() { + URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.XAPPS_METHOD); + logger.info("Invoking {}", uri); + AllDeployedXapps apps = restTemplate.getForObject(uri, AllDeployedXapps.class); + Assert.assertFalse(apps.isEmpty()); + } + + @Test + public void appStatusTest() { + URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.XAPPS_METHOD, "app"); + logger.info("Invoking {}", uri); + Xapp app = restTemplate.getForObject(uri, Xapp.class); + Assert.assertFalse(app.getName().isEmpty()); + } + + @Test + public void deployAppTest() { + URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.XAPPS_METHOD); + logger.info("Invoking {}", uri); + XAppInfo info = new XAppInfo(); + Xapp app = restTemplate.postForObject(uri, info, Xapp.class); + Assert.assertFalse(app.getName().isEmpty()); + } + + @Test + public void undeployAppTest() { + URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.XAPPS_METHOD, "app"); + logger.info("Invoking {}", uri); + ResponseEntity voidResponse = restTemplate.exchange(uri, HttpMethod.DELETE, null, Void.class); + Assert.assertTrue(voidResponse.getStatusCode().is2xxSuccessful()); + } + + @Test + public void getConfigTest() { + URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.CONFIG_METHOD); + logger.info("Invoking {}", uri); + AllXappConfig config = restTemplate.getForObject(uri, AllXappConfig.class); + Assert.assertFalse(config.isEmpty()); + } + + @Test + public void createConfigTest() { + URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.CONFIG_METHOD); + logger.info("Invoking {}", uri); + XAppConfig newConfig = new XAppConfig(); + XAppConfig response = restTemplate.postForObject(uri, newConfig, XAppConfig.class); + Assert.assertNotNull(response.getConfig()); + } + + @Test + public void deleteConfigTest() { + URI uri = buildUri(null, AppManagerController.CONTROLLER_PATH, AppManagerController.CONFIG_METHOD, "app"); + logger.info("Invoking {}", uri); + ConfigMetadata delConfig = new ConfigMetadata(); + HttpEntity entity = new HttpEntity<>(delConfig); + ResponseEntity voidResponse = restTemplate.exchange(uri, HttpMethod.DELETE, entity, Void.class); + Assert.assertTrue(voidResponse.getStatusCode().is2xxSuccessful()); + } + +} diff --git a/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/DashboardApplicationTest.java b/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/DefaultContextTest.java similarity index 74% rename from webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/DashboardApplicationTest.java rename to webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/DefaultContextTest.java index 439d6680..b68272cf 100644 --- a/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/DashboardApplicationTest.java +++ b/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/DefaultContextTest.java @@ -19,17 +19,27 @@ */ package org.oransc.ric.portal.dashboard; +import java.lang.invoke.MethodHandles; + import org.junit.Test; import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; +/** + * Tests whether the default (not mock) configuration classes run to completion. + */ @RunWith(SpringRunner.class) @SpringBootTest -public class DashboardApplicationTest { +public class DefaultContextTest { + + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); @Test public void contextLoads() { + logger.info("Context loads on default profile"); } } diff --git a/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/E2ManagerControllerTest.java b/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/E2ManagerControllerTest.java new file mode 100644 index 00000000..f54ac77d --- /dev/null +++ b/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/E2ManagerControllerTest.java @@ -0,0 +1,117 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * Copyright (C) 2019 AT&T Intellectual Property and Nokia + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================LICENSE_END=================================== + */ +package org.oransc.ric.portal.dashboard; + +import java.lang.invoke.MethodHandles; +import java.net.URI; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.oransc.ric.e2mgr.client.model.GetNodebResponse; +import org.oransc.ric.e2mgr.client.model.NodebIdentity; +import org.oransc.ric.e2mgr.client.model.SetupRequest; +import org.oransc.ric.portal.dashboard.controller.E2ManagerController; +import org.oransc.ric.portal.dashboard.model.RanDetailsTransport; +import org.oransc.ric.portal.dashboard.model.SuccessTransport; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; + +public class E2ManagerControllerTest extends AbstractControllerTest { + + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + @Test + public void versionTest() { + URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.VERSION_METHOD); + logger.info("Invoking {}", uri); + SuccessTransport st = restTemplate.getForObject(uri, SuccessTransport.class); + Assert.assertFalse(st.getData().toString().isEmpty()); + } + + @Test + public void healthTest() { + URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.HEALTH_METHOD); + logger.info("Invoking {}", uri); + ResponseEntity voidResponse = restTemplate.getForEntity(uri, Void.class); + Assert.assertTrue(voidResponse.getStatusCode().is2xxSuccessful()); + } + + @Test + public void ranDetailsTest() { + URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.RAN_METHOD); + logger.info("Invoking {}", uri); + ResponseEntity> response = restTemplate.exchange(uri, HttpMethod.GET, null, + new ParameterizedTypeReference>() { + }); + Assert.assertFalse(response.getBody().isEmpty()); + } + + @Test + public void nodebListTest() { + URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.NODEB_LIST_METHOD); + logger.info("Invoking {}", uri); + ResponseEntity> response = restTemplate.exchange(uri, HttpMethod.GET, null, + new ParameterizedTypeReference>() { + }); + Assert.assertFalse(response.getBody().isEmpty()); + } + + @Test + public void nodebStatusTest() { + URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.NODEB_METHOD, "nodeb"); + logger.info("Invoking {}", uri); + GetNodebResponse response = restTemplate.getForObject(uri, GetNodebResponse.class); + Assert.assertNotNull(response.getRanName()); + } + + @Test + public void bigRedButtonTest() { + URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.NODEB_METHOD); + logger.info("Invoking {}", uri); + ResponseEntity voidResponse = restTemplate.exchange(uri, HttpMethod.DELETE, null, Void.class); + Assert.assertTrue(voidResponse.getStatusCode().is2xxSuccessful()); + } + + @Test + public void endcSetupTest() { + URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.ENDC_SETUP_METHOD); + logger.info("Invoking {}", uri); + SetupRequest setup = new SetupRequest(); + HttpEntity entity = new HttpEntity<>(setup); + ResponseEntity voidResponse = restTemplate.exchange(uri, HttpMethod.POST, entity, Void.class); + Assert.assertTrue(voidResponse.getStatusCode().is2xxSuccessful()); + } + + @Test + public void x2SetupTest() { + URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.X2_SETUP_METHOD); + logger.info("Invoking {}", uri); + SetupRequest setup = new SetupRequest(); + HttpEntity entity = new HttpEntity<>(setup); + ResponseEntity voidResponse = restTemplate.exchange(uri, HttpMethod.POST, entity, Void.class); + Assert.assertTrue(voidResponse.getStatusCode().is2xxSuccessful()); + } + +} -- 2.16.6