Move mock configurations to test area 26/526/2
authorLott, Christopher (cl778h) <cl778h@att.com>
Wed, 17 Jul 2019 18:28:11 +0000 (14:28 -0400)
committerLott, Christopher (cl778h) <cl778h@att.com>
Wed, 17 Jul 2019 18:35:09 +0000 (14:35 -0400)
Add new DashboardTestServer class to support development.
Demote mockito dependencies to test scope.

Change-Id: I9dab0f9af61cad901892620d769e275091f953b8
Signed-off-by: Lott, Christopher (cl778h) <cl778h@att.com>
14 files changed:
docs/release-notes.rst
webapp-backend/README.md
webapp-backend/pom.xml
webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/DashboardApplication.java
webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/A1MediatorConfiguration.java
webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/AnrXappConfiguration.java
webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/AppManagerConfiguration.java
webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/E2ManagerConfiguration.java
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/DashboardTestServer.java [new file with mode: 0644]
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/test/config/A1MediatorMockConfiguration.java [moved from webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/A1MediatorMockConfiguration.java with 97% similarity]
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/test/config/AnrXappMockConfiguration.java [moved from webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/AnrXappMockConfiguration.java with 98% similarity]
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/test/config/AppManagerMockConfiguration.java [moved from webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/AppManagerMockConfiguration.java with 98% similarity]
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/test/config/E2ManagerMockConfiguration.java [moved from webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/E2ManagerMockConfiguration.java with 98% similarity]
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/test/controller/AbstractControllerTest.java

index 5a3198d..b6eb3f2 100644 (file)
@@ -20,7 +20,7 @@
 RIC Dashboard Release Notes
 ===========================
 
-Version 1.2.0, 12 July 2019
+Version 1.2.0, 17 July 2019
 ---------------------------
 * Split URL properties into prefix/suffix parts
 * Add jacoco plugin to back-end for code coverage
@@ -28,6 +28,7 @@ Version 1.2.0, 12 July 2019
 * Clean code of issues reported by Sonar
 * Drop mock RAN names feature that supported R1 testing
 * Extend mock endpoints to simulate delay seen in tests
+* Move mock configuration classes into test area
 
 Version 1.0.5, 5 July 2019
 --------------------------
index 2909ded..8a142d7 100644 (file)
@@ -1,12 +1,19 @@
 # RIC Dashboard Web Application Backend
 
+## Launch server
+
+Run `mvn -Dspring.config.name=application-abc spring-boot:run` to run a server configured
+by the file 'application-abc.properties' in the local directory.
+
 ## Development server
 
-Run `mvn -Dspring.profiles.active=mock spring-boot:run` for a dev server. Navigate to `http://localhost:8080/swagger-ui.html`. 
+Set an environment variable via JVM argument "-Dorg.oransc.ric.portal.dashboard=mock"
+and run the JUnit test case DashboardServerTest for a development server to run standalone
+with mock configuration and data that simulates the behavior of remote endpoints.
 
-## Alternate configuration
+## Swagger API documentation
 
-Run `mvn -Dspring.config.name=application-abc spring-boot:run` to read configuration from the file 'application-abc.properties' in the local directory.
+View the server's API documentation at URL `http://localhost:8080/swagger-ui.html`.
 
 ## License
 
index d7e12ec..e96777f 100644 (file)
@@ -83,12 +83,13 @@ limitations under the License.
                        <artifactId>springfox-swagger-ui</artifactId>
                        <version>${springfox.version}</version>
                </dependency>
+               <!-- Test dependencies -->
                <!-- Mockito supports development, not just testing -->
                <dependency>
                        <groupId>org.mockito</groupId>
                        <artifactId>mockito-core</artifactId>
+                       <scope>test</scope>
                </dependency>
-               <!-- Test dependencies -->
                <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-test</artifactId>
index 9dfa584..05778dc 100644 (file)
@@ -28,9 +28,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.annotation.ComponentScan;
 
 @SpringBootApplication
