aboutsummaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src/test
diff options
context:
space:
mode:
authorPatrikBuhr <patrik.buhr@est.tech>2021-08-09 10:20:55 +0200
committerPatrikBuhr <patrik.buhr@est.tech>2021-08-18 10:01:22 +0200
commite7f0355378e636261ad960626d2eb92f317b3f16 (patch)
tree086163ee6b8e975d584f2b1341da6a9498dd82d5 /a1-policy-management/src/test
parentf8d4f42ed21463a636b8217b9882b90b4c3468a3 (diff)
Update springboot version of the Policy Management Service (version 2.5)
This required some changes due to not backwards compatible changes. - The API to springboot WebClient is changed, which is wrapped in class AsyncRestClient. - The validation of trusted certs is made more strict. The Owner field of the peer cert must contain the name ofthe using host. The uniitest tests this, so the cert in config is updated (Owner is "localhost"). Change-Id: Ia954b0ee5942884cd4b9fd82769bc8089dc35c53 Issue-ID: CCSDK-3421 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/controllers/v1/ApplicationTest.java3
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java18
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java4
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTaskTest.java8
-rw-r--r--a1-policy-management/src/test/resources/keystore.jksbin0 -> 5019 bytes
-rw-r--r--a1-policy-management/src/test/resources/truststore.jksbin0 -> 3699 bytes
6 files changed, 21 insertions, 12 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 bc22c14d..240dd1df 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
@@ -193,8 +193,7 @@ class ApplicationTest {
this.addPolicyType("", "ric2");
url = "/rics?policyType=";
- // This tests also validation of trusted certs restClient(true)
- rsp = restClient(true).get(url).block();
+ rsp = restClient().get(url).block();
assertThat(rsp).contains("ric2") //
.doesNotContain("ric1") //
.contains("AVAILABLE");
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 ab9b7266..e31d0b91 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
@@ -97,8 +97,8 @@ import reactor.util.annotation.Nullable;
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@TestPropertySource(properties = { //
- "server.ssl.key-store=./config/keystore.jks", //
- "app.webclient.trust-store=./config/truststore.jks", //
+ "server.ssl.key-store=./src/test/resources/keystore.jks", //
+ "app.webclient.trust-store=./src/test/resources/truststore.jks", //
"app.vardata-directory=./target/testdata", //
"app.filepath=" //
})
@@ -309,6 +309,13 @@ class ApplicationTest {
}
@Test
+ void testTrustValidation() {
+ addRic("ric1");
+ String rsp = restClient(true).get("/rics").block(); // restClient(true) enables trust validation
+ assertThat(rsp).contains("ric1");
+ }
+
+ @Test
void testGetRics() throws Exception {
addRic("ric1");
this.addPolicyType("type1", "ric1");
@@ -320,9 +327,7 @@ class ApplicationTest {
addRic("ric2");
this.addPolicyType("", "ric2");
url = "/rics?policytype_id=";
-
- // This tests also validation of trusted certs restClient(true)
- rsp = restClient(true).get(url).block();
+ rsp = restClient().get(url).block();
assertThat(rsp).contains("ric2") //
.doesNotContain("ric1") //
.contains("AVAILABLE");
@@ -891,8 +896,7 @@ class ApplicationTest {
}
private AsyncRestClient restClient(boolean useTrustValidation) {
- String baseUrl = "https://localhost:" + port + Consts.V2_API_ROOT;
- return restClient(baseUrl, useTrustValidation);
+ return restClient(baseUrl() + Consts.V2_API_ROOT, useTrustValidation);
}
private AsyncRestClient restClient() {
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 030b831f..adb29a70 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
@@ -162,14 +162,14 @@ class ConfigurationControllerTest {
.keyStorePassword(config.keyStorePassword()) //
.keyStore(config.keyStore()) //
.keyPassword(config.keyPassword()) //
- .isTrustStoreUsed(true) //
+ .isTrustStoreUsed(false) //
.trustStore(config.trustStore()) //
.trustStorePassword(config.trustStorePassword()) //
.httpProxyConfig(config.httpProxyConfig()) //
.build();
AsyncRestClientFactory f = new AsyncRestClientFactory(config);
- return f.createRestClient("https://localhost:" + port);
+ return f.createRestClientNoHttpProxy("https://localhost:" + port);
}
}
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 9bd5c502..fae05475 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
@@ -21,6 +21,7 @@
package org.onap.ccsdk.oran.a1policymanagementservice.tasks;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
@@ -67,6 +68,7 @@ class RicSynchronizationTaskTest {
.build();
private static final String RIC_1_NAME = "ric1";
+
private static final Ric RIC_1 = new Ric(ImmutableRicConfig.builder() //
.ricId(RIC_1_NAME) //
.baseUrl("baseUrl1") //
@@ -160,6 +162,7 @@ class RicSynchronizationTaskTest {
RicSynchronizationTask synchronizerUnderTest = spy(createTask());
synchronizerUnderTest.run(RIC_1);
+ await().untilAsserted(() -> RicState.AVAILABLE.equals(RIC_1.getState()));
verify(a1ClientMock, times(1)).getPolicyTypeIdentities();
verifyNoMoreInteractions(a1ClientMock);
@@ -184,6 +187,7 @@ class RicSynchronizationTaskTest {
RicSynchronizationTask synchronizerUnderTest = createTask();
synchronizerUnderTest.run(RIC_1);
+ await().untilAsserted(() -> RicState.AVAILABLE.equals(RIC_1.getState()));
verify(a1ClientMock).getPolicyTypeIdentities();
verifyNoMoreInteractions(a1ClientMock);
@@ -213,7 +217,7 @@ class RicSynchronizationTaskTest {
RicSynchronizationTask synchronizerUnderTest = createTask();
synchronizerUnderTest.run(RIC_1);
-
+ await().untilAsserted(() -> RicState.AVAILABLE.equals(RIC_1.getState()));
verify(a1ClientMock).deleteAllPolicies();
verify(a1ClientMock).putPolicy(POLICY_1);
verifyNoMoreInteractions(a1ClientMock);
@@ -240,6 +244,7 @@ class RicSynchronizationTaskTest {
RicSynchronizationTask synchronizerUnderTest = createTask();
synchronizerUnderTest.run(RIC_1);
+ await().untilAsserted(() -> RicState.AVAILABLE.equals(RIC_1.getState()));
verify(a1ClientMock, times(2)).deleteAllPolicies();
verifyNoMoreInteractions(a1ClientMock);
@@ -264,6 +269,7 @@ class RicSynchronizationTaskTest {
RicSynchronizationTask synchronizerUnderTest = createTask();
synchronizerUnderTest.run(RIC_1);
+ await().untilAsserted(() -> RicState.AVAILABLE.equals(RIC_1.getState()));
verify(a1ClientMock, times(2)).deleteAllPolicies();
verifyNoMoreInteractions(a1ClientMock);
diff --git a/a1-policy-management/src/test/resources/keystore.jks b/a1-policy-management/src/test/resources/keystore.jks
new file mode 100644
index 00000000..675785b4
--- /dev/null
+++ b/a1-policy-management/src/test/resources/keystore.jks
Binary files differ
diff --git a/a1-policy-management/src/test/resources/truststore.jks b/a1-policy-management/src/test/resources/truststore.jks
new file mode 100644
index 00000000..e883cd67
--- /dev/null
+++ b/a1-policy-management/src/test/resources/truststore.jks
Binary files differ