summaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src/test
diff options
context:
space:
mode:
authorPatrikBuhr <patrik.buhr@est.tech>2021-10-07 18:03:53 +0200
committerPatrikBuhr <patrik.buhr@est.tech>2021-10-15 15:48:52 +0200
commit3b916e4dc5777863cb4ee873b41ee460fb9aec27 (patch)
treeda8003e728de8f9ca8d7a9a4369c20b16c1f6531 /a1-policy-management/src/test
parente81a9de40bc0acb4a15ecf9fd60500a6f71344e4 (diff)
Improving searching for policy types - A1 Jakarta
The querying for supported policy types is enhanced so that an application can get a list of all policy types that are compatible with a given version. This means added query parameters for GET types. Simplified exception handling. Issue-ID: CCSDK-3495 Signed-off-by: PatrikBuhr <patrik.buhr@est.tech> Change-Id: Iedc2267e4fe2b5e2c17d688e315893c354379930
Diffstat (limited to 'a1-policy-management/src/test')
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java59
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/EnvironmentProcessorTest.java11
2 files changed, 59 insertions, 11 deletions
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java
index 08350f81..f18953c4 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java
@@ -597,22 +597,55 @@ class ApplicationTest {
@Test
void testGetPolicyTypes() throws Exception {
- addPolicyType("type1", "ric1");
- addPolicyType("type2", "ric2");
+ String TYPE_ID_1 = "A_type1_1.9.0";
+ String TYPE_ID_2 = "A_type1_2.0.0";
+ String TYPE_ID_3 = "A_type1_1.5.0";
+ String TYPE_ID_4 = "type3_1.9.0";
+ addPolicyType(TYPE_ID_1, "ric1");
+ addPolicyType(TYPE_ID_2, "ric2");
+ addPolicyType(TYPE_ID_3, "ric2");
+ addPolicyType(TYPE_ID_4, "ric2");
+
+ addPolicyType("junk", "ric2");
+ addPolicyType("junk_a.b.c", "ric2");
String url = "/policy-types";
String rsp = restClient().get(url).block();
- String expResp = createPolicyTypesJson("type2", "type1");
- assertThat(rsp).isEqualTo(expResp);
+ assertThat(rsp).contains(TYPE_ID_1, TYPE_ID_2);
url = "/policy-types?ric_id=ric1";
rsp = restClient().get(url).block();
- expResp = createPolicyTypesJson("type1");
+ String expResp = createPolicyTypesJson(TYPE_ID_1);
assertThat(rsp).isEqualTo(expResp);
// Get policy types for non existing RIC
url = "/policy-types?ric_id=ric1XXX";
testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
+
+ // All types with a type_name
+ url = "/policy-types?type_name=A_type1";
+ rsp = restClient().get(url).block();
+ assertThat(rsp).contains(TYPE_ID_1, TYPE_ID_2);
+
+ // All types compatible with type1_1.5.0 (which is type1_1.9.0)
+ url = "/policy-types?type_name=A_type1&&compatible_with_version=1.5.0";
+ rsp = restClient().get(url).block();
+ expResp = createPolicyTypesJson(TYPE_ID_3, TYPE_ID_1);
+ assertThat(rsp).isEqualTo(expResp);
+
+ url = "/policy-types?type_name=A_type1&&compatible_with_version=junk";
+ testErrorCode(restClient().get(url), HttpStatus.BAD_REQUEST, "Version must contain major.minor.patch code");
+
+ url = "/policy-types?type_name=A_type1&&compatible_with_version=a.b.c";
+ testErrorCode(restClient().get(url), HttpStatus.BAD_REQUEST, "Syntax error in");
+
+ url = "/policy-types?compatible_with_version=1.5.0";
+ testErrorCode(restClient().get(url), HttpStatus.BAD_REQUEST, "type_name");
+
+ url = "/policy-types?regexp=type3_.*";
+ rsp = restClient().get(url).block();
+ expResp = createPolicyTypesJson(TYPE_ID_4);
+ assertThat(rsp).isEqualTo(expResp);
}
@Test
@@ -636,6 +669,7 @@ class ApplicationTest {
addPolicy("id1", "type1", "service1");
addPolicy("id2", "type1", "service2");
addPolicy("id3", "type2", "service1");
+ addPolicy("id4", "type1_1.0.0", "service1");
String url = "/policy-instances?policytype_id=type1";
String rsp = restClient().get(url).block();
@@ -651,6 +685,13 @@ class ApplicationTest {
.contains("id2") //
.doesNotContain("id3");
+ url = "/policy-instances?type_name=type1";
+ rsp = restClient().get(url).block();
+ assertThat(rsp).contains("id1") //
+ .contains("id2") //
+ .doesNotContain("id3") //
+ .contains("id4");
+
// Test get policies for non existing type
url = "/policy-instances?policytype_id=type1XXX";
testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
@@ -665,6 +706,7 @@ class ApplicationTest {
addPolicy("id1", "type1", "service1", "ric1");
addPolicy("id2", "type1", "service2", "ric1");
addPolicy("id3", "type2", "service1", "ric1");
+ addPolicy("id4", "type1_1.0.0", "service1");
String url = "/policies?policytype_id=type1";
String rsp = restClient().get(url).block();
@@ -678,6 +720,13 @@ class ApplicationTest {
PolicyIdList respList = gson.fromJson(rsp, PolicyIdList.class);
assertThat(respList.policyIds.iterator().next()).isEqualTo("id1");
+ url = "/policies?policytype_name=type1&service_id=service1";
+ rsp = restClient().get(url).block();
+ assertThat(rsp).contains("id1") //
+ .contains("id3") //
+ .contains("id4");
+ assertThat(gson.fromJson(rsp, PolicyIdList.class).policyIds).hasSize(3);
+
// Test get policy ids for non existing type
url = "/policies?policytype_id=type1XXX";
testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/EnvironmentProcessorTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/EnvironmentProcessorTest.java
index 5a1dbea7..64a7a19e 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/EnvironmentProcessorTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/EnvironmentProcessorTest.java
@@ -29,7 +29,7 @@ import ch.qos.logback.core.read.ListAppender;
import java.util.Properties;
import org.junit.jupiter.api.Test;
-import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.EnvironmentLoaderException;
+import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
import org.onap.ccsdk.oran.a1policymanagementservice.utils.LoggingUtils;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.ImmutableEnvProperties;
@@ -70,7 +70,7 @@ class EnvironmentProcessorTest {
Properties systemEnvironment = new Properties();
StepVerifier.create(EnvironmentProcessor.readEnvironmentVariables(systemEnvironment))
- .expectErrorMatches(throwable -> throwable instanceof EnvironmentLoaderException
+ .expectErrorMatches(throwable -> throwable instanceof ServiceException
&& throwable.getMessage().equals("$CONSUL_HOST environment has not been defined"))
.verify();
}
@@ -106,7 +106,7 @@ class EnvironmentProcessorTest {
systemEnvironment.put(CONSUL_HOST, CONSUL_HOST_VALUE);
StepVerifier.create(EnvironmentProcessor.readEnvironmentVariables(systemEnvironment))
- .expectErrorMatches(throwable -> throwable instanceof EnvironmentLoaderException
+ .expectErrorMatches(throwable -> throwable instanceof ServiceException
&& throwable.getMessage().equals("$CONFIG_BINDING_SERVICE environment has not been defined"))
.verify();
}
@@ -138,9 +138,8 @@ class EnvironmentProcessorTest {
systemEnvironment.put(CONFIG_BINDING_SERVICE, CONFIG_BINDING_SERVICE_VALUE);
StepVerifier.create(EnvironmentProcessor.readEnvironmentVariables(systemEnvironment))
- .expectErrorMatches(
- throwable -> throwable instanceof EnvironmentLoaderException && throwable.getMessage()
- .equals("Neither $HOSTNAME/$SERVICE_NAME have not been defined as system environment"))
+ .expectErrorMatches(throwable -> throwable instanceof ServiceException && throwable.getMessage()
+ .equals("Neither $HOSTNAME/$SERVICE_NAME have not been defined as system environment"))
.verify();
}
}