summaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src/test/java
diff options
context:
space:
mode:
authorPatrikBuhr <patrik.buhr@est.tech>2020-11-03 12:44:55 +0100
committerPatrikBuhr <patrik.buhr@est.tech>2020-11-03 12:50:44 +0100
commitbad7324bcc4900dfe3a31b4856da67aa3b6f6eeb (patch)
tree1aa2aace6343c0783faafb29881e88b4be18178c /a1-policy-management/src/test/java
parentefdb5b050f7dd7a80bdc168d660b639498baecea (diff)
Minor API changes
The callback registerred at service registration is formalized, documented and tested. Change-Id: Idb135ddcec1862da486c4abd287fd5c7a757d8eb Issue-ID: CCSDK-2502 Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Diffstat (limited to 'a1-policy-management/src/test/java')
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClientTest.java5
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java47
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConcurrencyTestRunnable.java2
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/RappSimulatorController.java81
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTaskTest.java45
5 files changed, 124 insertions, 56 deletions
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClientTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClientTest.java
index 87615f68..aad1ed02 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClientTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClientTest.java
@@ -43,9 +43,9 @@ import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.stubbing.OngoingStubbing;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client.A1ProtocolType;
-import org.onap.ccsdk.oran.a1policymanagementservice.clients.ImmutableAdapterOutput.Builder;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.CcsdkA1AdapterClient.AdapterOutput;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.CcsdkA1AdapterClient.AdapterRequest;
+import org.onap.ccsdk.oran.a1policymanagementservice.clients.ImmutableAdapterOutput.Builder;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ControllerConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableControllerConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policy;
@@ -171,7 +171,8 @@ class CcsdkA1AdapterClientTest {
@Test
void getTypeSchema_OSC() throws IOException {
String expUrl = RIC_1_URL + "/a1-p/policytypes/policyTypeId";
- testGetTypeSchema(A1ProtocolType.CCSDK_A1_ADAPTER_OSC_V1, expUrl, "policyTypeId", "test_osc_get_schema_response.json");
+ testGetTypeSchema(A1ProtocolType.CCSDK_A1_ADAPTER_OSC_V1, expUrl, "policyTypeId",
+ "test_osc_get_schema_response.json");
}
@Test
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 0fc252d8..02fdaf9c 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
@@ -52,6 +52,7 @@ import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableRicC
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableWebClientConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.WebClientConfig;
+import org.onap.ccsdk.oran.a1policymanagementservice.controllers.ServiceCallbackInfo;
import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.ImmutablePolicy;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.ImmutablePolicyType;
@@ -63,6 +64,7 @@ import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyTypes;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric.RicState;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics;
+import org.onap.ccsdk.oran.a1policymanagementservice.repository.Service;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Services;
import org.onap.ccsdk.oran.a1policymanagementservice.tasks.RicSupervision;
import org.onap.ccsdk.oran.a1policymanagementservice.tasks.ServiceSupervision;
@@ -122,6 +124,9 @@ class ApplicationTest {
@Autowired
Services services;
+ @Autowired
+ RappSimulatorController rAppSimulator;
+
private static Gson gson = new GsonBuilder().create();
public static class MockApplicationConfig extends ApplicationConfig {
@@ -192,6 +197,7 @@ class ApplicationTest {
policyTypes.clear();
services.clear();
a1ClientFactory.reset();
+ this.rAppSimulator.getTestResults().clear();
}
@AfterEach
@@ -355,7 +361,7 @@ class ApplicationTest {
policy = policies.getPolicy(policyInstanceId);
assertThat(policy.isTransient()).isFalse();
- url = "/policy_instances";
+ url = "/policy-instances";
String rsp = restClient().get(url).block();
assertThat(rsp).as("Response contains policy instance ID.").contains(policyInstanceId);
@@ -417,7 +423,7 @@ class ApplicationTest {
String body = putPolicyBody("service1", "ric1", "", "id1");
restClient().put("/policies", body).block();
- String rsp = restClient().get("/policy_instances").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();
@@ -518,7 +524,7 @@ class ApplicationTest {
void testGetPolicyInstances() throws Exception {
addPolicy("id1", "type1", "service1");
- String url = "/policy_instances";
+ String url = "/policy-instances";
String rsp = restClient().get(url).block();
logger.info(rsp);
PolicyInfoList info = gson.fromJson(rsp, PolicyInfoList.class);
@@ -536,14 +542,14 @@ class ApplicationTest {
addPolicy("id2", "type1", "service2");
addPolicy("id3", "type2", "service1");
- String url = "/policy_instances?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 = "/policy_instances?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") //
@@ -551,11 +557,11 @@ class ApplicationTest {
.doesNotContain("id3");
// Test get policies for non existing type
- url = "/policy_instances?policytype_id=type1XXX";
+ url = "/policy-instances?policytype_id=type1XXX";
testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
// Test get policies for non existing RIC
- url = "/policy_instances?ric_id=XXX";
+ url = "/policy-instances?ric_id=XXX";
testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
}
@@ -672,7 +678,25 @@ class ApplicationTest {
rsp = restClient().get(url).block();
info = gson.fromJson(rsp, PolicyStatusInfo.class);
assertThat(info.status.toString()).isEqualTo("{}");
+ }
+
+ @Test
+ void testServiceNotification() throws ServiceException {
+ putService("junkService");
+ Service junkService = this.services.get("junkService");
+ junkService.setCallbackUrl("https://junk");
+ putService("service");
+
+ Ric ric = addRic("ric1");
+ ric.setState(Ric.RicState.UNAVAILABLE);
+ supervision.checkAllRics();
+ waitForRicState("ric1", RicState.AVAILABLE);
+ RappSimulatorController.TestResults receivedCallbacks = rAppSimulator.getTestResults();
+ assertThat(receivedCallbacks.getReceivedInfo().size()).isEqualTo(1);
+ ServiceCallbackInfo callbackInfo = receivedCallbacks.getReceivedInfo().get(0);
+ assertThat(callbackInfo.ricId).isEqualTo("ric1");
+ assertThat(callbackInfo.eventType).isEqualTo(ServiceCallbackInfo.EventType.AVAILABLE);
}
private Policy addPolicy(String id, String typeName, String service, String ric) throws ServiceException {
@@ -685,7 +709,7 @@ class ApplicationTest {
.type(addPolicyType(typeName, ric)) //
.lastModified(Instant.now()) //
.isTransient(false) //
- .statusNotificationUri("/policy_status?id=XXX") //
+ .statusNotificationUri("/policy-status?id=XXX") //
.build();
policies.put(policy);
return policy;
@@ -696,7 +720,8 @@ class ApplicationTest {
}
private String createServiceJson(String name, long keepAliveIntervalSeconds) {
- return createServiceJson(name, keepAliveIntervalSeconds, "https://examples.javacodegeeks.com/core-java/");
+ String callbackUrl = baseUrl() + RappSimulatorController.SERVICE_CALLBACK_URL;
+ return createServiceJson(name, keepAliveIntervalSeconds, callbackUrl);
}
private String createServiceJson(String name, long keepAliveIntervalSeconds, String url) {
@@ -769,6 +794,10 @@ class ApplicationTest {
}
+ private String baseUrl() {
+ return "https://localhost:" + port;
+ }
+
private AsyncRestClient restClient(boolean useTrustValidation) {
String baseUrl = "https://localhost:" + port + Consts.V2_API_ROOT;
return restClient(baseUrl, useTrustValidation);
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 f8369610..ded864f7 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
@@ -131,7 +131,7 @@ class ConcurrencyTestRunnable implements Runnable {
}
private void listPolicies() {
- String uri = "/policy_instances";
+ String uri = "/policy-instances";
webClient.getForEntity(uri).block();
}
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/RappSimulatorController.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/RappSimulatorController.java
new file mode 100644
index 00000000..0a679201
--- /dev/null
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/RappSimulatorController.java
@@ -0,0 +1,81 @@
+/*-
+ * ========================LICENSE_START=================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ========================LICENSE_END===================================
+ */
+
+package org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+
+import java.lang.invoke.MethodHandles;
+import java.util.Vector;
+
+import lombok.Getter;
+
+import org.onap.ccsdk.oran.a1policymanagementservice.controllers.ServiceCallbackInfo;
+import org.onap.ccsdk.oran.a1policymanagementservice.controllers.VoidResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController("RappCallbacksController")
+@Api(tags = {"R-App Callbacks"})
+public class RappSimulatorController {
+
+ private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ public static final String SERVICE_CALLBACK_URL = "/r-app/pms-callback";
+ private static Gson gson = new GsonBuilder().create();
+
+ public static class TestResults {
+ @Getter
+ private Vector<ServiceCallbackInfo> receivedInfo = new Vector<>();
+
+ public void clear() {
+ receivedInfo.clear();
+ }
+ }
+
+ @Getter
+ private TestResults testResults = new TestResults();
+
+ private static final String CALLBACK_DESCRIPTION = "The URL to this call is registerred at Service registration.";
+
+ @PostMapping(path = SERVICE_CALLBACK_URL, produces = MediaType.APPLICATION_JSON_VALUE)
+ @ApiOperation(value = "Callback for Near-RT RIC status", notes = CALLBACK_DESCRIPTION)
+ @ApiResponses(value = { //
+ @ApiResponse(code = 200, message = "OK", response = VoidResponse.class)} //
+ )
+ public ResponseEntity<Object> jobStatusCallback( //
+ @RequestBody ServiceCallbackInfo body) {
+ logger.info("R-App callback body: {}", gson.toJson(body));
+ this.testResults.receivedInfo.add(body);
+ return new ResponseEntity<>(HttpStatus.OK);
+ }
+
+}
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 a50d4ab7..8029741e 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
@@ -23,9 +23,7 @@ package org.onap.ccsdk.oran.a1policymanagementservice.tasks;
import static ch.qos.logback.classic.Level.WARN;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -48,7 +46,6 @@ import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory;
-import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClient;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClientFactory;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableRicConfig;
@@ -162,21 +159,15 @@ class RicSynchronizationTaskTest {
RicSynchronizationTask synchronizerUnderTest = spy(createTask());
- AsyncRestClient restClientMock = setUpCreationOfAsyncRestClient(synchronizerUnderTest);
- when(restClientMock.put(anyString(), anyString())).thenReturn(Mono.just("Ok"));
-
synchronizerUnderTest.run(RIC_1);
verify(a1ClientMock, times(1)).getPolicyTypeIdentities();
verifyNoMoreInteractions(a1ClientMock);
verify(synchronizerUnderTest).run(RIC_1);
- verify(synchronizerUnderTest).createNotificationClient(SERVICE_1_CALLBACK_URL);
+ verify(synchronizerUnderTest).notifyServices(any());
verifyNoMoreInteractions(synchronizerUnderTest);
- verify(restClientMock).put("", "Synchronization completed for:" + RIC_1_NAME);
- verifyNoMoreInteractions(restClientMock);
-
assertThat(policyTypes.size()).isEqualTo(1);
assertThat(policies.size()).isZero();
assertThat(RIC_1.getState()).isEqualTo(RicState.AVAILABLE);
@@ -287,45 +278,11 @@ class RicSynchronizationTaskTest {
assertThat(RIC_1.getState()).isEqualTo(RicState.UNAVAILABLE);
}
- @Test
- void ricIdlePolicyTypeInRepo_thenSynchronizationWithErrorOnServiceNotificationErrorLogged() {
- RIC_1.setState(RicState.AVAILABLE);
-
- policyTypes.put(POLICY_TYPE_1);
-
- services.put(SERVICE_1);
-
- setUpCreationOfA1Client();
- simulateRicWithOnePolicyType();
-
- final ListAppender<ILoggingEvent> logAppender =
- LoggingUtils.getLogListAppender(RicSynchronizationTask.class, WARN);
-
- RicSynchronizationTask synchronizerUnderTest = spy(createTask());
-
- AsyncRestClient restClientMock = setUpCreationOfAsyncRestClient(synchronizerUnderTest);
- String originalErrorMessage = "Exception";
- when(restClientMock.put(anyString(), anyString())).thenReturn(Mono.error(new Exception(originalErrorMessage)));
-
- synchronizerUnderTest.run(RIC_1);
-
- ILoggingEvent loggingEvent = logAppender.list.get(0);
- assertThat(loggingEvent.getLevel()).isEqualTo(WARN);
- verifyCorrectLogMessage(0, logAppender,
- "Service notification failed for service: " + SERVICE_1_NAME + ". Cause: " + originalErrorMessage);
- }
-
private void setUpCreationOfA1Client() {
when(a1ClientFactoryMock.createA1Client(any(Ric.class))).thenReturn(Mono.just(a1ClientMock));
doReturn(Flux.empty()).when(a1ClientMock).deleteAllPolicies();
}
- private AsyncRestClient setUpCreationOfAsyncRestClient(RicSynchronizationTask synchronizerUnderTest) {
- AsyncRestClient restClientMock = mock(AsyncRestClient.class);
- doReturn(restClientMock).when(synchronizerUnderTest).createNotificationClient(anyString());
- return restClientMock;
- }
-
private void simulateRicWithOnePolicyType() {
when(a1ClientMock.getPolicyTypeIdentities()).thenReturn(Mono.just(Arrays.asList(POLICY_TYPE_1_NAME)));
}