X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=policy-agent%2Fsrc%2Ftest%2Fjava%2Forg%2Foransc%2Fpolicyagent%2Fconfiguration%2FApplicationConfigParserTest.java;h=6b106c93166c02b5e18137cfaa89dba7694bfe05;hb=2310d1c6a458bd12b2d1ff805f1bd12dcd536cfa;hp=02c84db878a9ccecc2c26b14b0221c9508a699d5;hpb=7c297ddb425a52dae965adc6a83629a14421ea05;p=nonrtric.git diff --git a/policy-agent/src/test/java/org/oransc/policyagent/configuration/ApplicationConfigParserTest.java b/policy-agent/src/test/java/org/oransc/policyagent/configuration/ApplicationConfigParserTest.java index 02c84db8..6b106c93 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/configuration/ApplicationConfigParserTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/configuration/ApplicationConfigParserTest.java @@ -39,6 +39,7 @@ import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.util.Map; import java.util.Properties; import org.junit.jupiter.api.Test; @@ -46,17 +47,17 @@ import org.onap.dmaap.mr.test.clients.ProtocolTypeConstants; import org.oransc.policyagent.exceptions.ServiceException; import org.springframework.http.MediaType; -public class ApplicationConfigParserTest { +class ApplicationConfigParserTest { ApplicationConfigParser parserUnderTest = new ApplicationConfigParser(); @Test - public void whenCorrectDmaapConfig() throws Exception { + void whenCorrectConfig() throws Exception { JsonObject jsonRootObject = getJsonRootObject(); - parserUnderTest.parse(jsonRootObject); + ApplicationConfigParser.ConfigParserResult result = parserUnderTest.parse(jsonRootObject); - Properties actualPublisherConfig = parserUnderTest.getDmaapPublisherConfig(); + Properties actualPublisherConfig = result.dmaapPublisherConfig(); assertAll("publisherConfig", () -> assertEquals("localhost:6845/events", actualPublisherConfig.get("ServiceName"), "Wrong ServiceName"), () -> assertEquals("A1-POLICY-AGENT-WRITE", actualPublisherConfig.get("topic"), "Wrong topic"), @@ -67,10 +68,10 @@ public class ApplicationConfigParserTest { () -> assertEquals("admin", actualPublisherConfig.get("password"), "Wrong password"), () -> assertEquals(ProtocolTypeConstants.HTTPNOAUTH.toString(), actualPublisherConfig.get("TransportType"), "Wrong TransportType"), - () -> assertEquals(15000, actualPublisherConfig.get("timeout"), "Wrong timeout"), - () -> assertEquals(100, actualPublisherConfig.get("limit"), "Wrong limit")); + () -> assertEquals("15000", actualPublisherConfig.get("timeout"), "Wrong timeout"), + () -> assertEquals("100", actualPublisherConfig.get("limit"), "Wrong limit")); - Properties actualConsumerConfig = parserUnderTest.getDmaapConsumerConfig(); + Properties actualConsumerConfig = result.dmaapConsumerConfig(); assertAll("consumerConfig", () -> assertEquals("localhost:6845/events", actualConsumerConfig.get("ServiceName"), "Wrong ServiceName"), () -> assertEquals("A1-POLICY-AGENT-READ", actualConsumerConfig.get("topic"), "Wrong topic"), @@ -83,8 +84,18 @@ public class ApplicationConfigParserTest { () -> assertEquals("policy-agent", actualConsumerConfig.get("id"), "Wrong id"), () -> assertEquals(ProtocolTypeConstants.HTTPNOAUTH.toString(), actualConsumerConfig.get("TransportType"), "Wrong TransportType"), - () -> assertEquals(15000, actualConsumerConfig.get("timeout"), "Wrong timeout"), - () -> assertEquals(100, actualConsumerConfig.get("limit"), "Wrong limit")); + () -> assertEquals("15000", actualConsumerConfig.get("timeout"), "Wrong timeout"), + () -> assertEquals("100", actualConsumerConfig.get("limit"), "Wrong limit")); + + Map controllers = result.controllerConfigs(); + assertEquals(1, controllers.size(), "size"); + ImmutableControllerConfig expectedControllerConfig = ImmutableControllerConfig.builder() // + .baseUrl("http://localhost:8083/") // + .name("controller1") // + .userName("user") // + .password("password") // + .build(); // + assertEquals(expectedControllerConfig, controllers.get("controller1"), "controller contents"); } private JsonObject getJsonRootObject() throws JsonIOException, JsonSyntaxException, IOException { @@ -100,7 +111,7 @@ public class ApplicationConfigParserTest { } @Test - public void whenDmaapConfigHasSeveralStreamsPublishing() throws Exception { + void whenDmaapConfigHasSeveralStreamsPublishing() throws Exception { JsonObject jsonRootObject = getJsonRootObject(); JsonObject json = jsonRootObject.getAsJsonObject("config").getAsJsonObject("streams_publishes"); JsonObject fake_info_object = new JsonObject(); @@ -120,6 +131,7 @@ public class ApplicationConfigParserTest { private JsonObject dmaap_publisher; private JsonObject fake_info_object; + @Override public String toString() { return String.format("[dmaap_publisher=%s, fake_info_object=%s]", dmaap_publisher.toString(), fake_info_object.toString()); @@ -127,7 +139,7 @@ public class ApplicationConfigParserTest { } @Test - public void whenDmaapConfigHasSeveralStreamsSubscribing() throws Exception { + void whenDmaapConfigHasSeveralStreamsSubscribing() throws Exception { JsonObject jsonRootObject = getJsonRootObject(); JsonObject json = jsonRootObject.getAsJsonObject("config").getAsJsonObject("streams_subscribes"); JsonObject fake_info_object = new JsonObject(); @@ -147,6 +159,7 @@ public class ApplicationConfigParserTest { private JsonObject dmaap_subscriber; private JsonObject fake_info_object; + @Override public String toString() { return String.format("[dmaap_subscriber=%s, fake_info_object=%s]", dmaap_subscriber.toString(), fake_info_object.toString()); @@ -154,7 +167,7 @@ public class ApplicationConfigParserTest { } @Test - public void whenMalformedUrlStreamsSubscribing() throws Exception { + void whenMalformedUrlStreamsSubscribing() throws Exception { JsonObject jsonRootObject = getJsonRootObject(); final String wrongTopicUrl = "WrongTopicUrl"; JsonObject json = getDmaapInfo(jsonRootObject, "streams_subscribes", "dmaap_subscriber"); @@ -170,7 +183,7 @@ public class ApplicationConfigParserTest { } @Test - public void whenMalformedUrlStreamsPublishing() throws Exception { + void whenMalformedUrlStreamsPublishing() throws Exception { JsonObject jsonRootObject = getJsonRootObject(); final String wrongTopicUrl = "WrongTopicUrl"; JsonObject json = getDmaapInfo(jsonRootObject, "streams_publishes", "dmaap_publisher"); @@ -186,11 +199,11 @@ public class ApplicationConfigParserTest { } @Test - public void whenWrongMemberNameInObject() throws Exception { + void whenWrongMemberNameInObject() throws Exception { JsonObject jsonRootObject = getJsonRootObject(); JsonObject json = jsonRootObject.getAsJsonObject("config"); json.remove("ric"); - final String message = "Could not find member: ric in: " + json; + final String message = "Could not find member: 'ric' in: " + json; Exception actualException = assertThrows(ServiceException.class, () -> parserUnderTest.parse(jsonRootObject)); @@ -198,7 +211,7 @@ public class ApplicationConfigParserTest { } @Test - public void whenWrongUrlPathStreamsSubscribing() throws Exception { + void whenWrongUrlPathStreamsSubscribing() throws Exception { JsonObject jsonRootObject = getJsonRootObject(); final String wrongTopicUrlString = "http://admin:admin@localhost:6845/events/A1-POLICY-AGENT-READ/users/policy-agent/wrong-topic-url"; @@ -214,7 +227,7 @@ public class ApplicationConfigParserTest { } @Test - public void whenWrongUrlPathStreamsPublishing() throws Exception { + void whenWrongUrlPathStreamsPublishing() throws Exception { JsonObject jsonRootObject = getJsonRootObject(); final String wrongTopicUrlString = "http://admin:admin@localhost:6845/events/A1-POLICY-AGENT-WRITE/wrong-topic-url"; @@ -229,7 +242,7 @@ public class ApplicationConfigParserTest { "Wrong error message when the streams publishes' URL has incorrect syntax"); } - public JsonObject getDmaapInfo(JsonObject jsonRootObject, String streamsPublishesOrSubscribes, + JsonObject getDmaapInfo(JsonObject jsonRootObject, String streamsPublishesOrSubscribes, String dmaapPublisherOrSubscriber) throws Exception { return jsonRootObject.getAsJsonObject("config").getAsJsonObject(streamsPublishesOrSubscribes) .getAsJsonObject(dmaapPublisherOrSubscriber).getAsJsonObject("dmaap_info");