summaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src/test
diff options
context:
space:
mode:
authorPatrikBuhr <patrik.buhr@est.tech>2020-10-22 10:51:21 +0200
committerPatrikBuhr <patrik.buhr@est.tech>2020-10-26 08:06:04 +0100
commitc655306c67fd9ed6b95d6b111f7bedab79c02f44 (patch)
tree00f52ce041d7fdb2eaf9cbd9002e2baa496af3be /a1-policy-management/src/test
parentc5f81cf8dace9637702d6934db1a9f4ed32ff131 (diff)
Added support for policy status notifications
Revised the version 2 of the component NBI Change-Id: I06571bfaa47ea3098ef71ce271e710a45b2d96e3 Issue-ID: CCSDK-2502 Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Diffstat (limited to 'a1-policy-management/src/test')
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/MockPolicyManagementService.java1
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientHelper.java2
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/SdncOscA1ClientTest.java3
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientV2Test.java15
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v1/ApplicationTest.java5
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java185
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConcurrencyTestRunnable.java33
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java1
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java2
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTaskTest.java1
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/ServiceSupervisionTest.java1
11 files changed, 127 insertions, 122 deletions
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/MockPolicyManagementService.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/MockPolicyManagementService.java
index 92d75b54..83b73d18 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/MockPolicyManagementService.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/MockPolicyManagementService.java
@@ -192,6 +192,7 @@ class MockPolicyManagementService {
.type(unnamedPolicyType) //
.lastModified(Instant.now()) //
.isTransient(false) //
+ .statusNotificationUri("statusNotificationUri") //
.build();
this.policies.put(policy);
}
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientHelper.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientHelper.java
index cec5c2c6..100e95e2 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientHelper.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientHelper.java
@@ -56,6 +56,7 @@ public class A1ClientHelper {
}
protected static Policy createPolicy(String nearRtRicUrl, String policyId, String json, String type) {
+ String callbackUrl = "https://test.com";
return ImmutablePolicy.builder() //
.id(policyId) //
.json(json) //
@@ -64,6 +65,7 @@ public class A1ClientHelper {
.type(createPolicyType(type)) //
.lastModified(Instant.now()) //
.isTransient(false) //
+ .statusNotificationUri(callbackUrl) //
.build();
}
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/SdncOscA1ClientTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/SdncOscA1ClientTest.java
index a0e95177..4eca44d4 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/SdncOscA1ClientTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/SdncOscA1ClientTest.java
@@ -268,7 +268,8 @@ class SdncOscA1ClientTest {
@Test
void putPolicy_STD_V2() {
- String expUrl = RIC_1_URL + "/A1-P/v2/policytypes/type1/policies/policy1";
+ String expUrl =
+ RIC_1_URL + "/A1-P/v2/policytypes/type1/policies/policy1?notificationDestination=https://test.com";
putPolicy(A1ProtocolType.SDNC_OSC_STD_V2_0_0, expUrl);
}
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientV2Test.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientV2Test.java
index d9238d64..de55882b 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientV2Test.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientV2Test.java
@@ -23,6 +23,7 @@ package org.onap.ccsdk.oran.a1policymanagementservice.clients;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -35,6 +36,7 @@ import org.json.JSONException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.ArgumentCaptor;
import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableRicConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig;
@@ -46,9 +48,9 @@ import reactor.test.StepVerifier;
@ExtendWith(MockitoExtension.class)
class StdA1ClientV2Test {
- private static final String RIC_URL = "RicUrl";
+ private static final String RIC_URL = "https://ric.com";
- private static final String RIC_BASE_URL = "RicBaseUrl/A1-P/v2";
+ private static final String RIC_BASE_URL = RIC_URL + "/A1-P/v2";
private static final String POLICYTYPES_IDENTITIES_URL = RIC_BASE_URL + "/policytypes";
private static final String POLICIES = "/policies";
@@ -69,7 +71,7 @@ class StdA1ClientV2Test {
void init() {
RicConfig ricConfig = ImmutableRicConfig.builder() //
.ricId("name") //
- .baseUrl("RicBaseUrl") //
+ .baseUrl(RIC_URL) //
.managedElementIds(new ArrayList<>()) //
.controllerName("") //
.build();
@@ -146,8 +148,11 @@ class StdA1ClientV2Test {
clientUnderTest
.putPolicy(A1ClientHelper.createPolicy(RIC_URL, POLICY_1_ID, POLICY_JSON_VALID, POLICY_TYPE_1_ID))
.block();
- verify(asyncRestClientMock).put(POLICYTYPES_URL + POLICY_TYPE_1_ID + POLICIES + "/" + POLICY_1_ID,
- POLICY_JSON_VALID);
+ ArgumentCaptor<String> urlCaptor = ArgumentCaptor.forClass(String.class);
+ verify(asyncRestClientMock).put(urlCaptor.capture(), eq(POLICY_JSON_VALID));
+ String actualUrl = urlCaptor.getValue();
+ String expUrl = POLICYTYPES_URL + POLICY_TYPE_1_ID + POLICIES + "/" + POLICY_1_ID;
+ assertThat(actualUrl).contains(expUrl);
}
@Test
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v1/ApplicationTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v1/ApplicationTest.java
index 97d0b504..551ed599 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v1/ApplicationTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v1/ApplicationTest.java
@@ -119,9 +119,7 @@ class ApplicationTest {
@Autowired
Services services;
- private static Gson gson = new GsonBuilder() //
- .serializeNulls() //
- .create(); //
+ private static Gson gson = new GsonBuilder().create();
public static class MockApplicationConfig extends ApplicationConfig {
@Override
@@ -670,6 +668,7 @@ class ApplicationTest {
.type(addPolicyType(typeName, ric)) //
.lastModified(Instant.now()) //
.isTransient(false) //
+ .statusNotificationUri("/policy_status?id=XXX") //
.build();
policies.put(policy);
return policy;
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 5128cd52..0fc252d8 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
@@ -122,9 +122,7 @@ class ApplicationTest {
@Autowired
Services services;
- private static Gson gson = new GsonBuilder() //
- .serializeNulls() //
- .create(); //
+ private static Gson gson = new GsonBuilder().create();
public static class MockApplicationConfig extends ApplicationConfig {
@Override
@@ -289,41 +287,42 @@ class ApplicationTest {
String managedElementId = "kista_1";
addRic(ricId, managedElementId);
- String url = "/ric?managed_element_id=" + managedElementId;
+ String url = "/rics/ric?managed_element_id=" + managedElementId;
String rsp = restClient().get(url).block();
RicInfo ricInfo = gson.fromJson(rsp, RicInfo.class);
assertThat(ricInfo.ricId).isEqualTo(ricId);
- url = "/ric?ric_id=" + ricId;
+ url = "/rics/ric?ric_id=" + ricId;
rsp = restClient().get(url).block();
ricInfo = gson.fromJson(rsp, RicInfo.class);
assertThat(ricInfo.ricId).isEqualTo(ricId);
// test GET RIC for ManagedElement that does not exist
- url = "/ric?managed_element_id=" + "junk";
+ url = "/rics/ric?managed_element_id=" + "junk";
testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
- url = "/ric";
+ url = "/rics/ric";
testErrorCode(restClient().get(url), HttpStatus.BAD_REQUEST);
}
- private String putPolicyUrl(String serviceName, String ricId, String policyTypeName, String policyInstanceId,
+ private String putPolicyBody(String serviceName, String ricId, String policyTypeName, String policyInstanceId,
boolean isTransient) {
- String url;
- if (policyTypeName.isEmpty()) {
- url = "/policy?policy_id=" + policyInstanceId + "&ric_id=" + ricId + "&service_id=" + serviceName;
- } else {
- url = "/policy?policy_id=" + policyInstanceId + "&ric_id=" + ricId + "&service_id=" + serviceName
- + "&policytype_id=" + policyTypeName;
- }
+ PolicyInfo info = new PolicyInfo();
+ info.policyId = policyInstanceId;
+ info.policyTypeId = policyTypeName;
+ info.ricId = ricId;
+ info.serviceId = serviceName;
+ info.policyData = gson.fromJson(jsonString(), Object.class);
+
if (isTransient) {
- url += "&transient=true";
+ info.isTransient = isTransient;
}
- return url;
+ info.statusNotificationUri = "statusNotificationUri";
+ return gson.toJson(info);
}
- private String putPolicyUrl(String serviceName, String ricId, String policyTypeName, String policyInstanceId) {
- return putPolicyUrl(serviceName, ricId, policyTypeName, policyInstanceId, false);
+ private String putPolicyBody(String serviceName, String ricId, String policyTypeName, String policyInstanceId) {
+ return putPolicyBody(serviceName, ricId, policyTypeName, policyInstanceId, false);
}
@Test
@@ -337,8 +336,8 @@ class ApplicationTest {
addPolicyType(policyTypeName, ricId);
// PUT a transient policy
- String url = putPolicyUrl(serviceName, ricId, policyTypeName, policyInstanceId, true);
- final String policyBody = jsonString();
+ String url = "/policies";
+ String policyBody = putPolicyBody(serviceName, ricId, policyTypeName, policyInstanceId, true);
this.rics.getRic(ricId).setState(Ric.RicState.AVAILABLE);
restClient().put(url, policyBody).block();
@@ -351,28 +350,29 @@ class ApplicationTest {
assertThat(policy.isTransient()).isTrue();
// Put a non transient policy
- url = putPolicyUrl(serviceName, ricId, policyTypeName, policyInstanceId);
+ policyBody = putPolicyBody(serviceName, ricId, policyTypeName, policyInstanceId);
restClient().put(url, policyBody).block();
policy = policies.getPolicy(policyInstanceId);
assertThat(policy.isTransient()).isFalse();
- url = "/policies";
+ url = "/policy_instances";
String rsp = restClient().get(url).block();
assertThat(rsp).as("Response contains policy instance ID.").contains(policyInstanceId);
- url = "/policy?policy_id=" + policyInstanceId;
+ url = "/policies/" + policyInstanceId;
rsp = restClient().get(url).block();
- assertThat(rsp).isEqualTo(policyBody);
+ assertThat(rsp).contains(policyBody);
// Test of error codes
- url = putPolicyUrl(serviceName, ricId + "XX", policyTypeName, policyInstanceId);
+ url = "/policies";
+ policyBody = putPolicyBody(serviceName, ricId + "XX", policyTypeName, policyInstanceId);
testErrorCode(restClient().put(url, policyBody), HttpStatus.NOT_FOUND);
- url = putPolicyUrl(serviceName, ricId, policyTypeName + "XX", policyInstanceId);
+ policyBody = putPolicyBody(serviceName, ricId, policyTypeName + "XX", policyInstanceId);
addPolicyType(policyTypeName + "XX", "otherRic");
testErrorCode(restClient().put(url, policyBody), HttpStatus.NOT_FOUND);
- url = putPolicyUrl(serviceName, ricId, policyTypeName, policyInstanceId);
+ policyBody = putPolicyBody(serviceName, ricId, policyTypeName, policyInstanceId);
this.rics.getRic(ricId).setState(Ric.RicState.SYNCHRONIZING);
testErrorCode(restClient().put(url, policyBody), HttpStatus.LOCKED);
this.rics.getRic(ricId).setState(Ric.RicState.AVAILABLE);
@@ -389,7 +389,6 @@ class ApplicationTest {
putService("service1");
addPolicyType("type1", "ric1");
- String url = putPolicyUrl("service1", "ric1", "type1", "id1");
MockA1Client a1Client = a1ClientFactory.getOrCreateA1Client("ric1");
HttpStatus httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
String responseBody = "Refused";
@@ -400,32 +399,25 @@ class ApplicationTest {
doReturn(Mono.error(a1Exception)).when(a1Client).putPolicy(any());
// PUT Policy
- testErrorCode(restClient().put(url, "{}"), httpStatus, responseBody);
+ String putBody = putPolicyBody("service1", "ric1", "type1", "id1");
+ String url = "/policies";
+ testErrorCode(restClient().put(url, putBody), httpStatus, responseBody);
// DELETE POLICY
this.addPolicy("instance1", "type1", "service1", "ric1");
doReturn(Mono.error(a1Exception)).when(a1Client).deletePolicy(any());
- testErrorCode(restClient().delete("/policy?policy_id=instance1"), httpStatus, responseBody);
-
- // GET STATUS
- this.addPolicy("instance1", "type1", "service1", "ric1");
- doReturn(Mono.error(a1Exception)).when(a1Client).getPolicyStatus(any());
- testErrorCode(restClient().get("/policy-status?policy_id=instance1"), httpStatus, responseBody);
+ testErrorCode(restClient().delete("/policies/instance1"), httpStatus, responseBody);
- // Check that empty response body is OK
- a1Exception = new WebClientResponseException(httpStatus.value(), "", null, null, null, null);
- doReturn(Mono.error(a1Exception)).when(a1Client).getPolicyStatus(any());
- testErrorCode(restClient().get("/policy-status?policy_id=instance1"), httpStatus);
}
@Test
void testPutTypelessPolicy() throws Exception {
putService("service1");
addPolicyType("", "ric1");
- String url = putPolicyUrl("service1", "ric1", "", "id1");
- restClient().put(url, jsonString()).block();
+ String body = putPolicyBody("service1", "ric1", "", "id1");
+ restClient().put("/policies", body).block();
- String rsp = restClient().get("/policies").block();
+ String rsp = restClient().get("/policy_instances").block();
PolicyInfoList info = gson.fromJson(rsp, PolicyInfoList.class);
assertThat(info.policies).hasSize(1);
PolicyInfo policyInfo = info.policies.iterator().next();
@@ -443,17 +435,19 @@ class ApplicationTest {
this.addPolicy("instance2", "type1", "service1", "ricXXX");
// Try change ric1 -> ricXXX
- String urlWrongRic = putPolicyUrl("service1", "ricXXX", "type1", "instance1");
- testErrorCode(restClient().put(urlWrongRic, jsonString()), HttpStatus.CONFLICT);
+ String bodyWrongRic = putPolicyBody("service1", "ricXXX", "type1", "instance1");
+ testErrorCode(restClient().put("/policies", bodyWrongRic), HttpStatus.CONFLICT);
}
@Test
void testGetPolicy() throws Exception {
- String url = "/policy?policy_id=id";
+ String url = "/policies/id";
Policy policy = addPolicy("id", "typeName", "service1", "ric1");
{
String rsp = restClient().get(url).block();
- assertThat(rsp).isEqualTo(policy.json());
+ PolicyInfo info = gson.fromJson(rsp, PolicyInfo.class);
+ String policyStr = gson.toJson(info.policyData);
+ assertThat(policyStr).isEqualTo(policy.json());
}
{
policies.remove(policy);
@@ -466,7 +460,7 @@ class ApplicationTest {
addPolicy("id", "typeName", "service1", "ric1");
assertThat(policies.size()).isEqualTo(1);
- String url = "/policy?policy_id=id";
+ String url = "/policies/id";
ResponseEntity<String> entity = restClient().deleteForEntity(url).block();
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
@@ -477,50 +471,19 @@ class ApplicationTest {
}
@Test
- void testGetPolicySchemas() throws Exception {
+ void testGetPolicyType() throws Exception {
addPolicyType("type1", "ric1");
- addPolicyType("type2", "ric2");
waitForRicState("ric1", RicState.AVAILABLE);
- waitForRicState("ric2", RicState.AVAILABLE);
- String url = "/policy-schemas";
+ String url = "/policy-types/type1";
String rsp = this.restClient().get(url).block();
- assertThat(rsp).contains("type1") //
- .contains("{\"title\":\"type2\"}");
-
- PolicySchemaList info = parseSchemas(rsp);
- assertThat(info.schemas).hasSize(2);
-
- url = "/policy-schemas?ric_id=ric1";
- rsp = restClient().get(url).block();
- assertThat(rsp).contains("type1");
- info = parseSchemas(rsp);
- assertThat(info.schemas).hasSize(1);
-
- // Schema for type
- url = "/policy-schemas?policytype_id=type1";
- rsp = restClient().get(url).block();
- assertThat(rsp).contains("type1") //
- .contains("title");
-
- // Both type and ric specified
- url = "/policy-schemas?ric_id=ric1&policytype_id=type1";
- rsp = restClient().get(url).block();
- PolicySchemaList list = gson.fromJson(rsp, PolicySchemaList.class);
- assertThat(list.schemas).hasSize(1);
- url = "/policy-schemas?ric_id=ric1&policytype_id=type2";
- rsp = restClient().get(url).block();
- list = gson.fromJson(rsp, PolicySchemaList.class);
- assertThat(list.schemas).isEmpty();
-
- // Get schema for non existing RIC
- url = "/policy-schemas?ric_id=ric1XXX";
- testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
+ PolicyTypeInfo info = gson.fromJson(rsp, PolicyTypeInfo.class);
+ assertThat(info.schema).isNotNull();
// Get non existing schema
- url = "/policy-schemas?policytype_id=type1XX";
+ url = "/policy-types/JUNK";
testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
}
@@ -552,10 +515,10 @@ class ApplicationTest {
}
@Test
- void testGetPolicies() throws Exception {
+ void testGetPolicyInstances() throws Exception {
addPolicy("id1", "type1", "service1");
- String url = "/policies";
+ String url = "/policy_instances";
String rsp = restClient().get(url).block();
logger.info(rsp);
PolicyInfoList info = gson.fromJson(rsp, PolicyInfoList.class);
@@ -568,19 +531,19 @@ class ApplicationTest {
}
@Test
- void testGetPoliciesFilter() throws Exception {
+ void testGetPolicyInstancesFilter() throws Exception {
addPolicy("id1", "type1", "service1");
addPolicy("id2", "type1", "service2");
addPolicy("id3", "type2", "service1");
- String url = "/policies?policytype_id=type1";
+ String url = "/policy_instances?policytype_id=type1";
String rsp = restClient().get(url).block();
logger.info(rsp);
assertThat(rsp).contains("id1") //
.contains("id2") //
.doesNotContain("id3");
- url = "/policies?policytype_id=type1&service_id=service2";
+ url = "/policy_instances?policytype_id=type1&service_id=service2";
rsp = restClient().get(url).block();
logger.info(rsp);
assertThat(rsp).doesNotContain("id1") //
@@ -588,11 +551,11 @@ class ApplicationTest {
.doesNotContain("id3");
// Test get policies for non existing type
- url = "/policies?policytype_id=type1XXX";
+ url = "/policy_instances?policytype_id=type1XXX";
testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
// Test get policies for non existing RIC
- url = "/policies?ric_id=XXX";
+ url = "/policy_instances?ric_id=XXX";
testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
}
@@ -602,24 +565,24 @@ class ApplicationTest {
addPolicy("id2", "type1", "service2", "ric1");
addPolicy("id3", "type2", "service1", "ric1");
- String url = "/policy-ids?policytype_id=type1";
+ String url = "/policies?policytype_id=type1";
String rsp = restClient().get(url).block();
logger.info(rsp);
assertThat(rsp).contains("id1") //
.contains("id2") //
.doesNotContain("id3");
- url = "/policy-ids?policytype_id=type1&service_id=service1&ric=ric1";
+ url = "/policies?policytype_id=type1&service_id=service1&ric=ric1";
rsp = restClient().get(url).block();
PolicyIdList respList = gson.fromJson(rsp, PolicyIdList.class);
assertThat(respList.policyIds.iterator().next()).isEqualTo("id1");
// Test get policy ids for non existing type
- url = "/policy-ids?policytype_id=type1XXX";
+ url = "/policies?policytype_id=type1XXX";
testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
// Test get policy ids for non existing RIC
- url = "/policy-ids?ric_id=XXX";
+ url = "/policies?ric_id=XXX";
testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
}
@@ -646,18 +609,18 @@ class ApplicationTest {
logger.info(rsp);
// Keep alive
- url = "/services/keepalive?service_id=name";
+ url = "/services/name/keepalive";
ResponseEntity<?> entity = restClient().putForEntity(url).block();
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
// DELETE service
assertThat(services.size()).isEqualTo(1);
- url = "/services?service_id=name";
+ url = "/services/name";
restClient().delete(url).block();
assertThat(services.size()).isZero();
// Keep alive, no registered service
- testErrorCode(restClient().put("/services/keepalive?service_id=name", ""), HttpStatus.NOT_FOUND);
+ testErrorCode(restClient().put("/services/junk/keepalive", ""), HttpStatus.NOT_FOUND);
// PUT service with bad payload
testErrorCode(restClient().put("/services", "crap"), HttpStatus.BAD_REQUEST, false);
@@ -676,9 +639,8 @@ class ApplicationTest {
putService("service1", 1, HttpStatus.CREATED);
addPolicyType("type1", "ric1");
- String url = putPolicyUrl("service1", "ric1", "type1", "instance1");
- final String policyBody = jsonString();
- restClient().put(url, policyBody).block();
+ String policyBody = putPolicyBody("service1", "ric1", "type1", "instance1");
+ restClient().put("/policies", policyBody).block();
assertThat(policies.size()).isEqualTo(1);
assertThat(services.size()).isEqualTo(1);
@@ -693,13 +655,24 @@ class ApplicationTest {
addPolicy("id", "typeName", "service1", "ric1");
assertThat(policies.size()).isEqualTo(1);
- String url = "/policy-status?policy_id=id";
+ String url = "/policies/id/status";
String rsp = restClient().get(url).block();
- assertThat(rsp).isEqualTo("OK");
+ PolicyStatusInfo info = gson.fromJson(rsp, PolicyStatusInfo.class);
+ assertThat(info.status).isEqualTo("OK");
// GET non existing policy status
- url = "/policy-status?policy_id=XXX";
+ url = "/policies/XXX/status";
testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
+
+ // GET STATUS, the NearRT RIC returns error
+ MockA1Client a1Client = a1ClientFactory.getOrCreateA1Client("ric1");
+ url = "/policies/id/status";
+ WebClientResponseException a1Exception = new WebClientResponseException(404, "", null, null, null);
+ doReturn(Mono.error(a1Exception)).when(a1Client).getPolicyStatus(any());
+ rsp = restClient().get(url).block();
+ info = gson.fromJson(rsp, PolicyStatusInfo.class);
+ assertThat(info.status.toString()).isEqualTo("{}");
+
}
private Policy addPolicy(String id, String typeName, String service, String ric) throws ServiceException {
@@ -712,6 +685,7 @@ class ApplicationTest {
.type(addPolicyType(typeName, ric)) //
.lastModified(Instant.now()) //
.isTransient(false) //
+ .statusNotificationUri("/policy_status?id=XXX") //
.build();
policies.put(policy);
return policy;
@@ -884,7 +858,4 @@ class ApplicationTest {
return ric;
}
- private static PolicySchemaList parseSchemas(String jsonString) {
- return gson.fromJson(jsonString, PolicySchemaList.class);
- }
}
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConcurrencyTestRunnable.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConcurrencyTestRunnable.java
index 89a76e95..f8369610 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConcurrencyTestRunnable.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConcurrencyTestRunnable.java
@@ -20,6 +20,9 @@
package org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
import java.time.Instant;
import java.util.concurrent.atomic.AtomicInteger;
@@ -52,6 +55,8 @@ class ConcurrencyTestRunnable implements Runnable {
private final PolicyTypes types;
private boolean failed = false;
+ private static Gson gson = new GsonBuilder().create();
+
ConcurrencyTestRunnable(AsyncRestClient client, RicSupervision supervision, MockA1ClientFactory a1ClientFactory,
Rics rics, PolicyTypes types) {
this.count = nextCount.incrementAndGet();
@@ -85,7 +90,7 @@ class ConcurrencyTestRunnable implements Runnable {
createInconsistency();
this.supervision.checkAllRics();
}
- String name = "policy:" + count + ":" + i;
+ String name = "policy_" + count + "_" + i;
putPolicy(name);
putPolicy(name + "-");
listPolicies();
@@ -115,6 +120,7 @@ class ConcurrencyTestRunnable implements Runnable {
.ownerServiceId("") //
.lastModified(Instant.now()) //
.isTransient(false) //
+ .statusNotificationUri("/policy_status?id=XXX") //
.build();
}
@@ -122,11 +128,10 @@ class ConcurrencyTestRunnable implements Runnable {
MockA1Client client = a1ClientFactory.getOrCreateA1Client("ric");
Policy policy = createPolicyObject("junk");
client.putPolicy(policy).block();
-
}
private void listPolicies() {
- String uri = "/policies";
+ String uri = "/policy_instances";
webClient.getForEntity(uri).block();
}
@@ -136,12 +141,28 @@ class ConcurrencyTestRunnable implements Runnable {
}
private void putPolicy(String name) {
- String putUrl = "/policy?policytype_id=type1&policy_id=" + name + "&ric_id=ric&service_id=service1";
- webClient.putForEntity(putUrl, "{}").block();
+ String putUrl = "/policies";
+ String body = putPolicyBody("service1", "ric", "type1", name, false);
+ webClient.putForEntity(putUrl, body).block();
+ }
+
+ private String putPolicyBody(String serviceName, String ricId, String policyTypeName, String policyInstanceId,
+ boolean isTransient) {
+ PolicyInfo info = new PolicyInfo();
+ info.policyId = policyInstanceId;
+ info.policyTypeId = policyTypeName;
+ info.ricId = ricId;
+ info.serviceId = serviceName;
+ info.policyData = gson.fromJson("{}", Object.class);
+
+ if (isTransient) {
+ info.isTransient = isTransient;
+ }
+ return gson.toJson(info);
}
private void deletePolicy(String name) {
- String deleteUrl = "/policy?policy_id=" + name;
+ String deleteUrl = "/policies/" + name;
webClient.delete(deleteUrl).block();
}
}
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java
index 4cc23607..04951ee7 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java
@@ -312,6 +312,7 @@ class RefreshConfigTaskTest {
.json("{}") //
.ownerServiceId("ownerServiceId") //
.isTransient(false) //
+ .statusNotificationUri("/policy_status?id=XXX") //
.build();
return policy;
}
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java
index ca5a6192..4e72bbf6 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java
@@ -81,6 +81,7 @@ class RicSupervisionTest {
.type(POLICY_TYPE_1) //
.lastModified(Instant.now()) //
.isTransient(false) //
+ .statusNotificationUri("statusNotificationUri") //
.build();
private static final Policy POLICY_2 = ImmutablePolicy.builder() //
@@ -91,6 +92,7 @@ class RicSupervisionTest {
.type(POLICY_TYPE_1) //
.lastModified(Instant.now()) //
.isTransient(false) //
+ .statusNotificationUri("statusNotificationUri") //
.build();
@Mock
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTaskTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTaskTest.java
index 0ac8fdb0..a50d4ab7 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTaskTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTaskTest.java
@@ -92,6 +92,7 @@ class RicSynchronizationTaskTest {
.type(POLICY_TYPE_1) //
.lastModified(Instant.now()) //
.isTransient(isTransient) //
+ .statusNotificationUri("statusNotificationUri") //
.build();
}
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/ServiceSupervisionTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/ServiceSupervisionTest.java
index 1a8e9b3e..c8476221 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/ServiceSupervisionTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/ServiceSupervisionTest.java
@@ -90,6 +90,7 @@ class ServiceSupervisionTest {
.type(policyType) //
.lastModified(Instant.now()) //
.isTransient(false) //
+ .statusNotificationUri("statusNotificationUri") //
.build();
@Test