aboutsummaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src/test/java
diff options
context:
space:
mode:
authorPatrikBuhr <patrik.buhr@est.tech>2020-10-08 16:55:03 +0200
committerPatrikBuhr <patrik.buhr@est.tech>2020-10-09 09:19:05 +0200
commit49763b0cf15a58b804e19e1d2907cb46044fd552 (patch)
tree48cd13aedaa40e9aa955985420ea4389874990da /a1-policy-management/src/test/java
parent535be96db56357f41970fd256abe7eb35fe4d98a (diff)
Improvent of AsynchRestClient
Previously, the cert and the trust databases was read each time a AsynchRestClient was created. Now, they are only read once. This has performance impact. Change-Id: I7a480a64542187d79ffc2ee7427e0140f45afadc 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/controllers/v1/ApplicationTest.java4
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java6
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageHandlerTest.java3
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java18
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java27
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTaskTest.java27
6 files changed, 41 insertions, 44 deletions
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 f8c15b6a..97d0b504 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
@@ -44,6 +44,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
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;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableWebClientConfig;
@@ -722,7 +723,8 @@ class ApplicationTest {
.trustStorePassword(config.trustStorePassword()) //
.build();
- return new AsyncRestClient(baseUrl(), config);
+ AsyncRestClientFactory f = new AsyncRestClientFactory(config);
+ return f.createRestClient(baseUrl());
}
private AsyncRestClient restClient() {
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 100e841c..5e09099f 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,6 +46,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
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;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableWebClientConfig;
@@ -206,7 +207,6 @@ class ApplicationTest {
}
@Test
-
void createApiDoc() throws FileNotFoundException {
String url = "https://localhost:" + this.port + "/v2/api-docs";
ResponseEntity<String> resp = restClient("", false).getForEntity(url).block();
@@ -790,7 +790,9 @@ class ApplicationTest {
.trustStorePassword(config.trustStorePassword()) //
.build();
- return new AsyncRestClient(baseUrl, config);
+ AsyncRestClientFactory f = new AsyncRestClientFactory(config);
+ return f.createRestClient(baseUrl);
+
}
private AsyncRestClient restClient(boolean useTrustValidation) {
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageHandlerTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageHandlerTest.java
index bab09931..99468811 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageHandlerTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageHandlerTest.java
@@ -46,8 +46,6 @@ import org.mockito.ArgumentCaptor;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClient;
import org.onap.ccsdk.oran.a1policymanagementservice.dmaap.DmaapRequestMessage.Operation;
import org.onap.ccsdk.oran.a1policymanagementservice.utils.LoggingUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -57,7 +55,6 @@ import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
class DmaapMessageHandlerTest {
- private static final Logger logger = LoggerFactory.getLogger(DmaapMessageHandlerTest.class);
private static final String URL = "url";
private final AsyncRestClient dmaapClient = mock(AsyncRestClient.class);
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 c62626c1..2e96b680 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
@@ -82,7 +82,6 @@ import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClient;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.ImmutableEnvProperties;
-import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -123,6 +122,9 @@ class RefreshConfigTaskTest {
private RefreshConfigTask createTestObject(boolean configFileExists, Rics rics, Policies policies,
boolean stubConfigFileExists) {
+ doReturn("fileName").when(appConfig).getLocalConfigurationFilePath();
+ doReturn(null).when(appConfig).getWebClientConfig();
+
RefreshConfigTask obj = spy(new RefreshConfigTask(appConfig, rics, policies, new Services(), new PolicyTypes(),
new A1ClientFactory(appConfig)));
if (stubConfigFileExists) {
@@ -132,18 +134,6 @@ class RefreshConfigTaskTest {
}
@Test
- void startWithStubbedRefresh_thenTerminationLogged() {
- refreshTaskUnderTest = this.createTestObject(CONFIG_FILE_DOES_NOT_EXIST, null, null, false);
- doReturn(Flux.empty()).when(refreshTaskUnderTest).createRefreshTask();
-
- final ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(RefreshConfigTask.class, ERROR);
-
- refreshTaskUnderTest.start();
-
- assertThat(logAppender.list.get(0).getFormattedMessage()).isEqualTo("Configuration refresh terminated");
- }
-
- @Test
void stop_thenTaskIsDisposed() throws Exception {
refreshTaskUnderTest = this.createTestObject(CONFIG_FILE_DOES_NOT_EXIST, null, null, false);
refreshTaskUnderTest.systemEnvironment = new Properties();
@@ -160,7 +150,6 @@ class RefreshConfigTaskTest {
refreshTaskUnderTest.systemEnvironment = new Properties();
// When
doReturn(getCorrectJson()).when(refreshTaskUnderTest).createInputStream(any());
- doReturn("fileName").when(appConfig).getLocalConfigurationFilePath();
StepVerifier //
.create(refreshTaskUnderTest.createRefreshTask()) //
@@ -189,7 +178,6 @@ class RefreshConfigTaskTest {
// When
final String JUNK_JSON = "{\"junk }";
doReturn(getJsonSteam(JUNK_JSON)).when(refreshTaskUnderTest).createInputStream(any());
- doReturn("fileName").when(appConfig).getLocalConfigurationFilePath();
final ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(RefreshConfigTask.class, ERROR);
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 25a7ddc4..90292d30 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
@@ -137,7 +137,8 @@ class RicSupervisionTest {
setUpGetPolicyIdentitiesToReturn(new ArrayList<>(Arrays.asList(POLICY_1_ID)));
setUpGetPolicyTypeIdentitiesToReturn(new ArrayList<>(Arrays.asList(POLICY_TYPE_1_NAME)));
- RicSupervision supervisorUnderTest = spy(new RicSupervision(rics, policies, a1ClientFactory, types, null));
+ RicSupervision supervisorUnderTest =
+ spy(new RicSupervision(rics, policies, a1ClientFactory, types, null, null));
supervisorUnderTest.checkAllRics();
@@ -151,7 +152,8 @@ class RicSupervisionTest {
RIC_1.setState(RicState.UNAVAILABLE);
rics.put(RIC_1);
- RicSupervision supervisorUnderTest = spy(new RicSupervision(rics, policies, a1ClientFactory, types, null));
+ RicSupervision supervisorUnderTest =
+ spy(new RicSupervision(rics, policies, a1ClientFactory, types, null, null));
doReturn(synchronizationTaskMock).when(supervisorUnderTest).createSynchronizationTask();
@@ -169,7 +171,8 @@ class RicSupervisionTest {
RIC_1.setState(RicState.SYNCHRONIZING);
rics.put(RIC_1);
- RicSupervision supervisorUnderTest = spy(new RicSupervision(rics, policies, a1ClientFactory, types, null));
+ RicSupervision supervisorUnderTest =
+ spy(new RicSupervision(rics, policies, a1ClientFactory, types, null, null));
supervisorUnderTest.checkAllRics();
@@ -186,7 +189,8 @@ class RicSupervisionTest {
setUpGetPolicyIdentitiesToReturn(new Exception("Failed"));
- RicSupervision supervisorUnderTest = spy(new RicSupervision(rics, policies, a1ClientFactory, types, null));
+ RicSupervision supervisorUnderTest =
+ spy(new RicSupervision(rics, policies, a1ClientFactory, types, null, null));
supervisorUnderTest.checkAllRics();
verify(supervisorUnderTest).checkAllRics();
@@ -205,7 +209,8 @@ class RicSupervisionTest {
setUpGetPolicyIdentitiesToReturn(new ArrayList<>(Arrays.asList(POLICY_1_ID)));
- RicSupervision supervisorUnderTest = spy(new RicSupervision(rics, policies, a1ClientFactory, types, null));
+ RicSupervision supervisorUnderTest =
+ spy(new RicSupervision(rics, policies, a1ClientFactory, types, null, null));
doReturn(synchronizationTaskMock).when(supervisorUnderTest).createSynchronizationTask();
@@ -228,7 +233,8 @@ class RicSupervisionTest {
setUpGetPolicyIdentitiesToReturn(new ArrayList<>(Arrays.asList(POLICY_1_ID, "Another_policy")));
- RicSupervision supervisorUnderTest = spy(new RicSupervision(rics, policies, a1ClientFactory, types, null));
+ RicSupervision supervisorUnderTest =
+ spy(new RicSupervision(rics, policies, a1ClientFactory, types, null, null));
doReturn(synchronizationTaskMock).when(supervisorUnderTest).createSynchronizationTask();
@@ -250,7 +256,8 @@ class RicSupervisionTest {
setUpGetPolicyIdentitiesToReturn(Collections.emptyList());
setUpGetPolicyTypeIdentitiesToReturn(new Exception("Failed"));
- RicSupervision supervisorUnderTest = spy(new RicSupervision(rics, policies, a1ClientFactory, types, null));
+ RicSupervision supervisorUnderTest =
+ spy(new RicSupervision(rics, policies, a1ClientFactory, types, null, null));
supervisorUnderTest.checkAllRics();
verify(supervisorUnderTest).checkAllRics();
@@ -269,7 +276,8 @@ class RicSupervisionTest {
setUpGetPolicyIdentitiesToReturn(Collections.emptyList());
setUpGetPolicyTypeIdentitiesToReturn(new ArrayList<>(Arrays.asList(POLICY_TYPE_1_NAME, "another_policy_type")));
- RicSupervision supervisorUnderTest = spy(new RicSupervision(rics, policies, a1ClientFactory, types, null));
+ RicSupervision supervisorUnderTest =
+ spy(new RicSupervision(rics, policies, a1ClientFactory, types, null, null));
doReturn(synchronizationTaskMock).when(supervisorUnderTest).createSynchronizationTask();
@@ -297,7 +305,8 @@ class RicSupervisionTest {
setUpGetPolicyIdentitiesToReturn(Collections.emptyList());
setUpGetPolicyTypeIdentitiesToReturn(new ArrayList<>(Arrays.asList(POLICY_TYPE_1_NAME, "another_policy_type")));
- RicSupervision supervisorUnderTest = spy(new RicSupervision(rics, policies, a1ClientFactory, types, null));
+ RicSupervision supervisorUnderTest =
+ spy(new RicSupervision(rics, policies, a1ClientFactory, types, null, null));
doReturn(synchronizationTaskMock).when(supervisorUnderTest).createSynchronizationTask();
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 e1c0c6b8..0a7fc850 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
@@ -49,6 +49,7 @@ 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.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableRicConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.ImmutablePolicy;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.ImmutablePolicyType;
@@ -118,6 +119,11 @@ class RicSynchronizationTaskTest {
RIC_1.clearSupportedPolicyTypes();
}
+ private RicSynchronizationTask createTask() {
+ ApplicationConfig config = new ApplicationConfig();
+ return new RicSynchronizationTask(a1ClientFactoryMock, policyTypes, policies, services, config);
+ };
+
@Test
void ricAlreadySynchronizing_thenNoSynchronization() {
RIC_1.setState(RicState.SYNCHRONIZING);
@@ -126,8 +132,7 @@ class RicSynchronizationTaskTest {
policyTypes.put(POLICY_TYPE_1);
policies.put(POLICY_1);
- RicSynchronizationTask synchronizerUnderTest =
- new RicSynchronizationTask(a1ClientFactoryMock, policyTypes, policies, services);
+ RicSynchronizationTask synchronizerUnderTest = createTask();
synchronizerUnderTest.run(RIC_1);
@@ -152,8 +157,7 @@ class RicSynchronizationTaskTest {
setUpCreationOfA1Client();
simulateRicWithOnePolicyType();
- RicSynchronizationTask synchronizerUnderTest =
- spy(new RicSynchronizationTask(a1ClientFactoryMock, policyTypes, policies, services));
+ RicSynchronizationTask synchronizerUnderTest = spy(createTask());
AsyncRestClient restClientMock = setUpCreationOfAsyncRestClient(synchronizerUnderTest);
when(restClientMock.put(anyString(), anyString())).thenReturn(Mono.just("Ok"));
@@ -184,8 +188,7 @@ class RicSynchronizationTaskTest {
String typeSchema = "schema";
when(a1ClientMock.getPolicyTypeSchema(POLICY_TYPE_1_NAME)).thenReturn(Mono.just(typeSchema));
- RicSynchronizationTask synchronizerUnderTest =
- new RicSynchronizationTask(a1ClientFactoryMock, policyTypes, policies, services);
+ RicSynchronizationTask synchronizerUnderTest = createTask();
synchronizerUnderTest.run(RIC_1);
@@ -213,8 +216,7 @@ class RicSynchronizationTaskTest {
when(a1ClientMock.deleteAllPolicies()).thenReturn(Flux.just("OK"));
when(a1ClientMock.putPolicy(any(Policy.class))).thenReturn(Mono.just("OK"));
- RicSynchronizationTask synchronizerUnderTest =
- new RicSynchronizationTask(a1ClientFactoryMock, policyTypes, policies, services);
+ RicSynchronizationTask synchronizerUnderTest = createTask();
synchronizerUnderTest.run(RIC_1);
@@ -240,8 +242,7 @@ class RicSynchronizationTaskTest {
.thenReturn(Flux.error(new Exception("Exception"))) //
.thenReturn(Flux.just("OK"));
- RicSynchronizationTask synchronizerUnderTest =
- new RicSynchronizationTask(a1ClientFactoryMock, policyTypes, policies, services);
+ RicSynchronizationTask synchronizerUnderTest = createTask();
synchronizerUnderTest.run(RIC_1);
@@ -265,8 +266,7 @@ class RicSynchronizationTaskTest {
String originalErrorMessage = "Exception";
when(a1ClientMock.deleteAllPolicies()).thenReturn(Flux.error(new Exception(originalErrorMessage)));
- RicSynchronizationTask synchronizerUnderTest =
- new RicSynchronizationTask(a1ClientFactoryMock, policyTypes, policies, services);
+ RicSynchronizationTask synchronizerUnderTest = createTask();
final ListAppender<ILoggingEvent> logAppender =
LoggingUtils.getLogListAppender(RicSynchronizationTask.class, WARN);
@@ -298,8 +298,7 @@ class RicSynchronizationTaskTest {
final ListAppender<ILoggingEvent> logAppender =
LoggingUtils.getLogListAppender(RicSynchronizationTask.class, WARN);
- RicSynchronizationTask synchronizerUnderTest =
- spy(new RicSynchronizationTask(a1ClientFactoryMock, policyTypes, policies, services));
+ RicSynchronizationTask synchronizerUnderTest = spy(createTask());
AsyncRestClient restClientMock = setUpCreationOfAsyncRestClient(synchronizerUnderTest);
String originalErrorMessage = "Exception";