Change to JUnit5 and clean up pom 37/2037/2
authorelinuxhenrik <henrik.b.andersson@est.tech>
Mon, 16 Dec 2019 15:36:26 +0000 (16:36 +0100)
committerelinuxhenrik <henrik.b.andersson@est.tech>
Mon, 16 Dec 2019 16:37:09 +0000 (17:37 +0100)
Change-Id: I9ddf9f621c2e0d405684e35092e8fa522bb5f9f8
Issue-ID: NONRTRIC-81
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
21 files changed:
dashboard/.gitignore
policy-agent/pom.xml
policy-agent/src/main/java/org/oransc/policyagent/Application.java
policy-agent/src/main/java/org/oransc/policyagent/clients/A1Client.java
policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfig.java
policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java
policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyInfo.java
policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyTypeInfo.java
policy-agent/src/main/java/org/oransc/policyagent/controllers/RicInfo.java
policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceController.java
policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceRegistrationInfo.java
policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceStatus.java
policy-agent/src/main/java/org/oransc/policyagent/controllers/StatusController.java
policy-agent/src/main/java/org/oransc/policyagent/repository/Policies.java
policy-agent/src/main/java/org/oransc/policyagent/repository/Policy.java
policy-agent/src/main/java/org/oransc/policyagent/repository/Service.java
policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java
policy-agent/src/test/java/org/oransc/policyagent/MockPolicyAgent.java
policy-agent/src/test/java/org/oransc/policyagent/configuration/ApplicationConfigTest.java
policy-agent/src/test/java/org/oransc/policyagent/tasks/StartupServiceTest.java
pom.xml

index 675d063..1fe9c87 100644 (file)
@@ -14,7 +14,7 @@
 /.classpath
 /.project
 /.settings
-/target/
+target
 /.mvn/wrapper/maven-wrapper.jar
 /.tox
 
index a438870..d9a28e3 100644 (file)
 <project
     xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
-    <groupId>org.oransc</groupId>
+    <parent>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>2.1.6.RELEASE</version>
+        <relativePath />
+    </parent>
+    <groupId>org.o-ran-sc.nonrtric</groupId>
     <artifactId>policy-agent</artifactId>
     <version>1.0.0-SNAPSHOT</version>
     <licenses>
             <url>https://nexus.onap.org/content/repositories/releases/</url>
         </repository>
     </repositories>
-    <parent>
-        <groupId>org.springframework.boot</groupId>
-        <artifactId>spring-boot-starter-parent</artifactId>
-        <version>2.1.6.RELEASE</version>
-        <relativePath />
-    </parent>
+    <properties>
+        <java.version>11</java.version>
+        <springfox.version>2.8.0</springfox.version>
+        <immutable.version>2.7.1</immutable.version>
+        <sdk.version>1.1.6</sdk.version>
+        <swagger.version>2.0.0</swagger.version>
+        <json.version>20180130</json.version>
+        <maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
+        <formatter-maven-plugin.version>2.8.1</formatter-maven-plugin.version>
+        <spotless-maven-plugin.version>1.18.0</spotless-maven-plugin.version>
+        <dockerfile-maven-plugin.version>1.4.13</dockerfile-maven-plugin.version>
+    </properties>
     <dependencies>
         <dependency>
             <groupId>org.springframework.boot</groupId>
         <dependency>
             <groupId>io.swagger.core.v3</groupId>
             <artifactId>swagger-jaxrs2</artifactId>
-            <version>2.0.0</version>
+            <version>${swagger.version}</version>
         </dependency>
         <dependency>
             <groupId>io.swagger.core.v3</groupId>
             <artifactId>swagger-jaxrs2-servlet-initializer</artifactId>
-            <version>2.0.0</version>
+            <version>${swagger.version}</version>
         </dependency>
         <dependency>
             <groupId>org.immutables</groupId>
         <dependency>
             <groupId>org.json</groupId>
             <artifactId>json</artifactId>
-            <version>20180130</version>
+            <version>${json.version}</version>
         </dependency>
         <!--TEST -->
         <dependency>
         <dependency>
             <groupId>org.junit.jupiter</groupId>
             <artifactId>junit-jupiter-engine</artifactId>
-            <version>${junit-jupiter.version}</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-configuration-processor</artifactId>
+            <optional>true</optional>
+        </dependency>
     </dependencies>
-    <properties>
-        <java.version>11</java.version>
-        <springfox.version>2.8.0</springfox.version>
-        <immutable.version>2.7.1</immutable.version>
-        <sdk.version>1.1.6</sdk.version>
-        <junit-jupiter.version>5.4.0</junit-jupiter.version>
-    </properties>
     <build>
         <plugins>
             <plugin>
             <plugin>
                 <groupId>net.revelc.code.formatter</groupId>
                 <artifactId>formatter-maven-plugin</artifactId>