-// Using this package limits the annotation scan to the dashboard classes.
-// Do not want Spring to find the autowired annotations in the generated
-// classes.
+// Limit scan to dashboard classes; exclude generated API classes
 @ComponentScan("org.oransc.ric.portal.dashboard")
 public class DashboardApplication {
 
index 0101fc9..23fae06 100644 (file)
@@ -38,7 +38,7 @@ import org.springframework.web.util.DefaultUriBuilderFactory;
  * container.
  */
 @Configuration
-@Profile("!mock")
+@Profile("!test")
 public class A1MediatorConfiguration {
 
        private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
index 33a5384..7fcb674 100644 (file)
@@ -38,7 +38,7 @@ import org.springframework.web.util.DefaultUriBuilderFactory;
  * Creates instances of the ANR xApp client APIs.
  */
 @Configuration
-@Profile("!mock")
+@Profile("!test")
 public class AnrXappConfiguration {
 
        private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
index 93aadf6..6a112d8 100644 (file)
@@ -39,7 +39,7 @@ import org.springframework.web.util.DefaultUriBuilderFactory;
  * container.
  */
 @Configuration
-@Profile("!mock")
+@Profile("!test")
 public class AppManagerConfiguration {
 
        private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
index 4289a88..0df6132 100644 (file)
@@ -38,7 +38,7 @@ import org.springframework.web.util.DefaultUriBuilderFactory;
  * Creates an E2 manager client as a bean to be managed by the Spring container.
  */
 @Configuration
-@Profile("!mock")
+@Profile("!test")
 public class E2ManagerConfiguration {
 
        private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
diff --git a/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/DashboardTestServer.java b/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/DashboardTestServer.java
new file mode 100644 (file)
index 0000000..4b89bd5
--- /dev/null
@@ -0,0 +1,70 @@
+/*-
+ * ========================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 org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+
+/**
+ * This class supports front-end web development. Placing this class in the test
+ * area allows excluding the mock configuration classes and the Mockito
+ * dependencies from the packaged version of the app.
+ * 
+ * To launch a development server set the environment variable as listed below.
+ * This runs a Spring-Boot server with mock back-end beans, and keeps the server
+ * alive for manual testing. Supply this JVM argument:
+ * 
+ * <pre>
+ * -Dorg.oransc.ric.portal.dashboard=mock
+ * </pre>
+ */
+@ExtendWith(SpringExtension.class)
+@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
+@ActiveProfiles("test")
+public class DashboardTestServer {
+
+       private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+       /*
+        * Keeps the test server alive forever. Use a guard so this test is never run by
+        * Jenkins.
+        */
+       @EnabledIfSystemProperty(named = "org.oransc.ric.portal.dashboard", matches = "mock")
+       @Test
+       public void keepServerAlive() {
+               logger.warn("Keeping server alive!");
+               try {
+                       synchronized (this) {
+                               this.wait();
+                       }
+               } catch (Exception ex) {
+                       logger.warn(ex.toString());
+               }
+       }
+}
@@ -17,7 +17,7 @@
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
-package org.oransc.ric.portal.dashboard.config;
+package org.oransc.ric.portal.dashboard.test.config;
 
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doAnswer;
@@ -38,7 +38,7 @@ import org.springframework.http.HttpStatus;
 /**
  * Creates a mock implementation of the A1 mediator client API.
  */
-@Profile("mock")
+@Profile("test")
 @Configuration
 public class A1MediatorMockConfiguration {
 
@@ -17,7 +17,7 @@
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
-package org.oransc.ric.portal.dashboard.config;
+package org.oransc.ric.portal.dashboard.test.config;
 
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
@@ -45,7 +45,7 @@ import org.springframework.http.HttpStatus;
 /**
  * Creates a mock implementation of the ANR xApp client APIs.
  */
-@Profile("mock")
+@Profile("test")
 @Configuration
 public class AnrXappMockConfiguration {
 
@@ -17,7 +17,7 @@
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
-package org.oransc.ric.portal.dashboard.config;
+package org.oransc.ric.portal.dashboard.test.config;
 
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doAnswer;
@@ -51,7 +51,7 @@ import org.springframework.http.HttpStatus;
  * Creates an implementation of the xApp manager client that answers requests
  * with mock data.
  */
-@Profile("mock")
+@Profile("test")
 @Configuration
 public class AppManagerMockConfiguration {
 
@@ -17,7 +17,7 @@
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
-package org.oransc.ric.portal.dashboard.config;
+package org.oransc.ric.portal.dashboard.test.config;
 
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doAnswer;
@@ -45,7 +45,7 @@ import org.springframework.http.HttpStatus;
 /**
  * Creates a mock implementation of the E2 Manager client API.
  */
-@Profile("mock")
+@Profile("test")
 @Configuration
 public class E2ManagerMockConfiguration {
 
index b06f9c4..c4d9a4d 100644 (file)
@@ -40,7 +40,7 @@ import org.springframework.web.util.UriComponentsBuilder;
 @ExtendWith(SpringExtension.class)
 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
 // Need the fake answers from the backend
-@ActiveProfiles("mock")
+@ActiveProfiles("test")
 public class AbstractControllerTest {
 
        private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());