aboutsummaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'a1-policy-management/src/test')
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/MockPolicyManagementService.java3
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactoryTest.java51
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientHelper.java4
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClientTest.java55
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1ClientTest.java6
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientTest.java8
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientV2Test.java6
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParserTest.java14
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigTest.java25
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java44
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java20
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java12
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java43
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTaskTest.java89
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/ServiceSupervisionTest.java6
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/MockA1Client.java24
-rw-r--r--a1-policy-management/src/test/resources/keystore.jksbin5019 -> 0 bytes
-rw-r--r--a1-policy-management/src/test/resources/test_application_configuration.json3
-rw-r--r--a1-policy-management/src/test/resources/test_application_configuration_with_dmaap_config.json5
-rw-r--r--a1-policy-management/src/test/resources/truststore.jksbin3699 -> 0 bytes
20 files changed, 196 insertions, 222 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 3cb1d91d..3b7695e8 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
@@ -32,7 +32,6 @@ import java.nio.file.Files;
import java.time.Instant;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policies;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policy;
@@ -50,10 +49,8 @@ import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.TestPropertySource;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.util.StringUtils;
-@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
@TestPropertySource(properties = { //
"server.ssl.key-store=./config/keystore.jks", //
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactoryTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactoryTest.java
index 645f2353..424668fc 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactoryTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactoryTest.java
@@ -27,8 +27,7 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
-import java.util.Vector;
-
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -37,8 +36,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client.A1ProtocolType;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ControllerConfig;
-import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableControllerConfig;
-import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableRicConfig;
+import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric;
@@ -68,21 +66,24 @@ class A1ClientFactoryTest {
private Ric ric;
private A1ClientFactory factoryUnderTest;
- private static ImmutableRicConfig ricConfig(String controllerName) {
- return ImmutableRicConfig.builder() //
+ private static RicConfig ricConfig(String controllerName, String customAdapter) {
+ return RicConfig.builder() //
.ricId(RIC_NAME) //
.baseUrl("baseUrl") //
- .managedElementIds(new Vector<>()) //
.controllerName(controllerName) //
+ .customAdapterClass(customAdapter) //
.build();
}
+ private static RicConfig ricConfig(String controllerName) {
+ return ricConfig(controllerName, "");
+ }
+
@BeforeEach
void createFactoryUnderTest() {
SecurityContext sec = new SecurityContext("");
factoryUnderTest = spy(new A1ClientFactory(applicationConfigMock, sec));
this.ric = new Ric(ricConfig(""));
-
}
@Test
@@ -109,6 +110,38 @@ class A1ClientFactoryTest {
assertEquals(A1ProtocolType.STD_V1_1, ric.getProtocolVersion(), "Not correct protocol");
}
+ public static class CustomA1AdapterFactory implements A1Client.Factory {
+ @Override
+ public A1Client create(RicConfig ricConfig, AsyncRestClientFactory restClientFactory) {
+ return new StdA1ClientVersion2(ricConfig, restClientFactory);
+ }
+ }
+
+ @Test
+ void testCustomAdapterCreation() {
+
+ Ric ric = new Ric(ricConfig("", CustomA1AdapterFactory.class.getName()));
+ A1Client client = factoryUnderTest.createA1Client(ric).block();
+
+ assertEquals(client.getClass(), StdA1ClientVersion2.class);
+
+ ric = new Ric(ricConfig("", "org.onap.ccsdk.oran.a1policymanagementservice.clients.StdA1ClientVersion2"));
+ client = factoryUnderTest.createA1Client(ric).block();
+
+ assertEquals(client.getClass(), StdA1ClientVersion2.class);
+
+ ric = new Ric(
+ ricConfig("", "org.onap.ccsdk.oran.a1policymanagementservice.clients.StdA1ClientVersion2$Factory"));
+ client = factoryUnderTest.createA1Client(ric).block();
+
+ assertEquals(client.getClass(), StdA1ClientVersion2.class);
+
+ Exception e = Assertions.assertThrows(Exception.class, () -> {
+ factoryUnderTest.createClient(new Ric(ricConfig("", "junk")), A1ProtocolType.CUSTOM_PROTOCOL);
+ });
+ assertEquals("Could not find class: junk", e.getMessage());
+ }
+
@Test
void getProtocolVersion_error() throws ServiceException {
whenGetProtocolVersionThrowException(clientMock1, clientMock2, clientMock3, clientMock4);
@@ -155,7 +188,7 @@ class A1ClientFactoryTest {
}
private void whenGetGetControllerConfigReturn() throws ServiceException {
- ControllerConfig controllerCfg = ImmutableControllerConfig.builder() //
+ ControllerConfig controllerCfg = ControllerConfig.builder() //
.name("name") //
.baseUrl("baseUrl") //
.password("pass") //
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 eb007138..56dc7ed6 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
@@ -25,7 +25,6 @@ import java.util.Arrays;
import java.util.Vector;
import org.json.JSONObject;
-import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableRicConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policy;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyType;
@@ -45,10 +44,9 @@ public class A1ClientHelper {
}
protected static Ric createRic(String url) {
- RicConfig cfg = ImmutableRicConfig.builder().ricId("ric") //
+ RicConfig cfg = RicConfig.builder().ricId("ric") //
.baseUrl(url) //
.managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))) //
- .controllerName("") //
.build();
return new Ric(cfg);
}
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 f49020ee..15e4983c 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
@@ -35,7 +35,6 @@ import java.net.URL;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;
-import java.util.Optional;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -45,9 +44,7 @@ import org.mockito.stubbing.OngoingStubbing;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client.A1ProtocolType;
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;
import org.springframework.http.HttpStatus;
import org.springframework.web.reactive.function.client.WebClientResponseException;
@@ -74,7 +71,7 @@ class CcsdkA1AdapterClientTest {
AsyncRestClient asyncRestClientMock;
private ControllerConfig controllerConfig() {
- return ImmutableControllerConfig.builder() //
+ return ControllerConfig.builder() //
.name("name") //
.baseUrl("baseUrl") //
.password(CONTROLLER_PASSWORD) //
@@ -113,9 +110,8 @@ class CcsdkA1AdapterClientTest {
assertEquals(1, policyTypeIds.size());
assertEquals(POLICY_TYPE_1_ID, policyTypeIds.get(0));
- ImmutableAdapterRequest expectedParams = ImmutableAdapterRequest.builder() //
- .nearRtRicUrl(expUrl) //
- .build();
+ AdapterRequest expectedParams = new AdapterRequest(expUrl, null);
+
String expInput = A1AdapterJsonHelper.createInputJsonString(expectedParams);
verify(asyncRestClientMock).postWithAuthHeader(GET_A1_POLICY_URL, expInput, CONTROLLER_USERNAME,
CONTROLLER_PASSWORD);
@@ -160,9 +156,8 @@ class CcsdkA1AdapterClientTest {
assertEquals(policyTypeId, respJson.getAsJsonObject().get("title").getAsString(),
"title should be updated to contain policyType ID");
- ImmutableAdapterRequest expectedParams = ImmutableAdapterRequest.builder() //
- .nearRtRicUrl(expUrl) //
- .build();
+ AdapterRequest expectedParams = new AdapterRequest(expUrl, null);
+
String expInput = A1AdapterJsonHelper.createInputJsonString(expectedParams);
verify(asyncRestClientMock).postWithAuthHeader(GET_A1_POLICY_URL, expInput, CONTROLLER_USERNAME,
@@ -205,9 +200,8 @@ class CcsdkA1AdapterClientTest {
assertEquals(1, returned.size());
for (String expUrl : expUrls) {
- ImmutableAdapterRequest expectedParams = ImmutableAdapterRequest.builder() //
- .nearRtRicUrl(expUrl) //
- .build();
+ AdapterRequest expectedParams = new AdapterRequest(expUrl, null);
+
String expInput = A1AdapterJsonHelper.createInputJsonString(expectedParams);
verify(asyncRestClientMock).postWithAuthHeader(GET_A1_POLICY_URL, expInput, CONTROLLER_USERNAME,
CONTROLLER_PASSWORD);
@@ -246,10 +240,7 @@ class CcsdkA1AdapterClientTest {
.block();
assertEquals("OK", returned);
- AdapterRequest expectedInputParams = ImmutableAdapterRequest.builder() //
- .nearRtRicUrl(expUrl) //
- .body(POLICY_JSON_VALID) //
- .build();
+ AdapterRequest expectedInputParams = new AdapterRequest(expUrl, POLICY_JSON_VALID);
String expInput = A1AdapterJsonHelper.createInputJsonString(expectedInputParams);
verify(asyncRestClientMock).postWithAuthHeader(PUT_A1_URL, expInput, CONTROLLER_USERNAME, CONTROLLER_PASSWORD);
@@ -282,10 +273,7 @@ class CcsdkA1AdapterClientTest {
controllerConfig(), asyncRestClientMock);
final String policyJson = "{}";
- AdapterOutput adapterOutput = ImmutableAdapterOutput.builder() //
- .body("NOK") //
- .httpStatus(HttpStatus.BAD_REQUEST.value()) // ERROR
- .build();
+ AdapterOutput adapterOutput = new AdapterOutput(HttpStatus.BAD_REQUEST.value(), "NOK");
String resp = A1AdapterJsonHelper.createOutputJsonString(adapterOutput);
whenAsyncPostThenReturn(Mono.just(resp));
@@ -311,9 +299,8 @@ class CcsdkA1AdapterClientTest {
clientUnderTest.deleteAllPolicies().blockLast();
- ImmutableAdapterRequest expectedParams = ImmutableAdapterRequest.builder() //
- .nearRtRicUrl(expUrl) //
- .build();
+ AdapterRequest expectedParams = new AdapterRequest(expUrl, null);
+
String expInput = A1AdapterJsonHelper.createInputJsonString(expectedParams);
verify(asyncRestClientMock).postWithAuthHeader(DELETE_A1_URL, expInput, CONTROLLER_USERNAME,
CONTROLLER_PASSWORD);
@@ -363,9 +350,8 @@ class CcsdkA1AdapterClientTest {
assertEquals("OK", response);
String expUrl = RIC_1_URL + "/A1-P/v2/policytypes/type1/policies/policy1/status";
- ImmutableAdapterRequest expectedParams = ImmutableAdapterRequest.builder() //
- .nearRtRicUrl(expUrl) //
- .build();
+ AdapterRequest expectedParams = new AdapterRequest(expUrl, null);
+
String expInput = A1AdapterJsonHelper.createInputJsonString(expectedParams);
verify(asyncRestClientMock).postWithAuthHeader(GET_A1_POLICY_STATUS_URL, expInput, CONTROLLER_USERNAME,
CONTROLLER_PASSWORD);
@@ -392,21 +378,14 @@ class CcsdkA1AdapterClientTest {
}
private String createOkResponseWithBody(Object body) {
- AdapterOutput output = ImmutableAdapterOutput.builder() //
- .body(gson().toJson(body)) //
- .httpStatus(HttpStatus.OK.value()) //
- .build();
+ AdapterOutput output = new AdapterOutput(HttpStatus.OK.value(), gson().toJson(body));
return A1AdapterJsonHelper.createOutputJsonString(output);
}
private String createOkResponseString(boolean withBody) {
- Builder responseBuilder = ImmutableAdapterOutput.builder().httpStatus(HttpStatus.OK.value());
- if (withBody) {
- responseBuilder.body(HttpStatus.OK.name());
- } else {
- responseBuilder.body(Optional.empty());
- }
- return A1AdapterJsonHelper.createOutputJsonString(responseBuilder.build());
+ String body = withBody ? HttpStatus.OK.name() : null;
+ AdapterOutput output = new AdapterOutput(HttpStatus.OK.value(), body);
+ return A1AdapterJsonHelper.createOutputJsonString(output);
}
private OngoingStubbing<Mono<String>> whenAsyncPostThenReturn(Mono<String> response) {
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1ClientTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1ClientTest.java
index 6aacc914..2ff07f15 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1ClientTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1ClientTest.java
@@ -26,7 +26,6 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -35,7 +34,6 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
-import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableRicConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig;
import reactor.core.publisher.Flux;
@@ -66,11 +64,9 @@ class OscA1ClientTest {
@BeforeEach
void init() {
- RicConfig ricConfig = ImmutableRicConfig.builder() //
+ RicConfig ricConfig = RicConfig.builder() //
.ricId("name") //
.baseUrl("RicBaseUrl") //
- .managedElementIds(new ArrayList<>()) //
- .controllerName("") //
.build();
asyncRestClientMock = mock(AsyncRestClient.class);
clientUnderTest = new OscA1Client(ricConfig, asyncRestClientMock);
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientTest.java
index b4709767..db4c79cd 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientTest.java
@@ -80,7 +80,7 @@ class StdA1ClientTest {
@Test
void testGetPolicyIdentities() {
- doReturn(RIC_URL).when(ricConfigMock).baseUrl();
+ doReturn(RIC_URL).when(ricConfigMock).getBaseUrl();
Mono<String> policyIds = Mono.just(Arrays.asList(POLICY_1_ID, POLICY_2_ID).toString());
when(asyncRestClientMock.get(anyString())).thenReturn(policyIds);
@@ -98,7 +98,7 @@ class StdA1ClientTest {
@Test
void testPutPolicyValidResponse() {
- doReturn(RIC_URL).when(ricConfigMock).baseUrl();
+ doReturn(RIC_URL).when(ricConfigMock).getBaseUrl();
when(asyncRestClientMock.put(anyString(), anyString())).thenReturn(Mono.just(POLICY_JSON));
Mono<String> policyMono =
@@ -110,7 +110,7 @@ class StdA1ClientTest {
@Test
void testDeletePolicy() {
- doReturn(RIC_URL).when(ricConfigMock).baseUrl();
+ doReturn(RIC_URL).when(ricConfigMock).getBaseUrl();
final String url = policiesBaseUrl() + POLICY_1_ID;
when(asyncRestClientMock.delete(url)).thenReturn(Mono.empty());
@@ -122,7 +122,7 @@ class StdA1ClientTest {
@Test
void testDeleteAllPolicies() {
- doReturn(RIC_URL).when(ricConfigMock).baseUrl();
+ doReturn(RIC_URL).when(ricConfigMock).getBaseUrl();
Mono<String> policyIds = Mono.just(Arrays.asList(POLICY_1_ID, POLICY_2_ID).toString());
when(asyncRestClientMock.get(policiesUrl())).thenReturn(policyIds);
when(asyncRestClientMock.delete(anyString())).thenReturn(Mono.empty());
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 de55882b..95c20426 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
@@ -28,7 +28,6 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -38,7 +37,6 @@ 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;
import reactor.core.publisher.Flux;
@@ -69,11 +67,9 @@ class StdA1ClientV2Test {
@BeforeEach
void init() {
- RicConfig ricConfig = ImmutableRicConfig.builder() //
+ RicConfig ricConfig = RicConfig.builder() //
.ricId("name") //
.baseUrl(RIC_URL) //
- .managedElementIds(new ArrayList<>()) //
- .controllerName("") //
.build();
asyncRestClientMock = mock(AsyncRestClient.class);
clientUnderTest = new StdA1ClientVersion2(ricConfig, asyncRestClientMock);
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParserTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParserTest.java
index 4a4e8a33..8e3e3a5d 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParserTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParserTest.java
@@ -59,25 +59,27 @@ class ApplicationConfigParserTest {
ApplicationConfigParser.ConfigParserResult result = parserUnderTest.parse(jsonRootObject);
- String topicUrl = result.dmaapProducerTopicUrl();
+ String topicUrl = result.getDmaapProducerTopicUrl();
assertEquals("http://admin:admin@localhost:6845/events/A1-POLICY-AGENT-WRITE", topicUrl, "controller contents");
- topicUrl = result.dmaapConsumerTopicUrl();
+ topicUrl = result.getDmaapConsumerTopicUrl();
assertEquals(
"http://admin:admin@localhost:6845/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=15000&limit=100",
topicUrl, "controller contents");
- Map<String, ControllerConfig> controllers = result.controllerConfigs();
+ Map<String, ControllerConfig> controllers = result.getControllerConfigs();
assertEquals(1, controllers.size(), "size");
- ImmutableControllerConfig expectedControllerConfig = ImmutableControllerConfig.builder() //
+ ControllerConfig expectedControllerConfig = ControllerConfig.builder() //
.baseUrl("http://localhost:8083/") //
.name("controller1") //
.userName("user") //
.password("password") //
.build(); //
- assertEquals(expectedControllerConfig, controllers.get("controller1"), "controller contents");
- assertEquals(2, result.ricConfigs().size());
+ ControllerConfig actual = controllers.get("controller1");
+ assertEquals(expectedControllerConfig, actual, "controller contents");
+
+ assertEquals(2, result.getRicConfigs().size());
}
private JsonObject getJsonRootObject() throws JsonIOException, JsonSyntaxException, IOException {
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigTest.java
index 7a075428..abf91f20 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigTest.java
@@ -26,7 +26,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
-import java.util.Vector;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -37,29 +36,23 @@ import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationCo
@ExtendWith(MockitoExtension.class)
class ApplicationConfigTest {
- private static final ImmutableRicConfig RIC_CONFIG_1 = ImmutableRicConfig.builder() //
+ private static final RicConfig RIC_CONFIG_1 = RicConfig.builder() //
.ricId("ric1") //
.baseUrl("ric1_url") //
- .managedElementIds(new Vector<>()) //
- .controllerName("") //
.build();
- private static final ImmutableRicConfig RIC_CONFIG_2 = ImmutableRicConfig.builder() //
+ private static final RicConfig RIC_CONFIG_2 = RicConfig.builder() //
.ricId("ric2") //
.baseUrl("ric1_url") //
- .managedElementIds(new Vector<>()) //
- .controllerName("") //
.build();
- private static final ImmutableRicConfig RIC_CONFIG_3 = ImmutableRicConfig.builder() //
+ private static final RicConfig RIC_CONFIG_3 = RicConfig.builder() //
.ricId("ric3") //
.baseUrl("ric1_url") //
- .managedElementIds(new Vector<>()) //
- .controllerName("") //
.build();
ConfigParserResult configParserResult(RicConfig... rics) {
- return ImmutableConfigParserResult.builder() //
+ return ConfigParserResult.builder() //
.ricConfigs(Arrays.asList(rics)) //
.dmaapConsumerTopicUrl("dmaapConsumerTopicUrl") //
.dmaapProducerTopicUrl("dmaapProducerTopicUrl") //
@@ -77,7 +70,7 @@ class ApplicationConfigTest {
assertEquals(RicConfigUpdate.Type.ADDED, update.get(0).getType());
assertTrue(appConfigUnderTest.getRicConfigs().contains(RIC_CONFIG_1), "Ric not added to configurations.");
- assertEquals(RIC_CONFIG_1, appConfigUnderTest.getRic(RIC_CONFIG_1.ricId()),
+ assertEquals(RIC_CONFIG_1, appConfigUnderTest.getRic(RIC_CONFIG_1.getRicId()),
"Not correct Ric retrieved from configurations.");
update = appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_1)).collectList().block();
@@ -98,11 +91,9 @@ class ApplicationConfigTest {
.setConfiguration(configParserResult(RIC_CONFIG_1, RIC_CONFIG_2, RIC_CONFIG_3)).collectList().block();
assertEquals(3, update.size());
- ImmutableRicConfig changedRicConfig = ImmutableRicConfig.builder() //
- .ricId(RIC_CONFIG_1.ricId()) //
+ RicConfig changedRicConfig = RicConfig.builder() //
+ .ricId(RIC_CONFIG_1.getRicId()) //
.baseUrl("changed_ric1_url") //
- .managedElementIds(new Vector<>()) //
- .controllerName("") //
.build();
update = appConfigUnderTest.setConfiguration(configParserResult(changedRicConfig, RIC_CONFIG_2, RIC_CONFIG_3))
@@ -110,7 +101,7 @@ class ApplicationConfigTest {
assertEquals(1, update.size());
assertEquals(RicConfigUpdate.Type.CHANGED, update.get(0).getType());
- assertEquals(changedRicConfig, appConfigUnderTest.getRic(RIC_CONFIG_1.ricId()),
+ assertEquals(changedRicConfig, appConfigUnderTest.getRic(RIC_CONFIG_1.getRicId()),
"Changed Ric not retrieved from configurations.");
}
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 569cb577..04845244 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
@@ -46,15 +46,12 @@ import java.util.List;
import org.json.JSONObject;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
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.clients.SecurityContext;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig.RicConfigUpdate;
-import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableRicConfig;
-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;
@@ -90,18 +87,16 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.TestPropertySource;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.web.reactive.function.client.WebClientResponseException;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import reactor.util.annotation.Nullable;
-@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@TestPropertySource(properties = { //
- "server.ssl.key-store=./src/test/resources/keystore.jks", //
- "app.webclient.trust-store=./src/test/resources/truststore.jks", //
+ "server.ssl.key-store=./config/keystore.jks", //
+ "app.webclient.trust-store=./config/truststore.jks", //
"app.webclient.trust-store-used=true", //
"app.vardata-directory=./target/testdata", //
"app.filepath=" //
@@ -319,8 +314,10 @@ class ApplicationTest {
@Test
void testTrustValidation() {
addRic("ric1");
+
String rsp = restClient(true).get("/rics").block(); // restClient(true) enables trust validation
assertThat(rsp).contains("ric1");
+
}
@Test
@@ -922,15 +919,20 @@ class ApplicationTest {
final Instant startTime = Instant.now();
List<Thread> threads = new ArrayList<>();
List<ConcurrencyTestRunnable> tests = new ArrayList<>();
- a1ClientFactory.setResponseDelay(Duration.ofMillis(1));
+ a1ClientFactory.setResponseDelay(Duration.ofMillis(2));
addRic("ric");
addPolicyType("type1", "ric");
addPolicyType("type2", "ric");
+ final String NON_RESPONDING_RIC = "NonRespondingRic";
+ Ric nonRespondingRic = addRic(NON_RESPONDING_RIC);
+ MockA1Client a1Client = a1ClientFactory.getOrCreateA1Client(NON_RESPONDING_RIC);
+ a1Client.setErrorInject("errorInject");
+
for (int i = 0; i < 10; ++i) {
AsyncRestClient restClient = restClient();
- ConcurrencyTestRunnable test =
- new ConcurrencyTestRunnable(restClient, supervision, a1ClientFactory, rics, policyTypes);
+ ConcurrencyTestRunnable test = new ConcurrencyTestRunnable(restClient, supervision, a1ClientFactory, rics,
+ policyTypes);
Thread thread = new Thread(test, "TestThread_" + i);
thread.start();
threads.add(thread);
@@ -944,19 +946,22 @@ class ApplicationTest {
}
assertThat(policies.size()).isZero();
logger.info("Concurrency test took " + Duration.between(startTime, Instant.now()));
+
+ assertThat(nonRespondingRic.getState()).isEqualTo(RicState.UNAVAILABLE);
+ nonRespondingRic.setState(RicState.AVAILABLE);
}
private AsyncRestClient restClient(String baseUrl, boolean useTrustValidation) {
WebClientConfig config = this.applicationConfig.getWebClientConfig();
- config = ImmutableWebClientConfig.builder() //
- .keyStoreType(config.keyStoreType()) //
- .keyStorePassword(config.keyStorePassword()) //
- .keyStore(config.keyStore()) //
- .keyPassword(config.keyPassword()) //
+ config = WebClientConfig.builder() //
+ .keyStoreType(config.getKeyStoreType()) //
+ .keyStorePassword(config.getKeyStorePassword()) //
+ .keyStore(config.getKeyStore()) //
+ .keyPassword(config.getKeyPassword()) //
.isTrustStoreUsed(useTrustValidation) //
- .trustStore(config.trustStore()) //
- .trustStorePassword(config.trustStorePassword()) //
- .httpProxyConfig(config.httpProxyConfig()) //
+ .trustStore(config.getTrustStore()) //
+ .trustStorePassword(config.getTrustStorePassword()) //
+ .httpProxyConfig(config.getHttpProxyConfig()) //
.build();
AsyncRestClientFactory f = new AsyncRestClientFactory(config, new SecurityContext(""));
@@ -1041,11 +1046,10 @@ class ApplicationTest {
if (managedElement != null) {
mes.add(managedElement);
}
- return ImmutableRicConfig.builder() //
+ return RicConfig.builder() //
.ricId(ricId) //
.baseUrl(ricId) //
.managedElementIds(mes) //
- .controllerName("") //
.build();
}
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java
index d500ba3e..51a68389 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java
@@ -30,13 +30,11 @@ import java.time.Duration;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClient;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClientFactory;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.SecurityContext;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
-import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableWebClientConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.WebClientConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics;
import org.onap.ccsdk.oran.a1policymanagementservice.tasks.RefreshConfigTask;
@@ -52,13 +50,11 @@ import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.test.context.TestPropertySource;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.web.reactive.function.client.WebClientResponseException;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
-@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@TestPropertySource(properties = { //
"server.ssl.key-store=./config/keystore.jks", //
@@ -166,15 +162,15 @@ class ConfigurationControllerTest {
private AsyncRestClient restClient() {
WebClientConfig config = this.applicationConfig.getWebClientConfig();
- config = ImmutableWebClientConfig.builder() //
- .keyStoreType(config.keyStoreType()) //
- .keyStorePassword(config.keyStorePassword()) //
- .keyStore(config.keyStore()) //
- .keyPassword(config.keyPassword()) //
+ config = WebClientConfig.builder() //
+ .keyStoreType(config.getKeyStoreType()) //
+ .keyStorePassword(config.getKeyStorePassword()) //
+ .keyStore(config.getKeyStore()) //
+ .keyPassword(config.getKeyPassword()) //
.isTrustStoreUsed(false) //
- .trustStore(config.trustStore()) //
- .trustStorePassword(config.trustStorePassword()) //
- .httpProxyConfig(config.httpProxyConfig()) //
+ .trustStore(config.getTrustStore()) //
+ .trustStorePassword(config.getTrustStorePassword()) //
+ .httpProxyConfig(config.getHttpProxyConfig()) //
.build();
AsyncRestClientFactory f = new AsyncRestClientFactory(config, new SecurityContext(""));
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 f09bd05d..2ecb9c28 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
@@ -38,7 +38,6 @@ import java.io.IOException;
import java.net.URL;
import java.time.Duration;
import java.util.Arrays;
-import java.util.HashMap;
import java.util.Optional;
import java.util.Properties;
import java.util.Vector;
@@ -55,8 +54,6 @@ import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationCo
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfigParser;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfigParser.ConfigParserResult;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ConfigurationFile;
-import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableConfigParserResult;
-import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableRicConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policies;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyTypes;
@@ -77,11 +74,10 @@ class RefreshConfigTaskTest {
ConfigurationFile configurationFileMock;
private static final String RIC_1_NAME = "ric1";
- private static final RicConfig CORRECT_RIC_CONIFG = ImmutableRicConfig.builder() //
+ private static final RicConfig CORRECT_RIC_CONIFG = RicConfig.builder() //
.ricId(RIC_1_NAME) //
.baseUrl("http://localhost:8080/") //
.managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))) //
- .controllerName("") //
.build();
private RefreshConfigTask createTestObject(boolean configFileExists) {
@@ -91,6 +87,7 @@ class RefreshConfigTaskTest {
private RefreshConfigTask createTestObject(boolean configFileExists, Rics rics, Policies policies,
boolean stubConfigFileExists) {
SecurityContext secContext = new SecurityContext("");
+
RefreshConfigTask obj =
spy(new RefreshConfigTask(configurationFileMock, appConfig, rics, policies, new Services(appConfig),
new PolicyTypes(appConfig), new A1ClientFactory(appConfig, secContext), secContext));
@@ -147,11 +144,8 @@ class RefreshConfigTaskTest {
}
ConfigParserResult configParserResult(RicConfig... rics) {
- return ImmutableConfigParserResult.builder() //
+ return ConfigParserResult.builder() //
.ricConfigs(Arrays.asList(rics)) //
- .dmaapConsumerTopicUrl("") //
- .dmaapProducerTopicUrl("") //
- .controllerConfigs(new HashMap<>()) //
.build();
}
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 b76131df..b2bf58e4 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
@@ -24,8 +24,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import java.time.Instant;
@@ -45,7 +45,7 @@ import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.SecurityContext;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
-import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableRicConfig;
+import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Lock;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Lock.LockType;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policies;
@@ -65,7 +65,7 @@ class RicSupervisionTest {
.schema("") //
.build();
- private static final Ric RIC_1 = new Ric(ImmutableRicConfig.builder() //
+ private static final Ric RIC_1 = new Ric(RicConfig.builder() //
.ricId("ric_1") //
.baseUrl("baseUrl1") //
.managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))) //
@@ -148,7 +148,8 @@ class RicSupervisionTest {
supervisorUnderTest.checkAllRics();
verify(supervisorUnderTest).checkAllRics();
- verifyNoMoreInteractions(supervisorUnderTest);
+ verify(synchronizationTaskMock, times(0)).synchronizeRic(RIC_1);
+ assertThat(RIC_1.getState()).isEqualTo(RicState.AVAILABLE);
}
@Test
@@ -156,18 +157,13 @@ class RicSupervisionTest {
doReturn(Mono.just(a1ClientMock)).when(a1ClientFactory).createA1Client(any(Ric.class));
RIC_1.setState(RicState.UNAVAILABLE);
rics.put(RIC_1);
-
RicSupervision supervisorUnderTest = spy(createRicSupervision());
-
doReturn(synchronizationTaskMock).when(supervisorUnderTest).createSynchronizationTask();
doReturn(Mono.just(RIC_1)).when(synchronizationTaskMock).synchronizeRic(any());
-
supervisorUnderTest.checkAllRics();
-
- verify(supervisorUnderTest).checkAllRics();
- verify(supervisorUnderTest).createSynchronizationTask();
verify(synchronizationTaskMock).synchronizeRic(RIC_1);
- verifyNoMoreInteractions(supervisorUnderTest);
+
+ assertThat(RIC_1.getState()).isEqualTo(RicState.UNAVAILABLE);
}
@Test
@@ -181,7 +177,8 @@ class RicSupervisionTest {
supervisorUnderTest.checkAllRics();
verify(supervisorUnderTest).checkAllRics();
- verifyNoMoreInteractions(supervisorUnderTest);
+ verify(synchronizationTaskMock, times(0)).synchronizeRic(RIC_1);
+ assertThat(RIC_1.getState()).isEqualTo(RicState.SYNCHRONIZING);
}
@Test
@@ -197,7 +194,8 @@ class RicSupervisionTest {
supervisorUnderTest.checkAllRics();
verify(supervisorUnderTest).checkAllRics();
- verifyNoMoreInteractions(supervisorUnderTest);
+ verify(synchronizationTaskMock, times(0)).synchronizeRic(RIC_1);
+
assertThat(RIC_1.getState()).isEqualTo(RicState.UNAVAILABLE);
}
@@ -219,9 +217,9 @@ class RicSupervisionTest {
supervisorUnderTest.checkAllRics();
verify(supervisorUnderTest).checkAllRics();
- verify(supervisorUnderTest).createSynchronizationTask();
verify(synchronizationTaskMock).synchronizeRic(RIC_1);
- verifyNoMoreInteractions(supervisorUnderTest);
+
+ assertThat(RIC_1.getState()).isEqualTo(RicState.UNAVAILABLE);
}
@Test
@@ -242,9 +240,9 @@ class RicSupervisionTest {
supervisorUnderTest.checkAllRics();
verify(supervisorUnderTest).checkAllRics();
- verify(supervisorUnderTest).createSynchronizationTask();
verify(synchronizationTaskMock).synchronizeRic(RIC_1);
- verifyNoMoreInteractions(supervisorUnderTest);
+
+ assertThat(RIC_1.getState()).isEqualTo(RicState.UNAVAILABLE);
}
@Test
@@ -261,7 +259,9 @@ class RicSupervisionTest {
supervisorUnderTest.checkAllRics();
verify(supervisorUnderTest).checkAllRics();
- verifyNoMoreInteractions(supervisorUnderTest);
+ verify(synchronizationTaskMock, times(0)).synchronizeRic(RIC_1);
+
+ assertThat(RIC_1.getState()).isEqualTo(RicState.UNAVAILABLE);
}
@Test
@@ -283,9 +283,9 @@ class RicSupervisionTest {
supervisorUnderTest.checkAllRics();
verify(supervisorUnderTest).checkAllRics();
- verify(supervisorUnderTest).createSynchronizationTask();
verify(synchronizationTaskMock).synchronizeRic(RIC_1);
- verifyNoMoreInteractions(supervisorUnderTest);
+
+ assertThat(RIC_1.getState()).isEqualTo(RicState.UNAVAILABLE);
}
@Test
@@ -311,9 +311,8 @@ class RicSupervisionTest {
supervisorUnderTest.checkAllRics();
verify(supervisorUnderTest).checkAllRics();
- verify(supervisorUnderTest).createSynchronizationTask();
verify(synchronizationTaskMock).synchronizeRic(RIC_1);
- verifyNoMoreInteractions(supervisorUnderTest);
+ assertThat(RIC_1.getState()).isEqualTo(RicState.UNAVAILABLE);
}
@SuppressWarnings("unchecked")
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 a5795ac9..6386441c 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
@@ -46,7 +46,8 @@ import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClientFactory;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.SecurityContext;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
-import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableRicConfig;
+import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig;
+import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policies;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policy;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyType;
@@ -56,6 +57,8 @@ 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.springframework.web.reactive.function.client.WebClientRequestException;
+import org.springframework.web.reactive.function.client.WebClientResponseException;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -105,10 +108,9 @@ class RicSynchronizationTaskTest {
@BeforeEach
void init() {
- ric1 = new Ric(ImmutableRicConfig.builder() //
+ ric1 = new Ric(RicConfig.builder() //
.ricId(RIC_1_NAME) //
.baseUrl("baseUrl1") //
- .managedElementIds(Collections.emptyList()) //
.controllerName("controllerName") //
.build());
policy1 = createPolicy("policyId1", false);
@@ -149,6 +151,35 @@ class RicSynchronizationTaskTest {
}
@Test
+ void ricIdleAndErrorDeletingPoliciesAllTheTime_thenSynchronizationWithFailedRecovery() {
+ setUpCreationOfA1Client();
+ simulateRicWithNoPolicyTypes();
+ policies.put(policy1);
+ WebClientResponseException exception = new WebClientResponseException(404, "", null, null, null);
+ when(a1ClientMock.deleteAllPolicies()).thenReturn(Flux.error(exception));
+ RicSynchronizationTask synchronizerUnderTest = createTask();
+ ric1.setState(RicState.AVAILABLE);
+ synchronizerUnderTest.run(ric1);
+ await().untilAsserted(() -> RicState.UNAVAILABLE.equals(ric1.getState()));
+ assertThat(policies.size()).isZero();
+ assertThat(ric1.getState()).isEqualTo(RicState.UNAVAILABLE);
+ }
+
+ @Test
+ void testConnectionError() {
+ setUpCreationOfA1Client();
+ simulateRicWithNoPolicyTypes();
+ policies.put(policy1);
+ WebClientRequestException exception =
+ new WebClientRequestException(new ServiceException("x"), null, null, null);
+ when(a1ClientMock.deleteAllPolicies()).thenReturn(Flux.error(exception));
+ RicSynchronizationTask synchronizerUnderTest = createTask();
+ ric1.setState(RicState.AVAILABLE);
+ synchronizerUnderTest.run(ric1);
+ await().untilAsserted(() -> RicState.UNAVAILABLE.equals(ric1.getState()));
+ }
+
+ @Test
void ricIdlePolicyTypeInRepo_thenSynchronizationWithReuseOfTypeFromRepoAndCorrectServiceNotified() {
rics.put(ric1);
ric1.setState(RicState.AVAILABLE);
@@ -234,58 +265,6 @@ class RicSynchronizationTaskTest {
assertThat(ric1.getState()).isEqualTo(RicState.AVAILABLE);
}
- @Test
- void ricIdleAndErrorDeletingPoliciesFirstTime_thenSynchronizationWithDeletionOfPolicies() {
- ric1.setState(RicState.AVAILABLE);
- rics.put(ric1);
-
- policies.put(policy1);
-
- setUpCreationOfA1Client();
- simulateRicWithNoPolicyTypes();
-
- when(a1ClientMock.deleteAllPolicies()) //
- .thenReturn(Flux.error(new Exception("Exception"))) //
- .thenReturn(Flux.just("OK"));
-
- RicSynchronizationTask synchronizerUnderTest = createTask();
-
- ric1.setState(RicState.UNAVAILABLE);
- synchronizerUnderTest.run(ric1);
- await().untilAsserted(() -> RicState.AVAILABLE.equals(ric1.getState()));
-
- verify(a1ClientMock, times(2)).deleteAllPolicies();
- verifyNoMoreInteractions(a1ClientMock);
-
- assertThat(policyTypes.size()).isZero();
- assertThat(policies.size()).isZero();
- assertThat(ric1.getState()).isEqualTo(RicState.AVAILABLE);
- }
-
- @Test
- void ricIdleAndErrorDeletingPoliciesAllTheTime_thenSynchronizationWithFailedRecovery() {
- setUpCreationOfA1Client();
- simulateRicWithNoPolicyTypes();
-
- policies.put(policy1);
-
- String originalErrorMessage = "Exception";
- when(a1ClientMock.deleteAllPolicies()).thenReturn(Flux.error(new Exception(originalErrorMessage)));
-
- RicSynchronizationTask synchronizerUnderTest = createTask();
-
- ric1.setState(RicState.AVAILABLE);
- synchronizerUnderTest.run(ric1);
- await().untilAsserted(() -> RicState.UNAVAILABLE.equals(ric1.getState()));
-
- verify(a1ClientMock, times(2)).deleteAllPolicies();
- verifyNoMoreInteractions(a1ClientMock);
-
- assertThat(policyTypes.size()).isZero();
- assertThat(policies.size()).isZero();
- assertThat(ric1.getState()).isEqualTo(RicState.UNAVAILABLE);
- }
-
private void setUpCreationOfA1Client() {
when(a1ClientFactoryMock.createA1Client(any(Ric.class))).thenReturn(Mono.just(a1ClientMock));
doReturn(Flux.empty()).when(a1ClientMock).deleteAllPolicies();
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 294b220c..c8c7c723 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
@@ -34,7 +34,6 @@ import ch.qos.logback.core.read.ListAppender;
import java.time.Duration;
import java.time.Instant;
-import java.util.Collections;
import org.awaitility.Durations;
import org.junit.jupiter.api.Test;
@@ -44,7 +43,6 @@ 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.configuration.ApplicationConfig;
-import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableRicConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policies;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policy;
@@ -70,11 +68,9 @@ class ServiceSupervisionTest {
private Services services;
private Service service;
private Policies policies;
- private RicConfig ricConfig = ImmutableRicConfig.builder() //
+ private RicConfig ricConfig = RicConfig.builder() //
.ricId(RIC_NAME) //
.baseUrl("baseUrl") //
- .managedElementIds(Collections.emptyList()) //
- .controllerName("") //
.build();
private Ric ric = new Ric(ricConfig);
private PolicyType policyType = PolicyType.builder() //
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/MockA1Client.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/MockA1Client.java
index 2a3b28ef..b76f1e72 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/MockA1Client.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/MockA1Client.java
@@ -28,6 +28,8 @@ import java.time.Duration;
import java.util.List;
import java.util.Vector;
+import lombok.Setter;
+
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policies;
@@ -44,7 +46,12 @@ import reactor.core.publisher.MonoSink;
public class MockA1Client implements A1Client {
Policies policies;
private final PolicyTypes policyTypes;
- private final Duration asynchDelay;
+
+ @Setter
+ private Duration asynchDelay;
+
+ @Setter
+ private String errorInject;
public MockA1Client(String ricId, ApplicationConfig appConfig, PolicyTypes policyTypes, Duration asynchDelay) {
this.policyTypes = policyTypes;
@@ -117,14 +124,19 @@ public class MockA1Client implements A1Client {
}
private <T> Mono<T> mono(T value) {
- if (this.asynchDelay.isZero()) {
- return Mono.just(value);
- } else {
- return Mono.create(monoSink -> asynchResponse(monoSink, value));
+ Mono<T> res = Mono.just(value);
+ if (!this.asynchDelay.isZero()) {
+ res = Mono.create(monoSink -> asynchResponse(monoSink, value));
}
+
+ if (this.errorInject != null) {
+ res = res.flatMap(x -> monoError(this.errorInject, HttpStatus.BAD_GATEWAY));
+ }
+
+ return res;
}
- public static Mono<String> monoError(String responseBody, HttpStatus status) {
+ public static <T> Mono<T> monoError(String responseBody, HttpStatus status) {
byte[] responseBodyBytes = responseBody.getBytes(StandardCharsets.UTF_8);
WebClientResponseException a1Exception = new WebClientResponseException(status.value(),
status.getReasonPhrase(), null, responseBodyBytes, StandardCharsets.UTF_8, null);
diff --git a/a1-policy-management/src/test/resources/keystore.jks b/a1-policy-management/src/test/resources/keystore.jks
deleted file mode 100644
index 675785b4..00000000
--- a/a1-policy-management/src/test/resources/keystore.jks
+++ /dev/null
Binary files differ
diff --git a/a1-policy-management/src/test/resources/test_application_configuration.json b/a1-policy-management/src/test/resources/test_application_configuration.json
index 959f53fd..fef2382a 100644
--- a/a1-policy-management/src/test/resources/test_application_configuration.json
+++ b/a1-policy-management/src/test/resources/test_application_configuration.json
@@ -1,4 +1,4 @@
-{
+{
"config": {
"description": "Application configuration",
"ric": [
@@ -13,6 +13,7 @@
{
"name": "ric2",
"baseUrl": "http://localhost:8081/",
+ "customAdapterClass": "org.onap.ccsdk.oran.a1policymanagementservice.clients.StdA1ClientVersion2$Factory",
"managedElementIds": [
"kista_3",
"kista_4"
diff --git a/a1-policy-management/src/test/resources/test_application_configuration_with_dmaap_config.json b/a1-policy-management/src/test/resources/test_application_configuration_with_dmaap_config.json
index b00720c3..6e1de75e 100644
--- a/a1-policy-management/src/test/resources/test_application_configuration_with_dmaap_config.json
+++ b/a1-policy-management/src/test/resources/test_application_configuration_with_dmaap_config.json
@@ -1,6 +1,6 @@
{
"config": {
- "//description" : "Test",
+ "description": "Test",
"controller": [
{
"name": "controller1",
@@ -14,6 +14,7 @@
"name": "ric1",
"controller": "controller1",
"baseUrl": "http://localhost:8083/",
+ "customAdapterClass": "org.onap.ccsdk.oran.a1policymanagementservice.clients.StdA1ClientVersion2$Factory",
"managedElementIds": [
"kista_1",
"kista_2"
@@ -53,4 +54,4 @@
}
}
}
-}
+} \ No newline at end of file
diff --git a/a1-policy-management/src/test/resources/truststore.jks b/a1-policy-management/src/test/resources/truststore.jks
deleted file mode 100644
index e883cd67..00000000
--- a/a1-policy-management/src/test/resources/truststore.jks
+++ /dev/null
Binary files differ