-                <version>2.8.1</version>
+                <version>${formatter-maven-plugin.version}</version>
                 <configuration>
                     <configFile>${project.basedir}/eclipse-formatter.xml</configFile>
                 </configuration>
-                <!-- https://code.revelc.net/formatter-maven-plugin/ use 
-                 mvn formatter:format spotless:apply process-sources -->
+                <!-- https://code.revelc.net/formatter-maven-plugin/ use
+                    mvn formatter:format spotless:apply process-sources -->
             </plugin>
             <plugin>
                 <groupId>com.diffplug.spotless</groupId>
                 <artifactId>spotless-maven-plugin</artifactId>
-                <version>1.18.0</version>
+                <version>${spotless-maven-plugin.version}</version>
                 <configuration>
                     <java>
-                        <removeUnusedImports/>
+                        <removeUnusedImports />
                         <importOrder>
                             <order>com,java,javax,org</order>
                         </importOrder>
                     </java>
                 </configuration>
-                <!-- https://github.com/diffplug/spotless/tree/master/plugin-maven use 
-                        mvn spotless:apply to rewrite source files use mvn spotless:check to validate 
-                        source files -->
+                <!-- https://github.com/diffplug/spotless/tree/master/plugin-maven
+                    use mvn spotless:apply to rewrite source files use mvn spotless:check to
+                    validate source files -->
             </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
-                <version>2.17</version>
                 <configuration>
                     <skipTests>false</skipTests>
                 </configuration>
             </plugin>
-            <plugin>
-                <groupId>com.spotify</groupId>
-                <artifactId>dockerfile-maven-plugin</artifactId>
-                <configuration>
-                    <repository>oransc/policy-agent</repository>
-                    <tag>${project.version}</tag>
-                    <buildArgs>
-                        <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
-                    </buildArgs>
-                </configuration>
-            </plugin>
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>build-helper-maven-plugin</artifactId>
                     </execution>
                 </executions>
             </plugin>
+            <plugin>
+                <groupId>com.spotify</groupId>
+                <artifactId>dockerfile-maven-plugin</artifactId>
+                <version>${dockerfile-maven-plugin.version}</version>
+                <configuration>
+                    <repository>oransc/policy-agent</repository>
+                    <tag>${project.version}</tag>
+                    <buildArgs>
+                        <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
+                    </buildArgs>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
+    <issueManagement>
+        <system>JIRA</system>
+        <url>https://jira.o-ran-sc.org/</url>
+    </issueManagement>
 </project>
