aboutsummaryrefslogtreecommitdiffstats
path: root/feature-lifecycle/src
diff options
context:
space:
mode:
authoradheli.tavares <adheli.tavares@est.tech>2024-07-19 12:04:46 +0100
committeradheli.tavares <adheli.tavares@est.tech>2024-07-19 12:05:20 +0100
commit9133dabc8566458899d39a7223fcc9c43788febd (patch)
tree509cc81d37da3e31bb606383f4b21d68747899c6 /feature-lifecycle/src
parentc295ebcf3e6c15510e9c0d9a1ae1dd206b403d73 (diff)
Uplift json schema validator library
Issue-ID: POLICY-5084 Change-Id: I426cd992895d4ce4b840ac1ab479152f954cceaf Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'feature-lifecycle/src')
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java14
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java32
2 files changed, 16 insertions, 30 deletions
diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java
index 6740700a..a4abdf37 100644
--- a/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java
+++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021,2023 Nordix Foundation.
+ * Modifications Copyright (C) 2021, 2023-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@
package org.onap.policy.drools.server.restful;
-import com.worldturner.medeia.api.ValidationFailedException;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
@@ -365,14 +364,13 @@ public class RestLifecycleManager implements LifecycleApi {
return Response.status(Response.Status.NOT_ACCEPTABLE).build();
}
- try {
- LifecycleFeature.getFsm().getDomainMaker().conformance(toscaPolicy);
- } catch (ValidationFailedException v) {
- logger.trace("policy {} validation errors: {}", toscaPolicy, v.getMessage(), v);
- return Response.status(Response.Status.NOT_ACCEPTABLE).entity(v.getFailures()).build();
+ var isOk = LifecycleFeature.getFsm().getDomainMaker().conformance(toscaPolicy);
+ if (isOk) {
+ return Response.status(Response.Status.OK).entity(Collections.emptyList()).build();
+ } else {
+ return Response.status(Response.Status.NOT_ACCEPTABLE).entity(Collections.emptyList()).build();
}
- return Response.status(Response.Status.OK).entity(Collections.emptyList()).build();
}
private Response deployUndeployOperation(String policy, boolean deploy) {
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java
index 23d3e24a..fcf946e4 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java
@@ -75,10 +75,6 @@ public class RestLifecycleManagerTest {
private static final String EXAMPLE_NATIVE_ARTIFACT_POLICY_JSON =
"src/test/resources/tosca-policy-native-artifact-example.json";
- private static final String EXAMPLE_OTHER_UNVAL_POLICY_NAME = "other-unvalidated";
- private static final String EXAMPLE_OTHER_UNVAL_POLICY_JSON =
- "src/test/resources/tosca-policy-other-unvalidated.json";
-
private static final String EXAMPLE_OTHER_VAL_POLICY_NAME = "other-validated";
private static final String EXAMPLE_OTHER_VAL_POLICY_JSON =
"src/test/resources/tosca-policy-other-validated.json";
@@ -257,10 +253,6 @@ public class RestLifecycleManagerTest {
}
testNotNativePolicy(opPolicy);
- /* add tosca policy "other-unvalidated" of policy type "type1.type2" with no attached type schema */
-
- testNotNativePolicy(getPolicyFromFile(EXAMPLE_OTHER_UNVAL_POLICY_JSON, EXAMPLE_OTHER_UNVAL_POLICY_NAME));
-
/* add tosca policy "other-validated" of policy type "typeA" with an attached type schema */
testNotNativePolicy(getPolicyFromFile(EXAMPLE_OTHER_VAL_POLICY_JSON, EXAMPLE_OTHER_VAL_POLICY_NAME));
@@ -269,9 +261,7 @@ public class RestLifecycleManagerTest {
ToscaPolicy toscaPolicyValError =
getPolicyFromFile(EXAMPLE_OTHER_VAL_ERROR_POLICY_JSON, EXAMPLE_OTHER_VAL_ERROR_POLICY_NAME);
- assertThat(
- listPost(toString(toscaPolicyValError),
- Status.NOT_ACCEPTABLE.getStatusCode())).isNotEmpty();
+ assertThat(listPost(toString(toscaPolicyValError), Status.NOT_ACCEPTABLE.getStatusCode())).isEmpty();
booleanPost("policies", toString(toscaPolicyValError),
Status.NOT_ACCEPTABLE.getStatusCode(), Boolean.FALSE);
@@ -303,7 +293,7 @@ public class RestLifecycleManagerTest {
/* delete native artifact policy */
- booleanDelete("policies/example.artifact/1.0.0", Status.OK.getStatusCode(), Boolean.TRUE);
+ booleanDelete("policies/example.artifact/1.0.0", Status.OK.getStatusCode());
assertTrue(PolicyControllerConstants.getFactory().get("lifecycle").isAlive());
assertFalse(PolicyControllerConstants.getFactory().get("lifecycle").getDrools().isBrained());
@@ -321,7 +311,7 @@ public class RestLifecycleManagerTest {
/* delete native controller policy */
- booleanDelete("policies/example.controller/1.0.0", Status.OK.getStatusCode(), Boolean.TRUE);
+ booleanDelete("policies/example.controller/1.0.0", Status.OK.getStatusCode());
resourceLists("policyTypes", 2);
get("policyTypes/onap.policies.native.drools.Artifact/1.0.0", Status.OK.getStatusCode());
@@ -337,9 +327,7 @@ public class RestLifecycleManagerTest {
assertThatIllegalArgumentException().isThrownBy(() -> PolicyControllerConstants.getFactory().get("lifecycle"));
opPolicy.getMetadata().remove("policy-id");
- assertThat(
- listPost(toString(opPolicy),
- Status.NOT_ACCEPTABLE.getStatusCode())).isNotEmpty();
+ assertThat(listPost(toString(opPolicy), Status.NOT_ACCEPTABLE.getStatusCode())).isEmpty();
metrics();
}
@@ -362,7 +350,7 @@ public class RestLifecycleManagerTest {
get("policies/example.artifact/1.0.0", Status.OK.getStatusCode());
booleanDelete("policies/" + toscaPolicy.getName() + "/" + toscaPolicy.getVersion(),
- Status.OK.getStatusCode(), Boolean.TRUE);
+ Status.OK.getStatusCode());
assertEquals(0,
PolicyControllerConstants
.getFactory().get("lifecycle").getDrools().facts("junits", ToscaPolicy.class).size());
@@ -400,9 +388,9 @@ public class RestLifecycleManagerTest {
booleanResponse(response, statusCode, bool);
}
- private void booleanDelete(String contextPath, int statusCode, Boolean bool) {
+ private void booleanDelete(String contextPath, int statusCode) {
Response response = client.delete(contextPath, Collections.emptyMap());
- booleanResponse(response, statusCode, bool);
+ booleanResponse(response, statusCode, Boolean.TRUE);
}
private void resourceLists(String resource, int size) {
@@ -462,9 +450,9 @@ public class RestLifecycleManagerTest {
}
private LifecycleFsm newFsmInstance() throws NoSuchFieldException, IllegalAccessException {
- LifecycleFsm fsm = new LifecycleFsm();
- ControllerSupport.setStaticField(LifecycleFeature.class, "fsm", fsm);
- return fsm;
+ LifecycleFsm lifecycleFsm = new LifecycleFsm();
+ ControllerSupport.setStaticField(LifecycleFeature.class, "fsm", lifecycleFsm);
+ return lifecycleFsm;
}
protected ToscaPolicy getPolicyFromFile(String filePath, String policyName) throws CoderException, IOException {