summaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src
diff options
context:
space:
mode:
Diffstat (limited to 'a1-policy-management/src')
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClient.java36
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClientFactory.java3
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1Client.java2
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion1.java2
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion2.java2
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/Consts.java2
-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
12 files changed, 40 insertions, 40 deletions
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClient.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClient.java
index 2b8c4fa6..ad2e221f 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClient.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClient.java
@@ -42,9 +42,7 @@ import org.springframework.web.reactive.function.client.WebClientResponseExcepti
import reactor.core.publisher.Mono;
import reactor.netty.http.client.HttpClient;
-import reactor.netty.resources.ConnectionProvider;
-import reactor.netty.tcp.ProxyProvider.Proxy;
-import reactor.netty.tcp.TcpClient;
+import reactor.netty.transport.ProxyProvider;
/**
* Generic reactive REST client.
@@ -200,32 +198,32 @@ public class AsyncRestClient {
&& !httpProxyConfig.httpProxyHost().isEmpty();
}
- private TcpClient createTcpClient() {
- TcpClient client = TcpClient.create(ConnectionProvider.newConnection()) //
+ private HttpClient buildHttpClient() {
+ HttpClient httpClient = HttpClient.create() //
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10_000) //
.doOnConnected(connection -> {
connection.addHandlerLast(new ReadTimeoutHandler(30));
connection.addHandlerLast(new WriteTimeoutHandler(30));
});
+
if (this.sslContext != null) {
- client = client.secure(c -> c.sslContext(sslContext));
+ httpClient = httpClient.secure(ssl -> ssl.sslContext(sslContext));
}
+
if (isHttpProxyConfigured()) {
- client = client.proxy(proxy -> proxy.type(Proxy.HTTP).host(httpProxyConfig.httpProxyHost())
- .port(httpProxyConfig.httpProxyPort()));
+ httpClient = httpClient.proxy(proxy -> proxy.type(ProxyProvider.Proxy.HTTP)
+ .host(httpProxyConfig.httpProxyHost()).port(httpProxyConfig.httpProxyPort()));
}
- return client;
+ return httpClient;
}
- private WebClient createWebClient(String baseUrl, TcpClient tcpClient) {
- HttpClient httpClient = HttpClient.from(tcpClient);
-
- ReactorClientHttpConnector connector = new ReactorClientHttpConnector(httpClient);
+ private WebClient buildWebClient(String baseUrl) {
+ final HttpClient httpClient = buildHttpClient();
ExchangeStrategies exchangeStrategies = ExchangeStrategies.builder() //
.codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(-1)) //
.build();
return WebClient.builder() //
- .clientConnector(connector) //
+ .clientConnector(new ReactorClientHttpConnector(httpClient)) //
.baseUrl(baseUrl) //
.exchangeStrategies(exchangeStrategies) //
.build();
@@ -233,15 +231,9 @@ public class AsyncRestClient {
private Mono<WebClient> getWebClient() {
if (this.webClient == null) {
- try {
- TcpClient tcpClient = createTcpClient();
- this.webClient = createWebClient(this.baseUrl, tcpClient);
- } catch (Exception e) {
- logger.error("Could not create WebClient {}", e.getMessage());
- return Mono.error(e);
- }
+ this.webClient = buildWebClient(baseUrl);
}
- return Mono.just(this.webClient);
+ return Mono.just(buildWebClient(baseUrl));
}
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClientFactory.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClientFactory.java
index db3834a9..cde6647a 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClientFactory.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClientFactory.java
@@ -72,7 +72,7 @@ public class AsyncRestClientFactory {
return createRestClient(baseUrl, false);
}
- public AsyncRestClient createRestClient(String baseUrl) {
+ public AsyncRestClient createRestClientUseHttpProxy(String baseUrl) {
return createRestClient(baseUrl, true);
}
@@ -190,5 +190,4 @@ public class AsyncRestClientFactory {
}
}
-
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1Client.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1Client.java
index 7ded8ac9..78a418ab 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1Client.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1Client.java
@@ -120,7 +120,7 @@ public class OscA1Client implements A1Client {
private final UriBuilder uri;
public OscA1Client(RicConfig ricConfig, AsyncRestClientFactory restClientFactory) {
- this(ricConfig, restClientFactory.createRestClient(""));
+ this(ricConfig, restClientFactory.createRestClientUseHttpProxy(""));
}
public OscA1Client(RicConfig ricConfig, AsyncRestClient restClient) {
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion1.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion1.java
index 130f5500..b158ad25 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion1.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion1.java
@@ -97,7 +97,7 @@ public class StdA1ClientVersion1 implements A1Client {
private final UriBuilder uri;
public StdA1ClientVersion1(RicConfig ricConfig, AsyncRestClientFactory restClientFactory) {
- this(restClientFactory.createRestClient(""), ricConfig);
+ this(restClientFactory.createRestClientUseHttpProxy(""), ricConfig);
}
public StdA1ClientVersion1(AsyncRestClient restClient, RicConfig ricConfig) {
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion2.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion2.java
index d79b2e72..d0f4da28 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion2.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion2.java
@@ -124,7 +124,7 @@ public class StdA1ClientVersion2 implements A1Client {
private final OranV2UriBuilder uriBuiler;
public StdA1ClientVersion2(RicConfig ricConfig, AsyncRestClientFactory restClientFactory) {
- this(ricConfig, restClientFactory.createRestClient(""));
+ this(ricConfig, restClientFactory.createRestClientUseHttpProxy(""));
}
public StdA1ClientVersion2(RicConfig ricConfig, AsyncRestClient restClient) {
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/Consts.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/Consts.java
index c3eff84a..3e6bda72 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/Consts.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/Consts.java
@@ -28,7 +28,7 @@ public class Consts {
public static final String TRANSIENT_PARAM = "transient";
public static final String MANAGED_ELEMENT_ID_PARAM = "managed_element_id";
- public static final String V2_API_ROOT = "a1-policy/v2";
+ public static final String V2_API_ROOT = "/a1-policy/v2";
public static final String V2_API_SERVICE_CALLBACKS_NAME = "Callbacks";
public static final String V2_API_SERVICE_CALLBACKS_DESCRIPTION = "";
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