From: adheli.tavares Date: Fri, 19 Jul 2024 10:51:37 +0000 (+0100) Subject: Uplift of json schema validator library X-Git-Tag: 4.0.1~11 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=b8c49fd30e2e660198d29e599a0ccecf184b2071;p=policy%2Fapex-pdp.git Uplift of json schema validator library Issue-ID: POLICY-5084 Change-Id: Ie24719570c43a9f7b0fdac28973cc50d8eb7ed2c Signed-off-by: adheli.tavares --- diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/SchemaHelperFactory.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/SchemaHelperFactory.java index 08289e642..3602ce12a 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/SchemaHelperFactory.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/SchemaHelperFactory.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2019-2020, 2024 Nordix Foundation. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -84,7 +84,7 @@ public class SchemaHelperFactory { } // Get the class for the schema helper using reflection - Object schemaHelperObject = null; + Object schemaHelperObject; final String pluginClass = schemaHelperParameters.getSchemaHelperPluginClass(); try { schemaHelperObject = Class.forName(pluginClass).getDeclaredConstructor().newInstance(); @@ -96,7 +96,7 @@ public class SchemaHelperFactory { } // Check the class is a schema helper - if (!(schemaHelperObject instanceof SchemaHelper)) { + if (!(schemaHelperObject instanceof SchemaHelper schemaHelper)) { final var resultString = "Specified Apex context schema helper plugin class \"" + pluginClass + "\" does not implement the SchemaHelper interface"; LOGGER.warn(resultString); @@ -104,7 +104,6 @@ public class SchemaHelperFactory { } // The context schema helper to return - final var schemaHelper = (SchemaHelper) schemaHelperObject; // Lock and load the schema helper schemaHelper.init(owningEntityKey.getKey(), schema); diff --git a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestRestSimEndpoint.java b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestRestSimEndpoint.java index 3d46e6a80..56539a1d7 100644 --- a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestRestSimEndpoint.java +++ b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestRestSimEndpoint.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020-2023 Nordix Foundation. + * Copyright (C) 2020-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,8 @@ package org.onap.policy.apex.examples.grpc; +import static org.awaitility.Awaitility.await; + import jakarta.ws.rs.GET; import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; @@ -28,6 +30,7 @@ import jakarta.ws.rs.core.Response; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.concurrent.TimeUnit; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -52,8 +55,12 @@ public class GrpcTestRestSimEndpoint { public Response dcaeClOutput(@QueryParam("timeout") final int timeout) throws IOException { String createSubscriptionRequest = Files.readString(Paths.get("src/main/resources/examples/events/APEXgRPC/CreateSubscriptionEvent.json")); - LOGGER.info("Create subscription request received: \n {}", createSubscriptionRequest); + LOGGER.info("Create subscription request received (on a timeout of {}): \n {} ", + timeout, createSubscriptionRequest); + await().pollDelay(4, TimeUnit.SECONDS) + .atMost(5, TimeUnit.SECONDS) + .until(() -> true); return Response.status(200).entity(createSubscriptionRequest).build(); } diff --git a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestServerSim.java b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestServerSim.java index 46e0ea254..4dc638551 100644 --- a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestServerSim.java +++ b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestServerSim.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020,2023 Nordix Foundation. + * Copyright (C) 2020, 2023-2024 Nordix Foundation. * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,11 +33,11 @@ import org.onap.policy.simulators.CdsSimulator; */ public class GrpcTestServerSim { private static final String HOST = "localhost"; - private HttpServletServer restServer; - private CdsSimulator grpcServer; + private final HttpServletServer restServer; + private final CdsSimulator grpcServer; /** - * Instantiates a new REST simulator for DMaaP requests. + * Instantiates a new REST simulator for requests. * * @throws InterruptedException interrupted exception * @throws IOException io exception diff --git a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java index ee1744f0e..e6d71e1ff 100644 --- a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java +++ b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java @@ -41,6 +41,7 @@ import org.onap.policy.apex.service.engine.main.ApexMain; * CDS is used to send a final output Log event on POLICY_CL_MGT topic. */ class TestApexGrpcExample { + @Test void testGrpcExample() throws Exception { // @formatter:off @@ -78,18 +79,24 @@ class TestApexGrpcExample { String getLoggedEventUrl = "http://localhost:54321/GrpcTestRestSim/sim/event/getLoggedEvent"; // wait for success response code to be received, until a timeout - await().atMost(20000, TimeUnit.MILLISECONDS).until(() -> - 200 == client.target(getLoggedEventUrl).request("application/json").get().getStatus()); + await().atMost(50000, TimeUnit.MILLISECONDS) + .pollInterval(10000, TimeUnit.MILLISECONDS) + .until(() -> 200 == client.target(getLoggedEventUrl).request("application/json").get().getStatus()); + apexMain.shutdown(); + Response response = client.target(getLoggedEventUrl).request("application/json").get(); sim.tearDown(); + String responseEntity = response.readEntity(String.class); - String expectedLoggedOutputEvent = Files - .readString(Paths.get("src/main/resources/examples/events/APEXgRPC/LogEvent.json")).replaceAll("\r", ""); - String expectedStatusEvent = - Files.readString(Paths.get("src/main/resources/examples/events/APEXgRPC/CDSResponseStatusEvent.json")) - .replaceAll("\r", ""); + var logFileJson = "src/main/resources/examples/events/APEXgRPC/LogEvent.json"; + String expectedLoggedOutputEvent = Files.readString(Paths.get(logFileJson)).replaceAll("\r", ""); + + var cdsResponseJson = "src/main/resources/examples/events/APEXgRPC/CDSResponseStatusEvent.json"; + String expectedStatusEvent = Files.readString(Paths.get(cdsResponseJson)).replaceAll("\r", ""); + // Both LogEvent and CDSResponseStatusEvent are generated from the final state in the policy assertThat(responseEntity).contains(expectedStatusEvent).contains(expectedLoggedOutputEvent); + client.close(); } } \ No newline at end of file diff --git a/model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReader.java b/model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReader.java index 8b0dec7b7..4a8780a4f 100644 --- a/model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReader.java +++ b/model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReader.java @@ -23,7 +23,6 @@ package org.onap.policy.apex.model.policymodel.handling; import static org.onap.policy.apex.model.basicmodel.concepts.AxConcept.WHITESPACE_REGEX; -import org.jetbrains.annotations.NotNull; import org.onap.policy.apex.model.basicmodel.concepts.AxKey; import org.onap.policy.apex.model.policymodel.concepts.AxLogic; import org.onap.policy.apex.model.policymodel.concepts.AxLogicReader; @@ -124,7 +123,7 @@ public class PolicyLogicReader implements AxLogicReader { return logicString.replaceAll(WHITESPACE_REGEX, ""); } - private @NotNull String getFullLogicFilePath(AxLogic axLogic) { + private String getFullLogicFilePath(AxLogic axLogic) { String fullLogicFilePath = logicPackage.replace(".", "/"); // Now, the logic should be in a subdirectory for the logic executor type diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-json/pom.xml b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-json/pom.xml index c46b26271..99864b304 100644 --- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-json/pom.xml +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-json/pom.xml @@ -1,7 +1,7 @@