index fdfca61..eed61e5 100644 (file)
@@ -41,8 +41,9 @@ public class Application {
     /**
      * Starts the service and reads the configuration.
      *
-     * @param ctx
-     * @return
+     * @param ctx the application context.
+     *
+     * @return the command line runner performing tasks at startup.
      */
     @Bean
     public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
index 9ad5dd7..8006b7b 100644 (file)
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
+
 package org.oransc.policyagent.clients;
 
+
+
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
index c5cd44a..e41f55e 100644 (file)
@@ -194,5 +194,4 @@ public class ApplicationConfig {
     InputStream createInputStream(@NotNull String filepath) throws IOException {
         return new BufferedInputStream(new FileInputStream(filepath));
     }
-
 }
index c0932a4..12fa02c 100644 (file)
@@ -17,6 +17,7 @@
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
+
 package org.oransc.policyagent.controllers;
 
 import com.google.gson.Gson;
index cd45f9e..b8df47e 100644 (file)
@@ -17,8 +17,8 @@
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
-package org.oransc.policyagent.controllers;
 
+package org.oransc.policyagent.controllers;
 import org.immutables.gson.Gson;
 import org.immutables.value.Value;
 
index ae93b5e..62a7196 100644 (file)
@@ -17,8 +17,8 @@
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
-package org.oransc.policyagent.controllers;
 
+package org.oransc.policyagent.controllers;
 import org.immutables.gson.Gson;
 import org.immutables.value.Value;
 
index bfb5b36..19e4332 100644 (file)
@@ -17,8 +17,8 @@
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
-package org.oransc.policyagent.controllers;
 
+package org.oransc.policyagent.controllers;
 import java.util.Vector;
 
 import org.immutables.gson.Gson;
index 86335b6..47123f2 100644 (file)
@@ -17,6 +17,7 @@
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
+
 package org.oransc.policyagent.controllers;
 
 import com.google.gson.Gson;
index 6ffaebd..705eafb 100644 (file)
@@ -17,8 +17,8 @@
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
-package org.oransc.policyagent.controllers;
 
+package org.oransc.policyagent.controllers;
 import org.immutables.gson.Gson;
 import org.immutables.value.Value;
 
index 64647b8..3063c6b 100644 (file)
@@ -17,6 +17,7 @@
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
+
 package org.oransc.policyagent.controllers;
 
 import com.google.gson.annotations.SerializedName;
index 6f86173..226ee73 100644 (file)
@@ -17,6 +17,7 @@
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
+
 package org.oransc.policyagent.controllers;
 
 import io.swagger.annotations.ApiOperation;
index daaa193..9895ff1 100644 (file)
@@ -26,12 +26,8 @@ import java.util.Map;
 import java.util.Vector;
 
 import org.oransc.policyagent.exceptions.ServiceException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public class Policies {
-    private static final Logger logger = LoggerFactory.getLogger(Policies.class);
-
     private Map<String, Policy> policiesId = new HashMap<>();
     private Map<String, Map<String, Policy>> policiesRic = new HashMap<>();
     private Map<String, Map<String, Policy>> policiesService = new HashMap<>();
index 038e484..5148226 100644 (file)
@@ -17,6 +17,7 @@
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
+
 package org.oransc.policyagent.repository;
 
 import org.immutables.gson.Gson;
index 6a26b98..512d065 100644 (file)
@@ -17,6 +17,7 @@
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
+
 package org.oransc.policyagent.repository;
 
 import java.time.Duration;
index df26ba4..b3e2c98 100644 (file)
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
+
 package org.oransc.policyagent;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
@@ -30,9 +31,8 @@ import java.net.URL;
 import java.util.List;
 import java.util.Vector;
 
-import org.junit.Test;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.oransc.policyagent.configuration.ApplicationConfig;
 import org.oransc.policyagent.configuration.ImmutableRicConfig;
 import org.oransc.policyagent.configuration.RicConfig;
@@ -58,10 +58,10 @@ import org.springframework.boot.web.server.LocalServerPort;
 import org.springframework.context.annotation.Bean;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
 import org.springframework.web.client.RestTemplate;
 
-@RunWith(SpringRunner.class)
+@ExtendWith(SpringExtension.class)
 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
 public class ApplicationTest {
 
@@ -87,7 +87,7 @@ public class ApplicationTest {
     }
 
     /**
-     * overrides the BeanFactory
+     * Overrides the BeanFactory.
      */
     @TestConfiguration
     static class TestBeanFactory {
@@ -103,8 +103,7 @@ public class ApplicationTest {
 
     private final RestTemplate restTemplate = new RestTemplate();
 
-    @BeforeEach
-    public void reset() {
+    private void reset() {
         rics.clear();
         policies.clear();
         policyTypes.clear();
@@ -213,7 +212,7 @@ public class ApplicationTest {
         assertThat(policies.size()).isEqualTo(0);
     }
 
-    public static <T> List<T> parseList(String json, Class<T> clazz) {
+    private static <T> List<T> parseList(String json, Class<T> clazz) {
         if (null == json) {
             return null;
         }
@@ -222,11 +221,11 @@ public class ApplicationTest {
 
     @Test
     public void testGetPolicyTypes() throws Exception {
-        String url = baseUrl() + "/policy_types";
         reset();
         addPolicy("id1", "type1", "service1");
         addPolicy("id2", "type2", "service2");
 
+        String url = baseUrl() + "/policy_types";
         String rsp = this.restTemplate.getForObject(url, String.class);
         System.out.println(rsp);
         assertThat(rsp).contains("type1");
index b7ea7dd..dda6426 100644 (file)
@@ -17,6 +17,7 @@
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
+
 package org.oransc.policyagent;
 
 import com.google.gson.JsonObject;
index 34ebdf9..2680608 100644 (file)
@@ -21,7 +21,7 @@
 package org.oransc.policyagent.configuration;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
index 4dcceb6..fd98e07 100644 (file)
@@ -20,9 +20,9 @@
 
 package org.oransc.policyagent.tasks;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
@@ -88,30 +88,30 @@ public class StartupServiceTest {
         verify(ricClientMock).getPolicyTypes(SECOND_RIC_URL);
         verifyNoMoreInteractions(ricClientMock);
 
-        assertEquals("Not correct number of policy types added.", 2, policyTypes.size());
-        assertEquals("Not correct type added.", type1, policyTypes.getType(POLICY_TYPE_1_NAME));
-        assertEquals("Not correct type added.", type2, policyTypes.getType(POLICY_TYPE_2_NAME));
-        assertEquals("Correct nymber of Rics not added to Rics", 2, rics.size());
+        assertEquals(2, policyTypes.size(), "Not correct number of policy types added.");
+        assertEquals(type1, policyTypes.getType(POLICY_TYPE_1_NAME), "Not correct type added.");
+        assertEquals(type2, policyTypes.getType(POLICY_TYPE_2_NAME), "Not correct type added.");
+        assertEquals(2, rics.size(), "Correct nymber of Rics not added to Rics");
 
         Ric firstRic = rics.getRic(FIRST_RIC_NAME);
-        assertNotNull("Ric \"" + FIRST_RIC_NAME + "\" not added to repositpry", firstRic);
-        assertEquals("Not correct Ric \"" + FIRST_RIC_NAME + "\" added to Rics", FIRST_RIC_NAME, firstRic.name());
-        assertEquals("Not correct state for \"" + FIRST_RIC_NAME + "\"", ACTIVE, firstRic.state());
-        assertEquals("Not correct no of types supported", 1, firstRic.getSupportedPolicyTypes().size());
-        assertTrue("Not correct type supported", firstRic.isSupportingType(type1));
-        assertEquals("Not correct no of managed nodes", 1, firstRic.getManagedNodes().size());
-        assertTrue("Not managed by node", firstRic.isManaging(MANAGED_NODE_A));
+        assertNotNull(firstRic, "Ric \"" + FIRST_RIC_NAME + "\" not added to repositpry");
+        assertEquals(FIRST_RIC_NAME, firstRic.name(), "Not correct Ric \"" + FIRST_RIC_NAME + "\" added to Rics");
+        assertEquals(ACTIVE, firstRic.state(), "Not correct state for \"" + FIRST_RIC_NAME + "\"");
+        assertEquals(1, firstRic.getSupportedPolicyTypes().size(), "Not correct no of types supported");
+        assertTrue(firstRic.isSupportingType(type1), "Not correct type supported");
+        assertEquals(1, firstRic.getManagedNodes().size(), "Not correct no of managed nodes");
+        assertTrue(firstRic.isManaging(MANAGED_NODE_A), "Not managed by node");
 
         Ric secondRic = rics.getRic(SECOND_RIC_NAME);
-        assertNotNull("Ric \"" + SECOND_RIC_NAME + "\" not added to repositpry", secondRic);
-        assertEquals("Not correct Ric \"" + SECOND_RIC_NAME + "\" added to Rics", SECOND_RIC_NAME, secondRic.name());
-        assertEquals("Not correct state for \"" + SECOND_RIC_NAME + "\"", ACTIVE, secondRic.state());
-        assertEquals("Not correct no of types supported", 2, secondRic.getSupportedPolicyTypes().size());
-        assertTrue("Not correct type supported", secondRic.isSupportingType(type1));
-        assertTrue("Not correct type supported", secondRic.isSupportingType(type2));
-        assertEquals("Not correct no of managed nodes", 2, secondRic.getManagedNodes().size());
-        assertTrue("Not correct managed node", secondRic.isManaging(MANAGED_NODE_B));
-        assertTrue("Not correct managed node", secondRic.isManaging(MANAGED_NODE_C));
+        assertNotNull(secondRic, "Ric \"" + SECOND_RIC_NAME + "\" not added to repositpry");
+        assertEquals(SECOND_RIC_NAME, secondRic.name(), "Not correct Ric \"" + SECOND_RIC_NAME + "\" added to Rics");
+        assertEquals(ACTIVE, secondRic.state(), "Not correct state for \"" + SECOND_RIC_NAME + "\"");
+        assertEquals(2, secondRic.getSupportedPolicyTypes().size(), "Not correct no of types supported");
+        assertTrue(secondRic.isSupportingType(type1), "Not correct type supported");
+        assertTrue(secondRic.isSupportingType(type2), "Not correct type supported");
+        assertEquals(2, secondRic.getManagedNodes().size(), "Not correct no of managed nodes");
+        assertTrue(secondRic.isManaging(MANAGED_NODE_B), "Not correct managed node");
+        assertTrue(secondRic.isManaging(MANAGED_NODE_C), "Not correct managed node");
     }
 
     private RicConfig getRicConfig(String name, String baseUrl, String... nodeNames) {
diff --git a/pom.xml b/pom.xml
index f7e42ab..0a9184f 100644 (file)
--- a/pom.xml
+++ b/pom.xml
   ============LICENSE_END=========================================================
 -->
 <project xmlns="http://maven.apache.org/POM/4.0.0"
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-       <modelVersion>4.0.0</modelVersion>
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
 
-       <groupId>org.oransc</groupId>
-       <artifactId>nonrtric</artifactId>
-       <version>1.0.0-SNAPSHOT</version>
-       <packaging>pom</packaging>
+    <groupId>org.o-ran-sc</groupId>
+    <artifactId>nonrtric</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+    <packaging>pom</packaging>
 
-       <name>nonrtric</name>
-       <modules>
-               <module>dashboard</module>
-               <module>near-rt-ric-simulator</module>
-               <module>sdnc-a1-controller</module>
-                <module>policy-agent</module>
-       </modules>
-</project>
+    <name>nonrtric</name>
+    <modules>
+        <module>policy-agent</module>
+        <module>dashboard</module>
+        <module>near-rt-ric-simulator</module>
+    </modules>
+ </project>