From dfbd081159b02601a48162a647848223a9303ebf Mon Sep 17 00:00:00 2001 From: elinuxhenrik Date: Mon, 16 Dec 2019 16:36:26 +0100 Subject: [PATCH] Change to JUnit5 and clean up pom Change-Id: I9ddf9f621c2e0d405684e35092e8fa522bb5f9f8 Issue-ID: NONRTRIC-81 Signed-off-by: elinuxhenrik --- dashboard/.gitignore | 2 +- policy-agent/pom.xml | 91 ++++++++++++---------- .../java/org/oransc/policyagent/Application.java | 5 +- .../org/oransc/policyagent/clients/A1Client.java | 3 + .../configuration/ApplicationConfig.java | 1 - .../policyagent/controllers/PolicyController.java | 1 + .../oransc/policyagent/controllers/PolicyInfo.java | 2 +- .../policyagent/controllers/PolicyTypeInfo.java | 2 +- .../oransc/policyagent/controllers/RicInfo.java | 2 +- .../policyagent/controllers/ServiceController.java | 1 + .../controllers/ServiceRegistrationInfo.java | 2 +- .../policyagent/controllers/ServiceStatus.java | 1 + .../policyagent/controllers/StatusController.java | 1 + .../oransc/policyagent/repository/Policies.java | 4 - .../org/oransc/policyagent/repository/Policy.java | 1 + .../org/oransc/policyagent/repository/Service.java | 1 + .../org/oransc/policyagent/ApplicationTest.java | 21 +++-- .../org/oransc/policyagent/MockPolicyAgent.java | 1 + .../configuration/ApplicationConfigTest.java | 2 +- .../policyagent/tasks/StartupServiceTest.java | 46 +++++------ pom.xml | 29 ++++--- 21 files changed, 118 insertions(+), 101 deletions(-) diff --git a/dashboard/.gitignore b/dashboard/.gitignore index 675d063c..1fe9c87d 100644 --- a/dashboard/.gitignore +++ b/dashboard/.gitignore @@ -14,7 +14,7 @@ /.classpath /.project /.settings -/target/ +target /.mvn/wrapper/maven-wrapper.jar /.tox diff --git a/policy-agent/pom.xml b/policy-agent/pom.xml index a4388706..d9a28e33 100644 --- a/policy-agent/pom.xml +++ b/policy-agent/pom.xml @@ -21,9 +21,15 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.oransc + + org.springframework.boot + spring-boot-starter-parent + 2.1.6.RELEASE + + + org.o-ran-sc.nonrtric policy-agent 1.0.0-SNAPSHOT @@ -39,12 +45,18 @@ https://nexus.onap.org/content/repositories/releases/ - - org.springframework.boot - spring-boot-starter-parent - 2.1.6.RELEASE - - + + 11 + 2.8.0 + 2.7.1 + 1.1.6 + 2.0.0 + 20180130 + 3.8.0 + 2.8.1 + 1.18.0 + 1.4.13 + org.springframework.boot @@ -70,12 +82,12 @@ io.swagger.core.v3 swagger-jaxrs2 - 2.0.0 + ${swagger.version} io.swagger.core.v3 swagger-jaxrs2-servlet-initializer - 2.0.0 + ${swagger.version} org.immutables @@ -91,7 +103,7 @@ org.json json - 20180130 + ${json.version} @@ -123,17 +135,14 @@ org.junit.jupiter junit-jupiter-engine - ${junit-jupiter.version} test + + org.springframework.boot + spring-boot-configuration-processor + true + - - 11 - 2.8.0 - 2.7.1 - 1.1.6 - 5.4.0 - @@ -143,48 +152,36 @@ net.revelc.code.formatter formatter-maven-plugin - 2.8.1 + ${formatter-maven-plugin.version} ${project.basedir}/eclipse-formatter.xml - + com.diffplug.spotless spotless-maven-plugin - 1.18.0 + ${spotless-maven-plugin.version} - + com,java,javax,org - + org.apache.maven.plugins maven-surefire-plugin - 2.17 false - - com.spotify - dockerfile-maven-plugin - - oransc/policy-agent - ${project.version} - - ${project.build.finalName}.jar - - - org.codehaus.mojo build-helper-maven-plugin @@ -203,6 +200,22 @@ + + com.spotify + dockerfile-maven-plugin + ${dockerfile-maven-plugin.version} + + oransc/policy-agent + ${project.version} + + ${project.build.finalName}.jar + + + + + JIRA + https://jira.o-ran-sc.org/ + diff --git a/policy-agent/src/main/java/org/oransc/policyagent/Application.java b/policy-agent/src/main/java/org/oransc/policyagent/Application.java index fdfca611..eed61e54 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/Application.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/Application.java @@ -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) { diff --git a/policy-agent/src/main/java/org/oransc/policyagent/clients/A1Client.java b/policy-agent/src/main/java/org/oransc/policyagent/clients/A1Client.java index 9ad5dd76..8006b7b9 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/clients/A1Client.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/clients/A1Client.java @@ -17,8 +17,11 @@ * limitations under the License. * ========================LICENSE_END=================================== */ + package org.oransc.policyagent.clients; + + import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; diff --git a/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfig.java b/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfig.java index c5cd44af..e41f55eb 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfig.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfig.java @@ -194,5 +194,4 @@ public class ApplicationConfig { InputStream createInputStream(@NotNull String filepath) throws IOException { return new BufferedInputStream(new FileInputStream(filepath)); } - } diff --git a/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java b/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java index c0932a4c..12fa02c0 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java @@ -17,6 +17,7 @@ * limitations under the License. * ========================LICENSE_END=================================== */ + package org.oransc.policyagent.controllers; import com.google.gson.Gson; diff --git a/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyInfo.java b/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyInfo.java index cd45f9ed..b8df47e7 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyInfo.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyInfo.java @@ -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; diff --git a/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyTypeInfo.java b/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyTypeInfo.java index ae93b5e1..62a7196d 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyTypeInfo.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyTypeInfo.java @@ -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; diff --git a/policy-agent/src/main/java/org/oransc/policyagent/controllers/RicInfo.java b/policy-agent/src/main/java/org/oransc/policyagent/controllers/RicInfo.java index bfb5b36e..19e43322 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/controllers/RicInfo.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/controllers/RicInfo.java @@ -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; diff --git a/policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceController.java b/policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceController.java index 86335b66..47123f20 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceController.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceController.java @@ -17,6 +17,7 @@ * limitations under the License. * ========================LICENSE_END=================================== */ + package org.oransc.policyagent.controllers; import com.google.gson.Gson; diff --git a/policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceRegistrationInfo.java b/policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceRegistrationInfo.java index 6ffaebd3..705eafb6 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceRegistrationInfo.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceRegistrationInfo.java @@ -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; diff --git a/policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceStatus.java b/policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceStatus.java index 64647b88..3063c6bc 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceStatus.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceStatus.java @@ -17,6 +17,7 @@ * limitations under the License. * ========================LICENSE_END=================================== */ + package org.oransc.policyagent.controllers; import com.google.gson.annotations.SerializedName; diff --git a/policy-agent/src/main/java/org/oransc/policyagent/controllers/StatusController.java b/policy-agent/src/main/java/org/oransc/policyagent/controllers/StatusController.java index 6f86173d..226ee736 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/controllers/StatusController.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/controllers/StatusController.java @@ -17,6 +17,7 @@ * limitations under the License. * ========================LICENSE_END=================================== */ + package org.oransc.policyagent.controllers; import io.swagger.annotations.ApiOperation; diff --git a/policy-agent/src/main/java/org/oransc/policyagent/repository/Policies.java b/policy-agent/src/main/java/org/oransc/policyagent/repository/Policies.java index daaa193c..9895ff11 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/repository/Policies.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/repository/Policies.java @@ -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 policiesId = new HashMap<>(); private Map> policiesRic = new HashMap<>(); private Map> policiesService = new HashMap<>(); diff --git a/policy-agent/src/main/java/org/oransc/policyagent/repository/Policy.java b/policy-agent/src/main/java/org/oransc/policyagent/repository/Policy.java index 038e484e..51482262 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/repository/Policy.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/repository/Policy.java @@ -17,6 +17,7 @@ * limitations under the License. * ========================LICENSE_END=================================== */ + package org.oransc.policyagent.repository; import org.immutables.gson.Gson; diff --git a/policy-agent/src/main/java/org/oransc/policyagent/repository/Service.java b/policy-agent/src/main/java/org/oransc/policyagent/repository/Service.java index 6a26b98e..512d065b 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/repository/Service.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/repository/Service.java @@ -17,6 +17,7 @@ * limitations under the License. * ========================LICENSE_END=================================== */ + package org.oransc.policyagent.repository; import java.time.Duration; diff --git a/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java b/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java index df26ba4f..b3e2c983 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java @@ -17,10 +17,11 @@ * 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 List parseList(String json, Class clazz) { + private static List parseList(String json, Class 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"); diff --git a/policy-agent/src/test/java/org/oransc/policyagent/MockPolicyAgent.java b/policy-agent/src/test/java/org/oransc/policyagent/MockPolicyAgent.java index b7ea7dd1..dda64269 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/MockPolicyAgent.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/MockPolicyAgent.java @@ -17,6 +17,7 @@ * limitations under the License. * ========================LICENSE_END=================================== */ + package org.oransc.policyagent; import com.google.gson.JsonObject; diff --git a/policy-agent/src/test/java/org/oransc/policyagent/configuration/ApplicationConfigTest.java b/policy-agent/src/test/java/org/oransc/policyagent/configuration/ApplicationConfigTest.java index 34ebdf99..2680608d 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/configuration/ApplicationConfigTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/configuration/ApplicationConfigTest.java @@ -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; diff --git a/policy-agent/src/test/java/org/oransc/policyagent/tasks/StartupServiceTest.java b/policy-agent/src/test/java/org/oransc/policyagent/tasks/StartupServiceTest.java index 4dcceb6c..fd98e07a 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/tasks/StartupServiceTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/tasks/StartupServiceTest.java @@ -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 f7e42ab6..0a9184fa 100644 --- a/pom.xml +++ b/pom.xml @@ -19,20 +19,19 @@ ============LICENSE_END========================================================= --> - 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"> + 4.0.0 - org.oransc - nonrtric - 1.0.0-SNAPSHOT - pom + org.o-ran-sc + nonrtric + 1.0.0-SNAPSHOT + pom - nonrtric - - dashboard - near-rt-ric-simulator - sdnc-a1-controller - policy-agent - - + nonrtric + + policy-agent + dashboard + near-rt-ric-simulator + + -- 2.16.6