diff options
Diffstat (limited to 'rest-services')
55 files changed, 1246 insertions, 403 deletions
diff --git a/rest-services/aai-client/pom.xml b/rest-services/aai-client/pom.xml index 2d2ee1e1..037f183d 100644 --- a/rest-services/aai-client/pom.xml +++ b/rest-services/aai-client/pom.xml @@ -7,13 +7,11 @@ <parent> <groupId>org.onap.dcaegen2.services.sdk</groupId> <artifactId>dcaegen2-services-sdk-rest-services</artifactId> - <version>1.1.2-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> + <version>1.1.4-SNAPSHOT</version> </parent> <groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId> <artifactId>aai-client</artifactId> - <version>1.1.3-SNAPSHOT</version> <name>dcaegen2-services-sdk-rest-services-aai-client</name> <description>Active and Available Inventory Rest Services Module</description> @@ -26,6 +24,12 @@ <version>${project.version}</version> </dependency> <dependency> + <groupId>org.onap.dcaegen2.services.sdk.security</groupId> + <artifactId>ssl</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <scope>test</scope> diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiHttpClientFactory.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiHttpClientFactory.java index d3047561..5e117456 100644 --- a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiHttpClientFactory.java +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiHttpClientFactory.java @@ -20,95 +20,66 @@ package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service; -import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.ssl.SslContext; +import io.vavr.control.Try; import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiHttpClient; -import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.get.AaiHttpGetClient; -import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.patch.AaiHttpPatchClient; -import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; -import org.onap.dcaegen2.services.sdk.rest.services.ssl.SslFactory; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient; +import org.onap.dcaegen2.services.sdk.rest.services.model.logging.ImmutableRequestDiagnosticContext; +import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; +import org.onap.dcaegen2.services.sdk.security.ssl.ImmutableSecurityKeys; +import org.onap.dcaegen2.services.sdk.security.ssl.ImmutableSecurityKeysStore; +import org.onap.dcaegen2.services.sdk.security.ssl.Passwords; +import org.onap.dcaegen2.services.sdk.security.ssl.SecurityKeys; +import org.onap.dcaegen2.services.sdk.security.ssl.SslFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import reactor.netty.Connection; -import reactor.netty.http.client.HttpClient; -import reactor.netty.http.client.HttpClientRequest; -import reactor.netty.http.client.HttpClientResponse; -import javax.net.ssl.SSLException; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Base64; -import java.util.Map; -import java.util.function.BiConsumer; +import java.util.UUID; public class AaiHttpClientFactory { private static final Logger LOGGER = LoggerFactory.getLogger(AaiHttpClientFactory.class); private final AaiClientConfiguration configuration; - private final SslFactory sslFactory; + private final SslFactory sslFactory = new SslFactory(); - public AaiHttpClientFactory(SslFactory sslFactory, AaiClientConfiguration configuration) { + public AaiHttpClientFactory(AaiClientConfiguration configuration) { this.configuration = configuration; - this.sslFactory = sslFactory; } - public AaiHttpClient<String> get() throws SSLException { - return new AaiHttpGetClient(configuration).createAaiHttpClient(build()); - } - - public AaiHttpClient<Integer> patch(JsonBodyBuilder jsonBodyBuilder) throws SSLException { - return new AaiHttpPatchClient(configuration, jsonBodyBuilder).createAaiHttpClient(build()); - } - - private HttpClient build() throws SSLException { + public CloudHttpClient build() { LOGGER.debug("Setting ssl context"); - - SslContext sslContext = createSslContext(); - - return HttpClient.create() - .secure(sslContextSpec -> sslContextSpec.sslContext(sslContext)) - .headers(this::settingHeaders) - .doOnRequest(logRequest()) - .doOnResponse(logResponse()); + return new CloudHttpClient(createSslContext()); } - private SslContext createSslContext() throws SSLException { + private SslContext createSslContext() { if (configuration.enableAaiCertAuth()) { - return sslFactory.createSecureContext( - configuration.keyStorePath(), - configuration.keyStorePasswordPath(), - configuration.trustStorePath(), - configuration.trustStorePasswordPath() - ); + final SecurityKeys collectorSecurityKeys = ImmutableSecurityKeys.builder() + .keyStore(ImmutableSecurityKeysStore.of(resource(configuration.keyStorePath()).get())) + .keyStorePassword(Passwords.fromResource(configuration.keyStorePasswordPath())) + .trustStore(ImmutableSecurityKeysStore.of(resource(configuration.trustStorePath()).get())) + .trustStorePassword(Passwords.fromResource(configuration.trustStorePasswordPath())) + .build(); + return sslFactory.createSecureClientContext(collectorSecurityKeys); } - return sslFactory.createInsecureContext(); + return sslFactory.createInsecureClientContext(); } - private HttpHeaders settingHeaders(HttpHeaders httpHeaders) { - httpHeaders.add("Authorization", "Basic " + performBasicAuthentication()); - for(Map.Entry<String,String> header : configuration.aaiHeaders().entrySet()) - httpHeaders.add(header.getKey(), header.getValue()); - return httpHeaders; + private Try<Path> resource(String resource) { + return Try.of(() -> Paths.get(Passwords.class.getResource(resource).toURI())); } - private String performBasicAuthentication() { - return Base64.getEncoder().encodeToString( - (configuration.aaiUserName() + ":" + configuration.aaiUserPassword()).getBytes() - ); + public static String performBasicAuthentication(String userName, String password) { + return Base64.getEncoder().encodeToString((userName + ":" + password).getBytes()); } - private static BiConsumer<HttpClientRequest, Connection> logRequest() { - return (httpClientRequest, connection) -> { - LOGGER.info("Request: {} {}", httpClientRequest.method(), httpClientRequest.uri()); - httpClientRequest.requestHeaders().forEach(stringStringEntry -> - LOGGER.info("{}={}", stringStringEntry.getKey(), stringStringEntry.getValue()) - ); - }; + public static RequestDiagnosticContext createRequestDiagnosticContext() { + return ImmutableRequestDiagnosticContext.builder() + .invocationId(UUID.randomUUID()).requestId(UUID.randomUUID()).build(); } - private static BiConsumer<? super HttpClientResponse, ? super Connection> logResponse() { - return (httpClientResponse, connection) -> - LOGGER.info("ResponseStatus {}", httpClientResponse.status().code()); - } } diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClient.java index 7feffddc..07987d2e 100644 --- a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClient.java +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClient.java @@ -22,42 +22,46 @@ package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.get import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration; import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiHttpClient; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient; import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel; import org.onap.dcaegen2.services.sdk.rest.services.uri.URI; import reactor.core.publisher.Mono; -import reactor.netty.http.client.HttpClient; + +import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.AaiHttpClientFactory.createRequestDiagnosticContext; +import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.AaiHttpClientFactory.performBasicAuthentication; public final class AaiHttpGetClient implements AaiHttpClient<String> { - private HttpClient httpClient; + private CloudHttpClient httpGetClient; private final AaiClientConfiguration configuration; public AaiHttpGetClient(AaiClientConfiguration configuration) { this.configuration = configuration; + addAuthorizationBasicHeader(); } @Override public Mono<String> getAaiResponse(AaiModel aaiModel) { - return httpClient - .baseUrl(getUri(aaiModel.getCorrelationId())) - .get() - .responseContent() - .aggregate() - .asString(); + return httpGetClient.get(getUri(aaiModel.getCorrelationId()), createRequestDiagnosticContext(), configuration.aaiHeaders(), String.class); } - public AaiHttpGetClient createAaiHttpClient(HttpClient httpClient) { - this.httpClient = httpClient; + public AaiHttpGetClient createAaiHttpClient(CloudHttpClient httpGetClient) { + this.httpGetClient = httpGetClient; return this; } - String getUri(String pnfName) { + private String getUri(String pnfName) { return new URI.URIBuilder() .scheme(configuration.aaiProtocol()) .host(configuration.aaiHost()) .port(configuration.aaiPort()) .path(configuration.aaiBasePath() + configuration.aaiPnfPath() + "/" + pnfName).build().toString(); } + + private void addAuthorizationBasicHeader() { + configuration.aaiHeaders().put("Authorization", + "Basic " + performBasicAuthentication(configuration.aaiUserName(), configuration.aaiUserPassword())); + } } diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClient.java index 51000b09..ef601550 100644 --- a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClient.java +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClient.java @@ -20,27 +20,22 @@ package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.patch; -import io.netty.handler.codec.http.HttpHeaders; import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration; import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiHttpClient; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient; import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel; import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; import org.onap.dcaegen2.services.sdk.rest.services.uri.URI; -import org.slf4j.MDC; import reactor.core.publisher.Mono; -import reactor.netty.ByteBufFlux; -import reactor.netty.http.client.HttpClient; +import reactor.netty.http.client.HttpClientResponse; -import java.util.UUID; -import java.util.function.Consumer; +import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.AaiHttpClientFactory.createRequestDiagnosticContext; +import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.AaiHttpClientFactory.performBasicAuthentication; -import static org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables.REQUEST_ID; -import static org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables.X_INVOCATION_ID; -import static org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables.X_ONAP_REQUEST_ID; -public final class AaiHttpPatchClient implements AaiHttpClient<Integer> { +public final class AaiHttpPatchClient implements AaiHttpClient<HttpClientResponse> { - private HttpClient httpClient; + private CloudHttpClient httpPatchClient; private final AaiClientConfiguration configuration; private final JsonBodyBuilder jsonBodyBuilder; @@ -48,24 +43,20 @@ public final class AaiHttpPatchClient implements AaiHttpClient<Integer> { public AaiHttpPatchClient(final AaiClientConfiguration configuration, JsonBodyBuilder jsonBodyBuilder) { this.configuration = configuration; this.jsonBodyBuilder = jsonBodyBuilder; + addAuthorizationBasicHeader(); } - - public Mono<Integer> getAaiResponse(AaiModel aaiModel) { - return httpClient - .headers(addHeaders()) - .baseUrl(getUri(aaiModel.getCorrelationId())) - .patch() - .send(ByteBufFlux.fromString(Mono.just(jsonBodyBuilder.createJsonBody(aaiModel)))) - .responseSingle((res, content) -> Mono.just(res.status().code())); + public Mono<HttpClientResponse> getAaiResponse(AaiModel aaiModel) { + return httpPatchClient + .patch(getUri(aaiModel.getCorrelationId()), createRequestDiagnosticContext(), configuration.aaiHeaders(), jsonBodyBuilder, aaiModel); } - public AaiHttpPatchClient createAaiHttpClient(HttpClient httpClient) { - this.httpClient = httpClient; + public AaiHttpPatchClient createAaiHttpClient(CloudHttpClient httpPatchClient) { + this.httpPatchClient = httpPatchClient; return this; } - String getUri(String pnfName) { + private String getUri(String pnfName) { return new URI.URIBuilder() .scheme(configuration.aaiProtocol()) .host(configuration.aaiHost()) @@ -73,10 +64,8 @@ public final class AaiHttpPatchClient implements AaiHttpClient<Integer> { .path(configuration.aaiBasePath() + configuration.aaiPnfPath() + "/" + pnfName).build().toString(); } - private Consumer<? super HttpHeaders> addHeaders() { - return h -> { - h.add(X_ONAP_REQUEST_ID, MDC.get(REQUEST_ID)); - h.add(X_INVOCATION_ID, UUID.randomUUID().toString()); - }; + private void addAuthorizationBasicHeader() { + configuration.aaiHeaders().put("Authorization", + "Basic " + performBasicAuthentication(configuration.aaiUserName(), configuration.aaiUserPassword())); } } diff --git a/rest-services/cbs-client/pom.xml b/rest-services/cbs-client/pom.xml index 9766ed58..70c11a1c 100644 --- a/rest-services/cbs-client/pom.xml +++ b/rest-services/cbs-client/pom.xml @@ -7,13 +7,11 @@ <parent> <groupId>org.onap.dcaegen2.services.sdk</groupId> <artifactId>dcaegen2-services-sdk-rest-services</artifactId> - <version>1.1.2-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> + <version>1.1.4-SNAPSHOT</version> </parent> <groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId> <artifactId>cbs-client</artifactId> - <version>1.1.3-SNAPSHOT</version> <name>dcaegen2-services-sdk-rest-services-cbs-client</name> <description>Config Binding Service Rest Services Module</description> diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientFactory.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientFactory.java index c2bc823d..f5bf0dae 100644 --- a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientFactory.java +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientFactory.java @@ -23,6 +23,7 @@ import org.jetbrains.annotations.NotNull; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.impl.CbsClientImpl; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.impl.CbsLookup; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties; import reactor.core.publisher.Mono; /** diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/listener/CompositeTreeChangeListener.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/listener/CompositeTreeChangeListener.java new file mode 100644 index 00000000..2f90f5e9 --- /dev/null +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/listener/CompositeTreeChangeListener.java @@ -0,0 +1,50 @@ +/* + * ============LICENSE_START==================================== + * DCAEGEN2-SERVICES-SDK + * ========================================================= + * Copyright (C) 2019 Nokia. All rights reserved. + * ========================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================== + */ +package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.listener; + +import io.vavr.control.Option; +import java.util.Collection; +import java.util.HashSet; + +/** + * @since 1.1.2 + * + * NOTE + * The class is thread unsafe + */ +class CompositeTreeChangeListener<V> implements TreeChangeListener<V> { + + private final Collection<TreeChangeListener<V>> listeners = new HashSet<>(); + + public void addListener(TreeChangeListener<V> listener) { + listeners.add(listener); + } + + public void removeListener(TreeChangeListener<V> listener) { + listeners.remove(listener); + } + + @Override + public void accept(Option<MerkleTree<V>> updatedSubtree) { + for (TreeChangeListener<V> listener : listeners) { + listener.accept(updatedSubtree); + } + } +} diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/listener/ListenableCbsConfig.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/listener/ListenableCbsConfig.java index 46c032ea..ce065d1d 100644 --- a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/listener/ListenableCbsConfig.java +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/listener/ListenableCbsConfig.java @@ -22,10 +22,6 @@ package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.listener; import io.vavr.collection.List; import io.vavr.control.Option; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi; import reactor.core.Disposable; import reactor.core.publisher.Flux; @@ -38,27 +34,9 @@ import reactor.core.publisher.Flux; public class ListenableCbsConfig { private MerkleTree<String> tree = MerkleTree.emptyWithDefaultDigest(String::getBytes); - private final Map<List<String>, CompositeTreeChangeListener<String>> pathListeners = new HashMap<>(); - private final Object listenersUpdateMonitor = new Object(); + private final TreePathListener<String> pathListener = new TreePathListener<>(); private final Object treeUpdateMonitor = new Object(); - public void listen(List<String> path, TreeChangeListener<String> listener) { - synchronized (listenersUpdateMonitor) { - CompositeTreeChangeListener<String> compositeListener = pathListeners - .computeIfAbsent(path, p -> new CompositeTreeChangeListener<>()); - compositeListener.addListener(listener); - } - } - - public void cancel(List<String> path, TreeChangeListener<String> listener) { - synchronized (listenersUpdateMonitor) { - CompositeTreeChangeListener<String> compositeListener = pathListeners.get(path); - if (compositeListener != null) { - compositeListener.removeListener(listener); - } - } - } - public Flux<Option<MerkleTree<String>>> subtreeChanges(List<String> path) { return Flux.create(sink -> { final TreeChangeListener<String> listener = sink::next; @@ -67,43 +45,26 @@ public class ListenableCbsConfig { }); } + public void listen(List<String> path, TreeChangeListener<String> listener) { + pathListener.listen(path, listener); + } + + public void cancel(List<String> path, TreeChangeListener<String> listener) { + pathListener.cancel(path, listener); + } + public Disposable subscribeForUpdates(Flux<MerkleTree<String>> updates) { return updates.subscribe(this::update); } public void update(MerkleTree<String> newTree) { final MerkleTree<String> oldTree; + synchronized (treeUpdateMonitor) { oldTree = tree; tree = newTree; } - for (Map.Entry<List<String>, CompositeTreeChangeListener<String>> entry : pathListeners.entrySet()) { - final List<String> path = entry.getKey(); - final CompositeTreeChangeListener<String> listeners = entry.getValue(); - if (!newTree.isSame(path, oldTree)) { - listeners.accept(newTree, path); - } - } - } - - private static class CompositeTreeChangeListener<V> implements TreeChangeListener<V> { - - private final Collection<TreeChangeListener<V>> listeners = new HashSet<>(); - - void addListener(TreeChangeListener<V> listener) { - listeners.add(listener); - } - - void removeListener(TreeChangeListener<V> listener) { - listeners.remove(listener); - } - - @Override - public void accept(Option<MerkleTree<V>> updatedSubtree) { - for (TreeChangeListener<V> listener : listeners) { - listener.accept(updatedSubtree); - } - } + pathListener.update(oldTree, newTree); } } diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/listener/TreePathListener.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/listener/TreePathListener.java new file mode 100644 index 00000000..6c578317 --- /dev/null +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/listener/TreePathListener.java @@ -0,0 +1,54 @@ +/* + * ============LICENSE_START==================================== + * DCAEGEN2-SERVICES-SDK + * ========================================================= + * Copyright (C) 2019 Nokia. All rights reserved. + * ========================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================== + */ +package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.listener; + +import io.vavr.collection.List; +import java.util.HashMap; +import java.util.Map; + +/** + * @since 1.1.2 + */ +class TreePathListener<T> { + + private final Map<List<String>, CompositeTreeChangeListener<T>> pathListeners = new HashMap<>(); + + public synchronized void listen(List<String> path, TreeChangeListener<T> listener) { + CompositeTreeChangeListener<T> compositeListener = pathListeners + .computeIfAbsent(path, p -> new CompositeTreeChangeListener<>()); + + compositeListener.addListener(listener); + } + + public synchronized void cancel(List<String> path, TreeChangeListener<T> listener) { + CompositeTreeChangeListener<T> compositeListener = pathListeners.get(path); + if (compositeListener != null) { + compositeListener.removeListener(listener); + } + } + + public void update(MerkleTree<T> oldTree, MerkleTree<T> newTree) { + pathListeners.forEach((path, listener) -> { + if (!newTree.isSame(path, oldTree)) { + listener.accept(newTree, path); + } + }); + } +} diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/streams/StreamParser.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/streams/StreamParser.java new file mode 100644 index 00000000..f8393438 --- /dev/null +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/streams/StreamParser.java @@ -0,0 +1,40 @@ +/* + * ============LICENSE_START==================================== + * DCAEGEN2-SERVICES-SDK + * ========================================================= + * Copyright (C) 2019 Nokia. All rights reserved. + * ========================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================== + */ + +package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.streams; + +import io.vavr.control.Either; +import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.listener.MerkleTree; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.streams.DataStream; + +/** + * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a> + * @since 1.1.2 + */ +@ExperimentalApi +public interface StreamParser<S extends DataStream> { + + Either<StreamParserError, S> parse(MerkleTree<String> subtree); + + default S unsafeParse(MerkleTree<String> subtree) { + return parse(subtree).getOrElseThrow(StreamParsingException::new); + } +} diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/streams/StreamParserError.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/streams/StreamParserError.java new file mode 100644 index 00000000..7ef0a470 --- /dev/null +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/streams/StreamParserError.java @@ -0,0 +1,40 @@ +/* + * ============LICENSE_START==================================== + * DCAEGEN2-SERVICES-SDK + * ========================================================= + * Copyright (C) 2019 Nokia. All rights reserved. + * ========================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================== + */ + +package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.streams; + +import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi; + +/** + * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a> + * @since 1.1.2 + */ +@ExperimentalApi +public class StreamParserError { + private final String message; + + public StreamParserError(String message) { + this.message = message; + } + + public String message() { + return message; + } +} diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/streams/StreamParsingException.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/streams/StreamParsingException.java new file mode 100644 index 00000000..1a3b9ea2 --- /dev/null +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/streams/StreamParsingException.java @@ -0,0 +1,42 @@ +/* + * ============LICENSE_START==================================== + * DCAEGEN2-SERVICES-SDK + * ========================================================= + * Copyright (C) 2019 Nokia. All rights reserved. + * ========================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================== + */ + +package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.streams; + +import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi; + +/** + * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a> + * @since 1.1.2 + */ +@ExperimentalApi +public class StreamParsingException extends RuntimeException { + + private final StreamParserError cause; + + public StreamParsingException(StreamParserError cause) { + super(cause.message()); + this.cause = cause; + } + + public StreamParserError cause() { + return cause; + } +} diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsLookup.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsLookup.java index 9eba2755..3c11d234 100644 --- a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsLookup.java +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsLookup.java @@ -23,7 +23,7 @@ package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.impl; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import java.net.InetSocketAddress; -import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.EnvProperties; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient; import reactor.core.publisher.Mono; diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/EnvProperties.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/EnvProperties.java index 8f35ea5e..8a40c2c0 100644 --- a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/EnvProperties.java +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/EnvProperties.java @@ -18,7 +18,7 @@ * ============LICENSE_END===================================== */ -package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api; +package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model; import org.immutables.value.Value; diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/AafCredentials.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/AafCredentials.java new file mode 100644 index 00000000..11481561 --- /dev/null +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/AafCredentials.java @@ -0,0 +1,37 @@ +/* + * ============LICENSE_START==================================== + * DCAEGEN2-SERVICES-SDK + * ========================================================= + * Copyright (C) 2019 Nokia. All rights reserved. + * ========================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================== + */ + +package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.streams; + + +import org.jetbrains.annotations.Nullable; +import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi; + +/** + * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a> + * @version 1.2.1 + */ +@ExperimentalApi +public interface AafCredentials { + + @Nullable String username(); + + @Nullable String password(); +} diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/DataStream.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/DataStream.java new file mode 100644 index 00000000..43d9d726 --- /dev/null +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/DataStream.java @@ -0,0 +1,32 @@ +/* + * ============LICENSE_START==================================== + * DCAEGEN2-SERVICES-SDK + * ========================================================= + * Copyright (C) 2019 Nokia. All rights reserved. + * ========================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================== + */ + +package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.streams; + +import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi; + +/** + * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a> + * @version 1.2.1 + */ +@ExperimentalApi +public interface DataStream { + +} diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/SinkStream.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/SinkStream.java new file mode 100644 index 00000000..3ccce215 --- /dev/null +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/SinkStream.java @@ -0,0 +1,34 @@ +/* + * ============LICENSE_START==================================== + * DCAEGEN2-SERVICES-SDK + * ========================================================= + * Copyright (C) 2019 Nokia. All rights reserved. + * ========================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================== + */ + +package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.streams; + +import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi; + +/** + * AKA PublishStream + * + * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a> + * @version 1.2.1 + */ +@ExperimentalApi +public interface SinkStream { + +} diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/SourceStream.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/SourceStream.java new file mode 100644 index 00000000..78bb5b51 --- /dev/null +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/SourceStream.java @@ -0,0 +1,34 @@ +/* + * ============LICENSE_START==================================== + * DCAEGEN2-SERVICES-SDK + * ========================================================= + * Copyright (C) 2019 Nokia. All rights reserved. + * ========================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================== + */ + +package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.streams; + +import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi; + +/** + * AKA SubscribeStream + * + * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a> + * @version 1.2.1 + */ +@ExperimentalApi +public interface SourceStream { + +} diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/dmaap/DataRouter.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/dmaap/DataRouter.java new file mode 100644 index 00000000..ba26b103 --- /dev/null +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/dmaap/DataRouter.java @@ -0,0 +1,39 @@ +/* + * ============LICENSE_START==================================== + * DCAEGEN2-SERVICES-SDK + * ========================================================= + * Copyright (C) 2019 Nokia. All rights reserved. + * ========================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================== + */ + +package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.streams.dmaap; + + +import org.jetbrains.annotations.Nullable; +import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi; + +/** + * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a> + * @version 1.2.1 + */ +@ExperimentalApi +public interface DataRouter { + + String location(); + + @Nullable String username(); + + @Nullable String password(); +} diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/dmaap/DataRouterSink.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/dmaap/DataRouterSink.java new file mode 100644 index 00000000..a8aa5cbb --- /dev/null +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/dmaap/DataRouterSink.java @@ -0,0 +1,43 @@ +/* + * ============LICENSE_START==================================== + * DCAEGEN2-SERVICES-SDK + * ========================================================= + * Copyright (C) 2019 Nokia. All rights reserved. + * ========================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================== + */ + +package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.streams.dmaap; + + +import org.immutables.value.Value; +import org.jetbrains.annotations.Nullable; +import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.streams.SinkStream; + +/** + * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a> + * @version 1.2.1 + */ +@ExperimentalApi +@Value.Immutable +public abstract class DataRouterSink implements DataRouter, SinkStream { + + abstract String publisherUrl(); + + abstract String publisherId(); + + abstract @Nullable String logUrl(); + +} diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/dmaap/DataRouterSource.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/dmaap/DataRouterSource.java new file mode 100644 index 00000000..ac8362db --- /dev/null +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/dmaap/DataRouterSource.java @@ -0,0 +1,39 @@ +/* + * ============LICENSE_START==================================== + * DCAEGEN2-SERVICES-SDK + * ========================================================= + * Copyright (C) 2019 Nokia. All rights reserved. + * ========================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================== + */ + +package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.streams.dmaap; + + +import org.immutables.value.Value; +import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.streams.SourceStream; + +/** + * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a> + * @version 1.2.1 + */ +@ExperimentalApi +@Value.Immutable +public abstract class DataRouterSource implements DataRouter, SourceStream { + + abstract String deliveryUrl(); + + abstract String subscriberId(); +} diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/dmaap/MessageRouter.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/dmaap/MessageRouter.java new file mode 100644 index 00000000..76c6f6db --- /dev/null +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/dmaap/MessageRouter.java @@ -0,0 +1,44 @@ +/* + * ============LICENSE_START==================================== + * DCAEGEN2-SERVICES-SDK + * ========================================================= + * Copyright (C) 2019 Nokia. All rights reserved. + * ========================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================== + */ + +package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.streams.dmaap; + + +import org.jetbrains.annotations.Nullable; +import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.streams.AafCredentials; + +/** + * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a> + * @version 1.2.1 + */ +@ExperimentalApi +public interface MessageRouter { + + String topicUrl(); + + @Nullable String clientRole(); + + @Nullable String clientId(); + + @Nullable String location(); + + @Nullable AafCredentials aafCredentials(); +} diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/dmaap/MessageRouterSink.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/dmaap/MessageRouterSink.java new file mode 100644 index 00000000..7584bac4 --- /dev/null +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/dmaap/MessageRouterSink.java @@ -0,0 +1,36 @@ +/* + * ============LICENSE_START==================================== + * DCAEGEN2-SERVICES-SDK + * ========================================================= + * Copyright (C) 2019 Nokia. All rights reserved. + * ========================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================== + */ + +package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.streams.dmaap; + + +import org.immutables.value.Value; +import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.streams.SinkStream; + +/** + * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a> + * @version 1.2.1 + */ +@ExperimentalApi +@Value.Immutable +public abstract class MessageRouterSink implements MessageRouter, SinkStream { + +} diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/dmaap/MessageRouterSource.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/dmaap/MessageRouterSource.java new file mode 100644 index 00000000..e9599a5e --- /dev/null +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/model/streams/dmaap/MessageRouterSource.java @@ -0,0 +1,36 @@ +/* + * ============LICENSE_START==================================== + * DCAEGEN2-SERVICES-SDK + * ========================================================= + * Copyright (C) 2019 Nokia. All rights reserved. + * ========================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================== + */ + +package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.streams.dmaap; + + +import org.immutables.value.Value; +import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.streams.SourceStream; + +/** + * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a> + * @version 1.2.1 + */ +@ExperimentalApi +@Value.Immutable +public abstract class MessageRouterSource implements MessageRouter, SourceStream { + +} diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/CloudConfigurationClient.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/CloudConfigurationClient.java index 8a1abe36..534397ca 100644 --- a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/CloudConfigurationClient.java +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/CloudConfigurationClient.java @@ -22,8 +22,8 @@ package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.providers; import com.google.gson.JsonObject; -import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.EnvProperties; -import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.ImmutableEnvProperties; +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.Mono; /** diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/CloudConfigurationProvider.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/CloudConfigurationProvider.java index e1105344..d82d5d31 100644 --- a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/CloudConfigurationProvider.java +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/CloudConfigurationProvider.java @@ -22,7 +22,7 @@ package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.providers; import com.google.gson.JsonObject; -import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.EnvProperties; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties; import reactor.core.publisher.Mono; /** diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/ReactiveCloudConfigurationProvider.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/ReactiveCloudConfigurationProvider.java index 4052b4ab..b7507884 100644 --- a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/ReactiveCloudConfigurationProvider.java +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/ReactiveCloudConfigurationProvider.java @@ -24,7 +24,7 @@ package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.providers; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient; -import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.EnvProperties; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties; import org.onap.dcaegen2.services.sdk.rest.services.uri.URI; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/EnvPropertiesTest.java b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/EnvPropertiesTest.java index b48543d2..73217cdb 100644 --- a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/EnvPropertiesTest.java +++ b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/EnvPropertiesTest.java @@ -24,6 +24,7 @@ package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties; /** * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a> diff --git a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/listener/ListenableCbsConfigTest.java b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/listener/ListenableCbsConfigTest.java index e5cb4f11..7546774b 100644 --- a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/listener/ListenableCbsConfigTest.java +++ b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/listener/ListenableCbsConfigTest.java @@ -25,8 +25,6 @@ import static org.assertj.core.api.Assertions.assertThat; import io.vavr.collection.List; import java.util.concurrent.atomic.AtomicReference; import org.junit.jupiter.api.Test; -import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.listener.ListenableCbsConfig; -import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.listener.MerkleTree; import reactor.core.publisher.Flux; import reactor.core.publisher.ReplayProcessor; import reactor.test.StepVerifier; @@ -135,4 +133,4 @@ class ListenableCbsConfigTest { .verifyComplete(); } -}
\ No newline at end of file +} diff --git a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/listener/MerkleTreeTest.java b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/listener/MerkleTreeTest.java index b24ff2ee..1077ee60 100644 --- a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/listener/MerkleTreeTest.java +++ b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/listener/MerkleTreeTest.java @@ -24,7 +24,6 @@ import static org.assertj.core.api.Assertions.assertThat; import io.vavr.collection.List; import org.junit.jupiter.api.Test; -import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.listener.MerkleTree; /** * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a> diff --git a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientImplIT.java b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientImplIT.java index 8a0977d9..e862d849 100644 --- a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientImplIT.java +++ b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientImplIT.java @@ -29,11 +29,11 @@ import java.time.Duration; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.ImmutableEnvProperties; import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClient; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClientFactory; -import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.EnvProperties; -import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.ImmutableEnvProperties; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; diff --git a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsLookupTest.java b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsLookupTest.java index 858e938c..77cfaf63 100644 --- a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsLookupTest.java +++ b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsLookupTest.java @@ -31,9 +31,9 @@ import com.google.gson.JsonParser; import java.io.InputStreamReader; import java.net.InetSocketAddress; import org.junit.jupiter.api.Test; -import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.EnvProperties; -import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.ImmutableEnvProperties; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.ImmutableEnvProperties; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; diff --git a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/ReactiveCloudConfigurationProviderTest.java b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/ReactiveCloudConfigurationProviderTest.java index c711226f..9bb4ad39 100644 --- a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/ReactiveCloudConfigurationProviderTest.java +++ b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/ReactiveCloudConfigurationProviderTest.java @@ -27,9 +27,9 @@ import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import org.junit.jupiter.api.Test; -import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.ImmutableEnvProperties; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient; -import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.EnvProperties; +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.Mono; import reactor.test.StepVerifier; diff --git a/rest-services/common-dependency/pom.xml b/rest-services/common-dependency/pom.xml index ef74c694..4d9b2e08 100644 --- a/rest-services/common-dependency/pom.xml +++ b/rest-services/common-dependency/pom.xml @@ -8,13 +8,11 @@ <parent> <groupId>org.onap.dcaegen2.services.sdk</groupId> <artifactId>dcaegen2-services-sdk-rest-services</artifactId> - <version>1.1.2-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> + <version>1.1.4-SNAPSHOT</version> </parent> <groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId> <artifactId>common-dependency</artifactId> - <version>1.1.3-SNAPSHOT</version> <name>dcaegen2-services-sdk-rest-services-common-dependency</name> <description>Common functionality in the project</description> @@ -53,6 +51,20 @@ <groupId>org.slf4j</groupId> <artifactId>log4j-over-slf4j</artifactId> </dependency> - + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.projectreactor</groupId> + <artifactId>reactor-test</artifactId> + <scope>test</scope> + </dependency> </dependencies> </project>
\ No newline at end of file diff --git a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClient.java b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClient.java index cba5c6af..e142081e 100644 --- a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClient.java +++ b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClient.java @@ -29,14 +29,18 @@ import java.util.Collections; import java.util.Map; import java.util.function.BiConsumer; import java.util.stream.Collectors; +import org.onap.dcaegen2.services.sdk.rest.services.model.ClientModel; +import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import reactor.core.publisher.Mono; +import reactor.netty.ByteBufFlux; import reactor.netty.http.client.HttpClient; import reactor.netty.http.client.HttpClientRequest; import reactor.netty.http.client.HttpClientResponse; + /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 11/15/18 */ @@ -55,7 +59,7 @@ public class CloudHttpClient { this(HttpClient.create().secure(sslContextSpec -> sslContextSpec.sslContext(sslContext))); } - private CloudHttpClient(HttpClient httpClient) { + CloudHttpClient(HttpClient httpClient) { this.httpClient = httpClient; } @@ -64,12 +68,9 @@ public class CloudHttpClient { return get(url, context, Collections.EMPTY_MAP, bodyClass); } - public <T> Mono<T> get(String url, RequestDiagnosticContext context, Map<String, String> customHeaders, Class<T> bodyClass) { - final HttpClient clientWithHeaders = httpClient - .doOnRequest((req, conn) -> logRequest(context, req)) - .doOnResponse((rsp, conn) -> logResponse(context, rsp)) - .headers(hdrs -> context.remoteCallHttpHeaders().forEach((BiConsumer<String, String>) hdrs::set)) - .headers(hdrs -> customHeaders.forEach(hdrs::set)); + public <T> Mono<T> get(String url, RequestDiagnosticContext context, Map<String, String> customHeaders, + Class<T> bodyClass) { + final HttpClient clientWithHeaders = getHttpClientWithHeaders(context, customHeaders); return callHttpGet(clientWithHeaders, url, bodyClass); } @@ -77,6 +78,27 @@ public class CloudHttpClient { return callHttpGet(httpClient, url, bodyClass); } + public Mono<HttpClientResponse> post(String url, RequestDiagnosticContext context, Map<String, String> customHeaders, + JsonBodyBuilder jsonBodyBuilder, ClientModel clientModel) { + final HttpClient clientWithHeaders = getHttpClientWithHeaders(context, customHeaders); + return callHttpPost(clientWithHeaders, url, jsonBodyBuilder, clientModel); + } + + public Mono<HttpClientResponse> patch(String url, RequestDiagnosticContext context, Map<String, String> customHeaders, + JsonBodyBuilder jsonBodyBuilder, ClientModel clientModel) { + final HttpClient clientWithHeaders = getHttpClientWithHeaders(context, customHeaders); + return callHttpPatch(clientWithHeaders, url, jsonBodyBuilder, clientModel); + } + + private HttpClient getHttpClientWithHeaders(RequestDiagnosticContext context, Map<String, String> customHeaders) { + final HttpClient clientWithHeaders = httpClient + .doOnRequest((req, conn) -> logRequest(context, req)) + .doOnResponse((rsp, conn) -> logResponse(context, rsp)) + .headers(hdrs -> context.remoteCallHttpHeaders().forEach((BiConsumer<String, String>) hdrs::set)) + .headers(hdrs -> customHeaders.forEach(hdrs::set)); + return clientWithHeaders; + } + private <T> Mono<T> callHttpGet(HttpClient client, String url, Class<T> bodyClass) { return client.get() .uri(url) @@ -86,6 +108,20 @@ public class CloudHttpClient { .map(body -> parseJson(body, bodyClass)); } + private <T extends ClientModel> Mono<HttpClientResponse> callHttpPost(HttpClient client, String url, + JsonBodyBuilder<T> jsonBodyBuilder, T clientModel) { + return client.baseUrl(url).post() + .send(ByteBufFlux.fromString(Mono.just(jsonBodyBuilder.createJsonBody(clientModel)))) + .responseSingle((httpClientResponse, byteBufMono) -> Mono.just(httpClientResponse)); + } + + private <T extends ClientModel> Mono<HttpClientResponse> callHttpPatch(HttpClient client, String url, + JsonBodyBuilder<T> jsonBodyBuilder, T clientModel) { + return client.baseUrl(url).patch() + .send(ByteBufFlux.fromString(Mono.just(jsonBodyBuilder.createJsonBody(clientModel)))) + .responseSingle((httpClientResponse, byteBufMono) -> Mono.just(httpClientResponse)); + } + private Exception createException(String url, HttpClientResponse response) { return new IOException(String.format("Request failed for URL '%s'. Response code: %s", url, diff --git a/rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClientIT.java b/rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClientIT.java new file mode 100644 index 00000000..37c189ee --- /dev/null +++ b/rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClientIT.java @@ -0,0 +1,152 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.sdk.rest.services.adapters.http; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import io.netty.handler.codec.http.HttpResponseStatus; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.sdk.rest.services.model.DmaapModel; +import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; +import org.onap.dcaegen2.services.sdk.rest.services.model.logging.ImmutableRequestDiagnosticContext; +import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; +import reactor.core.publisher.Mono; +import reactor.netty.DisposableServer; +import reactor.netty.http.client.HttpClient; +import reactor.netty.http.server.HttpServer; +import reactor.netty.resources.ConnectionProvider; +import reactor.test.StepVerifier; +import reactor.netty.http.client.HttpClientResponse; + +class CloudHttpClientIT { + private static final int MAX_CONNECTIONS = 1; + private static final String SAMPLE_STRING = "sampleString"; + private static final String SAMPLE_URL = "/sampleURL"; + private static final String JSON_BODY = "{\"correlationId\":\"NOKnhfsadhff\"," + + "\"ipaddress-v4\":\"256.22.33.155\", " + + "\"ipaddress-v6\":\"200J:0db8:85a3:0000:0000:8a2e:0370:7334\"}"; + private static final ConnectionProvider connectionProvider = ConnectionProvider.fixed("test", MAX_CONNECTIONS); + + private DmaapModel dmaapModel = mock(DmaapModel.class); + private JsonBodyBuilder<DmaapModel> jsonBodyBuilder = mock(JsonBodyBuilder.class); + + @Disabled + @Test + void successfulPatchResponse() { + DisposableServer server = createValidServer(); + HttpClient httpClient = createHttpClientForContextWithAddress(server, connectionProvider); + CloudHttpClient cloudHttpClient = new CloudHttpClient(httpClient); + + when(jsonBodyBuilder.createJsonBody(dmaapModel)).thenReturn(JSON_BODY); + Mono<HttpClientResponse> content = cloudHttpClient.patch(SAMPLE_URL, createRequestDiagnosticContext(), createCustomHeaders(), + jsonBodyBuilder, dmaapModel); + + StepVerifier.create(content) + .expectNext(content.block()) + .expectComplete() + .verify(); + server.disposeNow(); + } + + @Disabled + @Test + void errorPatchRequest() { + DisposableServer server = createInvalidServer(); + HttpClient httpClient = createHttpClientForContextWithAddress(server, connectionProvider); + CloudHttpClient cloudHttpClient = new CloudHttpClient(httpClient); + + when(jsonBodyBuilder.createJsonBody(dmaapModel)).thenReturn(JSON_BODY); + Mono<HttpClientResponse> content = cloudHttpClient.patch(SAMPLE_URL, createRequestDiagnosticContext(), createCustomHeaders(), + jsonBodyBuilder, dmaapModel); + + StepVerifier.create(content) + .expectNext(content.block()) + .expectComplete() + .verify(); + server.disposeNow(); + } + + @Test + void successfulGetResponse() { + DisposableServer server = createValidServer(); + HttpClient httpClient = createHttpClientForContextWithAddress(server, connectionProvider); + CloudHttpClient cloudHttpClient = new CloudHttpClient(httpClient); + + Mono<String> content = cloudHttpClient.get(SAMPLE_URL, String.class); + + StepVerifier.create(content) + .expectNext(SAMPLE_STRING) + .expectComplete() + .verify(); + server.disposeNow(); + } + @Test + void errorGetRequest() { + DisposableServer server = createInvalidServer(); + HttpClient httpClient = createHttpClientForContextWithAddress(server, connectionProvider); + CloudHttpClient cloudHttpClient = new CloudHttpClient(httpClient); + + Mono<String> content = cloudHttpClient.get(SAMPLE_URL, String.class); + + StepVerifier.create(content) + .expectError() + .verify(); + server.disposeNow(); + } + + private Map<String, String> createCustomHeaders() { + Map<String, String> customHeaders = new HashMap<>(); + customHeaders.put("X_INVOCATION_ID", UUID.randomUUID().toString()); + + return customHeaders; + } + + private DisposableServer createValidServer() { + Mono<String> response = Mono.just(SAMPLE_STRING); + return HttpServer.create() + .handle((req, resp) -> resp.sendString(response)) + .wiretap(true) + .bindNow(); + } + + private DisposableServer createInvalidServer() { + return HttpServer.create() + .handle((req, resp) -> Mono.error(new Exception("returnError"))) + .wiretap(true) + .bindNow(); + } + + private RequestDiagnosticContext createRequestDiagnosticContext() { + return ImmutableRequestDiagnosticContext.builder() + .invocationId(UUID.randomUUID()).requestId(UUID.randomUUID()).build(); + } + + private HttpClient createHttpClientForContextWithAddress(DisposableServer disposableServer, + ConnectionProvider connectionProvider) { + HttpClient client = connectionProvider == null? HttpClient.create() : HttpClient.create(connectionProvider); + return client.addressSupplier(disposableServer::address).wiretap(true); + } +}
\ No newline at end of file diff --git a/rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/model/logging/MdcVariablesTest.java b/rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/model/logging/MdcVariablesTest.java new file mode 100644 index 00000000..bb0cc6cf --- /dev/null +++ b/rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/model/logging/MdcVariablesTest.java @@ -0,0 +1,36 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.sdk.rest.services.model.logging; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +class MdcVariablesTest { + + @Test + void shouldReturnProperHttpHeader() { + String expectedValue = "X-header"; + String returnedValue = MdcVariables.httpHeader("header"); + + assertEquals(expectedValue, returnedValue); + } +}
\ No newline at end of file diff --git a/rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/uri/URITest.java b/rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/uri/URITest.java new file mode 100644 index 00000000..b4a59638 --- /dev/null +++ b/rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/uri/URITest.java @@ -0,0 +1,45 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 2019 NOKIA Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ + +package org.onap.dcaegen2.services.sdk.rest.services.uri; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +class URITest { + + @Test + void buildProperUri() { + String expectedValue = "http://user@localhost:8080path?query#fragment"; + URI uri = new URI.URIBuilder().scheme("http") + .host("localhost") + .port(8080) + .path("path") + .fragment("fragment") + .authority("authority") + .userInfo("user") + .query("query") + .build(); + + assertEquals(expectedValue, uri.toString()); + } +}
\ No newline at end of file diff --git a/rest-services/dmaap-client/pom.xml b/rest-services/dmaap-client/pom.xml index 2834191e..52e9f0ac 100644 --- a/rest-services/dmaap-client/pom.xml +++ b/rest-services/dmaap-client/pom.xml @@ -7,13 +7,11 @@ <parent> <groupId>org.onap.dcaegen2.services.sdk</groupId> <artifactId>dcaegen2-services-sdk-rest-services</artifactId> - <version>1.1.2-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> + <version>1.1.4-SNAPSHOT</version> </parent> <groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId> <artifactId>dmaap-client</artifactId> - <version>1.1.3-SNAPSHOT</version> <name>dcaegen2-services-sdk-rest-services-dmaap-client</name> <description>DMaaP Rest Services Module</description> @@ -26,22 +24,6 @@ <version>${project.version}</version> </dependency> <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context</artifactId> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-webflux</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-reactor-netty</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> </dependency> diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/config/DmaapConsumerConfiguration.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/config/DmaapConsumerConfiguration.java index f7107f7c..75816ea4 100644 --- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/config/DmaapConsumerConfiguration.java +++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/config/DmaapConsumerConfiguration.java @@ -22,12 +22,10 @@ package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config; import org.immutables.gson.Gson; import org.immutables.value.Value; -import org.springframework.stereotype.Component; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18 */ -@Component @Value.Immutable(prehash = true) @Value.Style(builder = "new") @Gson.TypeAdapters diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/DMaaPAbstractReactiveHttpClient.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/DMaaPAbstractReactiveHttpClient.java new file mode 100644 index 00000000..55fa7fb7 --- /dev/null +++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/DMaaPAbstractReactiveHttpClient.java @@ -0,0 +1,37 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service; + +import java.util.UUID; +import org.onap.dcaegen2.services.sdk.rest.services.model.logging.ImmutableRequestDiagnosticContext; +import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; + +public abstract class DMaaPAbstractReactiveHttpClient { + + protected final static String SLASH = "/"; + + protected RequestDiagnosticContext getRequestDiagnosticContext() { + return ImmutableRequestDiagnosticContext.builder() + .invocationId(UUID.randomUUID()).requestId(UUID.randomUUID()).build(); + } + + +} diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/DMaaPClientServiceUtils.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/DMaaPClientServiceUtils.java new file mode 100644 index 00000000..3876b527 --- /dev/null +++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/DMaaPClientServiceUtils.java @@ -0,0 +1,49 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author <a href="mailto:marcin.wmigdal@nokia.com">Marcin Migdal</a> on 3/8/2019 + */ +public final class DMaaPClientServiceUtils { + + public final static String CONTENT_TYPE = "Content-Type"; + + private DMaaPClientServiceUtils() { + + } + + /** + * Method generates headers for HTTP requests + * @param contentType contentType to be used in HTTP header* + * @return Map of Headers + * */ + public static Map<String, String> getHeaders(String contentType) { + Map<String, String> header = new HashMap<>(); + header.put(CONTENT_TYPE, contentType); + return header; + } + + +} diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClient.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClient.java index 99f70209..d0f95f6e 100644 --- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClient.java +++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClient.java @@ -21,12 +21,13 @@ package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.consumer; import java.net.URI; -import java.util.HashMap; import java.util.Map; import java.util.Optional; import java.util.UUID; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.DMaaPAbstractReactiveHttpClient; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.DMaaPClientServiceUtils; import org.onap.dcaegen2.services.sdk.rest.services.model.logging.ImmutableRequestDiagnosticContext; import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; import org.onap.dcaegen2.services.sdk.rest.services.uri.URI.URIBuilder; @@ -36,17 +37,9 @@ import reactor.core.publisher.Mono; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 6/26/18 */ -public class DMaaPConsumerReactiveHttpClient { +public class DMaaPConsumerReactiveHttpClient extends DMaaPAbstractReactiveHttpClient { - private final static String SLASH = "/"; - private final static String CONTENT_TYPE = "Content-Type"; - private final String dmaapHostName; - private final String dmaapProtocol; - private final Integer dmaapPortNumber; - private final String dmaapTopicName; - private final String consumerGroup; - private final String consumerId; - private final String contentType; + private final DmaapConsumerConfiguration consumerConfiguration; private final CloudHttpClient cloudHttpClient; /** @@ -57,13 +50,7 @@ public class DMaaPConsumerReactiveHttpClient { public DMaaPConsumerReactiveHttpClient(DmaapConsumerConfiguration consumerConfiguration, CloudHttpClient cloudHttpClient) { - this.dmaapHostName = consumerConfiguration.dmaapHostName(); - this.dmaapProtocol = consumerConfiguration.dmaapProtocol(); - this.dmaapPortNumber = consumerConfiguration.dmaapPortNumber(); - this.dmaapTopicName = consumerConfiguration.dmaapTopicName(); - this.consumerGroup = consumerConfiguration.consumerGroup(); - this.consumerId = consumerConfiguration.consumerId(); - this.contentType = consumerConfiguration.dmaapContentType(); + this.consumerConfiguration = consumerConfiguration; this.cloudHttpClient = cloudHttpClient; } @@ -73,10 +60,10 @@ public class DMaaPConsumerReactiveHttpClient { * @return reactive response from DMaaP in string format */ public Mono<String> getDMaaPConsumerResponse(Optional<RequestDiagnosticContext> requestDiagnosticContextOptional) { - Map<String,String> headers = new HashMap<>(); - headers.put(CONTENT_TYPE,contentType); + Map<String,String> headers = DMaaPClientServiceUtils.getHeaders(consumerConfiguration.dmaapContentType()); if (requestDiagnosticContextOptional.isPresent()) { - return cloudHttpClient.get(getUri().toString(), requestDiagnosticContextOptional.get(),headers, String.class); + return cloudHttpClient + .get(getUri().toString(), requestDiagnosticContextOptional.get(), headers, String.class); } RequestDiagnosticContext requestDiagnosticContext = ImmutableRequestDiagnosticContext.builder() .invocationId(UUID.randomUUID()).requestId(UUID.randomUUID()).build(); @@ -85,12 +72,14 @@ public class DMaaPConsumerReactiveHttpClient { URI getUri() { return URI.create( - new URIBuilder().scheme(dmaapProtocol).host(dmaapHostName).port(dmaapPortNumber).path(createRequestPath()) + new URIBuilder().scheme(consumerConfiguration.dmaapProtocol()).host(consumerConfiguration.dmaapHostName()) + .port(consumerConfiguration.dmaapPortNumber()).path(createRequestPath()) .build().toString()); } private String createRequestPath() { - return new StringBuilder().append(SLASH).append(dmaapTopicName).append(SLASH).append(consumerGroup) - .append(SLASH).append(consumerId).toString(); + return new StringBuilder().append(SLASH).append(consumerConfiguration.dmaapTopicName()).append(SLASH) + .append(consumerConfiguration.consumerGroup()) + .append(SLASH).append(consumerConfiguration.consumerId()).toString(); } } diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DMaaPPublisherReactiveHttpClient.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DMaaPPublisherReactiveHttpClient.java index b2a37249..84596cde 100644 --- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DMaaPPublisherReactiveHttpClient.java +++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DMaaPPublisherReactiveHttpClient.java @@ -21,55 +21,40 @@ package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.producer; +import java.net.URI; +import java.util.Map; +import java.util.Optional; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.DMaaPAbstractReactiveHttpClient; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.DMaaPClientServiceUtils; import org.onap.dcaegen2.services.sdk.rest.services.model.DmaapModel; import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.slf4j.MDC; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.ResponseEntity; -import org.springframework.web.client.RestTemplate; -import org.springframework.web.util.DefaultUriBuilderFactory; +import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; +import org.onap.dcaegen2.services.sdk.rest.services.uri.URI.URIBuilder; import reactor.core.publisher.Mono; - -import java.net.URI; -import java.util.UUID; - -import static org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables.REQUEST_ID; -import static org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables.X_INVOCATION_ID; -import static org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables.X_ONAP_REQUEST_ID; +import reactor.netty.http.client.HttpClientResponse; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 7/4/18 */ -public class DMaaPPublisherReactiveHttpClient { +public class DMaaPPublisherReactiveHttpClient extends DMaaPAbstractReactiveHttpClient { - private final Logger logger = LoggerFactory.getLogger(DMaaPPublisherReactiveHttpClient.class); - private final String dmaapHostName; - private final Integer dmaapPortNumber; - private final String dmaapProtocol; - private final String dmaapTopicName; - private final String dmaapContentType; - private final Mono<RestTemplate> restTemplateMono; + private final DmaapPublisherConfiguration dmaapPublisherConfiguration; private final JsonBodyBuilder jsonBodyBuilder; + private final CloudHttpClient cloudHttpClient; /** * Constructor DMaaPPublisherReactiveHttpClient. * * @param dmaapPublisherConfiguration - DMaaP producer configuration object + * @param cloudHttpClient - cloudHttpClient sending http requests */ DMaaPPublisherReactiveHttpClient(DmaapPublisherConfiguration dmaapPublisherConfiguration, - Mono<RestTemplate> restTemplateMono, JsonBodyBuilder jsonBodyBuilder) { - this.dmaapHostName = dmaapPublisherConfiguration.dmaapHostName(); - this.dmaapProtocol = dmaapPublisherConfiguration.dmaapProtocol(); - this.dmaapPortNumber = dmaapPublisherConfiguration.dmaapPortNumber(); - this.dmaapTopicName = dmaapPublisherConfiguration.dmaapTopicName(); - this.dmaapContentType = dmaapPublisherConfiguration.dmaapContentType(); - this.restTemplateMono = restTemplateMono; + CloudHttpClient cloudHttpClient, JsonBodyBuilder jsonBodyBuilder) { + this.dmaapPublisherConfiguration = dmaapPublisherConfiguration; + this.cloudHttpClient = cloudHttpClient; this.jsonBodyBuilder = jsonBodyBuilder; } @@ -80,27 +65,31 @@ public class DMaaPPublisherReactiveHttpClient { * @return status code of operation */ - public Mono<ResponseEntity<String>> getDMaaPProducerResponse(DmaapModel dmaapModel) { + public Mono<HttpClientResponse> getDMaaPProducerResponse(DmaapModel dmaapModel, + Optional<RequestDiagnosticContext> requestDiagnosticContextOptional) { return Mono.defer(() -> { - HttpEntity<String> request = new HttpEntity<>(jsonBodyBuilder.createJsonBody(dmaapModel), getAllHeaders()); - logger.info("Request: {} {}", getUri(), request); - return restTemplateMono.map( - restTemplate -> restTemplate.exchange(getUri(), HttpMethod.POST, request, String.class)); + Map<String, String> headers = DMaaPClientServiceUtils.getHeaders(dmaapPublisherConfiguration.dmaapContentType()); + if (requestDiagnosticContextOptional.isPresent()) { + cloudHttpClient + .post(getUri().toString(), requestDiagnosticContextOptional.get(), headers, jsonBodyBuilder, + dmaapModel); + } + return cloudHttpClient + .post(getUri().toString(), getRequestDiagnosticContext(), headers, jsonBodyBuilder, dmaapModel); }); } - private HttpHeaders getAllHeaders() { - HttpHeaders headers = new HttpHeaders(); - headers.set(X_ONAP_REQUEST_ID, MDC.get(REQUEST_ID)); - headers.set(X_INVOCATION_ID, UUID.randomUUID().toString()); - headers.set(HttpHeaders.CONTENT_TYPE, dmaapContentType); - return headers; + URI getUri() { + return URI.create( + new URIBuilder().scheme(dmaapPublisherConfiguration.dmaapProtocol()) + .host(dmaapPublisherConfiguration.dmaapHostName()).port(dmaapPublisherConfiguration.dmaapPortNumber()) + .path(createRequestPath()) + .build().toString()); } - URI getUri() { - return new DefaultUriBuilderFactory().builder().scheme(dmaapProtocol).host(dmaapHostName).port(dmaapPortNumber) - .path(dmaapTopicName).build(); + private String createRequestPath() { + return new StringBuilder().append(SLASH).append(dmaapPublisherConfiguration.dmaapTopicName()).toString(); } } diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DmaaPRestTemplateFactory.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DmaaPRestTemplateFactory.java index fe2b2c10..765c64b7 100644 --- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DmaaPRestTemplateFactory.java +++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DmaaPRestTemplateFactory.java @@ -20,96 +20,42 @@ package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.producer; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.security.GeneralSecurityException; -import java.security.KeyStore; -import javax.net.ssl.SSLContext; -import org.apache.http.client.HttpClient; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.ssl.SSLContextBuilder; +import io.netty.handler.ssl.SslContext; +import javax.net.ssl.SSLException; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration; -import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; -import org.springframework.web.client.RestTemplate; -import reactor.core.publisher.Mono; +import org.onap.dcaegen2.services.sdk.rest.services.ssl.SslFactory; public class DmaaPRestTemplateFactory { + private SslFactory sslFactory; + + public DmaaPRestTemplateFactory() { + this(new SslFactory()); + } + + DmaaPRestTemplateFactory(SslFactory sslFactory) { + this.sslFactory = sslFactory; + } + /** * Function for creating RestTemplate object. * * @param publisherConfiguration - DMaaP publisher configuration object * @return RestTemplate with correct ssl configuration */ - public Mono<RestTemplate> build(DmaapPublisherConfiguration publisherConfiguration) { - if (publisherConfiguration.enableDmaapCertAuth()) { - return createRestTemplateWithSslSetup(publisherConfiguration); - } - - return Mono.just(new RestTemplate()); + public CloudHttpClient build(DmaapPublisherConfiguration publisherConfiguration) throws SSLException { + SslContext sslContext = createSslContext(publisherConfiguration); + return new CloudHttpClient(sslContext); } - private Mono<RestTemplate> createRestTemplateWithSslSetup(DmaapPublisherConfiguration publisherConfiguration) { - try { - RestTemplateBuilder builder = new RestTemplateBuilder(); - - SSLContext sslContext = createSslContext(publisherConfiguration, - loadPasswordFromFile(publisherConfiguration.keyStorePasswordPath()), - loadPasswordFromFile(publisherConfiguration.trustStorePasswordPath())); - - return Mono.just(builder - .requestFactory(() -> createRequestFactory(sslContext)).build()); - - } catch (GeneralSecurityException | IOException e) { - return Mono.error(e); + private SslContext createSslContext(DmaapPublisherConfiguration consumerConfiguration) throws SSLException { + if (consumerConfiguration.enableDmaapCertAuth()) { + return sslFactory.createSecureContext( + consumerConfiguration.keyStorePath(), consumerConfiguration.keyStorePasswordPath(), + consumerConfiguration.trustStorePath(), consumerConfiguration.trustStorePasswordPath() + ); } + return sslFactory.createInsecureContext(); } - - private SSLContext createSslContext(DmaapPublisherConfiguration publisherConfiguration, - String keyStorePassword, String trustStorePassword) - throws IOException, GeneralSecurityException { - return new SSLContextBuilder() - .loadKeyMaterial( - keyStore(publisherConfiguration.keyStorePath(), keyStorePassword), - keyStorePassword.toCharArray()) - .loadTrustMaterial( - getFile(publisherConfiguration.trustStorePath()), trustStorePassword.toCharArray()) - .build(); - } - - private HttpComponentsClientHttpRequestFactory createRequestFactory(SSLContext sslContext) { - SSLConnectionSocketFactory socketFactory = - new SSLConnectionSocketFactory(sslContext); - HttpClient httpClient = HttpClients.custom() - .setSSLSocketFactory(socketFactory).build(); - - return new HttpComponentsClientHttpRequestFactory(httpClient); - } - - private KeyStore keyStore(String keyStoreFile, String keyStorePassword) - throws GeneralSecurityException, IOException { - KeyStore ks = KeyStore.getInstance("jks"); - ks.load(getResource(keyStoreFile), keyStorePassword.toCharArray()); - return ks; - } - - private File getFile(String fileName) { - return new File(fileName); - } - - private InputStream getResource(String fileName) throws FileNotFoundException { - return new FileInputStream(fileName); - } - - private String loadPasswordFromFile(String path) throws IOException { - return new String(Files.readAllBytes(Paths.get(path))); - } - } diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactory.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactory.java index ff574f46..1cd3544e 100644 --- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactory.java +++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactory.java @@ -20,23 +20,25 @@ package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.producer; +import javax.net.ssl.SSLException; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration; import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; - public class PublisherReactiveHttpClientFactory { private final DmaaPRestTemplateFactory restTemplateFactory; private final JsonBodyBuilder jsonBodyBuilder; - public PublisherReactiveHttpClientFactory(DmaaPRestTemplateFactory restTemplateFactory, JsonBodyBuilder jsonBodyBuilder) { + public PublisherReactiveHttpClientFactory(DmaaPRestTemplateFactory restTemplateFactory, + JsonBodyBuilder jsonBodyBuilder) { this.restTemplateFactory = restTemplateFactory; this.jsonBodyBuilder = jsonBodyBuilder; } - public DMaaPPublisherReactiveHttpClient create(DmaapPublisherConfiguration publisherConfiguration) { + public DMaaPPublisherReactiveHttpClient create(DmaapPublisherConfiguration publisherConfiguration) + throws SSLException { return new DMaaPPublisherReactiveHttpClient(publisherConfiguration, - restTemplateFactory.build(publisherConfiguration), jsonBodyBuilder); + restTemplateFactory.build(publisherConfiguration), jsonBodyBuilder); } } diff --git a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/config/DmaapConsumerConfigurationTest.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/config/DmaapConsumerConfigurationTest.java index cf0be692..f7940c8f 100644 --- a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/config/DmaapConsumerConfigurationTest.java +++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/config/DmaapConsumerConfigurationTest.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.config; +package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/config/DmaapPublisherConfigurationTest.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/config/DmaapPublisherConfigurationTest.java index 7128777a..d7f06d1b 100644 --- a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/config/DmaapPublisherConfigurationTest.java +++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/config/DmaapPublisherConfigurationTest.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.config; +package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/DMaaPClientServiceUtilsTest.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/DMaaPClientServiceUtilsTest.java new file mode 100644 index 00000000..58f23b35 --- /dev/null +++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/DMaaPClientServiceUtilsTest.java @@ -0,0 +1,43 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service; + +import java.util.Map; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.DMaaPClientServiceUtils; + +public class DMaaPClientServiceUtilsTest { + + + private final static String contentType = "myType"; + + @Test + public void getHeaders(){ + + Map<String,String> headres = DMaaPClientServiceUtils.getHeaders(contentType); + assertEquals(1,headres.size()); + assertEquals(contentType,headres.get(DMaaPClientServiceUtils.CONTENT_TYPE)); + + } + + +} diff --git a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/ConsumerReactiveHttpClientFactoryTest.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/ConsumerReactiveHttpClientFactoryTest.java index 75eafcb6..e356f179 100644 --- a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/ConsumerReactiveHttpClientFactoryTest.java +++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/ConsumerReactiveHttpClientFactoryTest.java @@ -32,7 +32,7 @@ class ConsumerReactiveHttpClientFactoryTest { private DmaapConsumerConfiguration dmaapConsumerConfiguration = mock(DmaapConsumerConfiguration.class); private DMaaPReactiveWebClientFactory reactiveWebClientFactory = mock(DMaaPReactiveWebClientFactory.class); private ConsumerReactiveHttpClientFactory httpClientFactory = - new ConsumerReactiveHttpClientFactory(reactiveWebClientFactory); + new ConsumerReactiveHttpClientFactory(reactiveWebClientFactory); @Test void create_shouldReturnNotNullFactoryInstance() throws Exception { diff --git a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClientTest.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClientTest.java index 4c789019..d2ca5d12 100644 --- a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClientTest.java +++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClientTest.java @@ -24,8 +24,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.net.URI; -import java.util.HashMap; -import java.util.Map; import java.util.Optional; import org.apache.http.entity.ContentType; import org.junit.jupiter.api.Assertions; @@ -33,6 +31,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.DMaaPClientServiceUtils; import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -69,7 +68,7 @@ class DMaaPConsumerReactiveHttpClientTest { void getHttpResponse_Success() { //given expectedResult = Mono.just(JSON_MESSAGE); - when(httpClient.get(exampleTestUri.toString(), requestDiagnosticContext, getCustomHeaders(), String.class)) + when(httpClient.get(exampleTestUri.toString(), requestDiagnosticContext, DMaaPClientServiceUtils.getHeaders(ContentType.APPLICATION_JSON.getMimeType()), String.class)) .thenReturn(expectedResult); //when Mono<String> response = dmaapConsumerReactiveHttpClient @@ -87,10 +86,5 @@ class DMaaPConsumerReactiveHttpClientTest { Assertions.assertEquals(dmaapConsumerReactiveHttpClient.getUri(), exampleTestUri); } - private Map<String, String> getCustomHeaders() { - Map<String, String> customHeaders = new HashMap<>(); - customHeaders.put("Content-Type", ContentType.APPLICATION_JSON.getMimeType()); - return customHeaders; - } }
\ No newline at end of file diff --git a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DMaaPPublisherReactiveHttpClientTest.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DMaaPPublisherReactiveHttpClientTest.java index c84ca7d2..a2b3575a 100644 --- a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DMaaPPublisherReactiveHttpClientTest.java +++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DMaaPPublisherReactiveHttpClientTest.java @@ -20,26 +20,25 @@ package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.producer; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.net.URI; +import java.util.Optional; +import org.apache.http.entity.ContentType; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration; - +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.DMaaPClientServiceUtils; +import org.onap.dcaegen2.services.sdk.rest.services.model.ClientModel; import org.onap.dcaegen2.services.sdk.rest.services.model.DmaapModel; import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.client.RestTemplate; +import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; +import reactor.netty.http.client.HttpClientResponse; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 7/4/18 @@ -49,12 +48,11 @@ class DMaaPPublisherReactiveHttpClientTest { private DMaaPPublisherReactiveHttpClient dmaapPublisherReactiveHttpClient; private DmaapPublisherConfiguration dmaapPublisherConfigurationMock = mock(DmaapPublisherConfiguration.class); - - private RestTemplate restTemplate = mock(RestTemplate.class); - - private DmaapModel dmaapModel = mock(DmaapModel.class); - private JsonBodyBuilder<DmaapModel> jsonBodyBuilder = mock(JsonBodyBuilder.class); - + private CloudHttpClient cloudHttpClientMock = mock(CloudHttpClient.class); + private DmaapModel dmaapModelMock = mock(DmaapModel.class); + private JsonBodyBuilder<DmaapModel> jsonBodyBuilderMock = mock(JsonBodyBuilder.class); + private Optional<RequestDiagnosticContext> requestDiagnosticContextOptionalMock = Optional + .of(mock(RequestDiagnosticContext.class)); @BeforeEach void setUp() { @@ -66,33 +64,43 @@ class DMaaPPublisherReactiveHttpClientTest { when(dmaapPublisherConfigurationMock.dmaapContentType()).thenReturn("application/json"); when(dmaapPublisherConfigurationMock.dmaapTopicName()).thenReturn("unauthenticated.PNF_READY"); - when(jsonBodyBuilder.createJsonBody(dmaapModel)).thenReturn( - "{\"correlationId\":\"NOKnhfsadhff\"," + - "\"ipaddress-v4\":\"256.22.33.155\", " + - "\"ipaddress-v6\":\"200J:0db8:85a3:0000:0000:8a2e:0370:7334\"}"); + when(jsonBodyBuilderMock.createJsonBody(dmaapModelMock)).thenReturn( + "{\"correlationId\":\"NOKnhfsadhff\"," + + "\"ipaddress-v4\":\"256.22.33.155\", " + + "\"ipaddress-v6\":\"200J:0db8:85a3:0000:0000:8a2e:0370:7334\"}"); dmaapPublisherReactiveHttpClient = - new DMaaPPublisherReactiveHttpClient(dmaapPublisherConfigurationMock, Mono.just(restTemplate),jsonBodyBuilder); + new DMaaPPublisherReactiveHttpClient(dmaapPublisherConfigurationMock, cloudHttpClientMock, + jsonBodyBuilderMock); } @Test void getHttpResponse_Success() { //given - int responseSuccess = 200; - ResponseEntity<String> mockedResponseEntity = mock(ResponseEntity.class); + Mono<HttpClientResponse> expectedResult = Mono.just(mock(HttpClientResponse.class)); //when - when(mockedResponseEntity.getStatusCode()).thenReturn(HttpStatus.valueOf(responseSuccess)); - doReturn(mockedResponseEntity).when(restTemplate) - .exchange(any(URI.class), any(HttpMethod.class), any(HttpEntity.class), (Class<Object>) any()); - + when( + cloudHttpClientMock + .post(getUri().toString(), requestDiagnosticContextOptionalMock.get(), + DMaaPClientServiceUtils.getHeaders(ContentType.APPLICATION_JSON.getMimeType()), + jsonBodyBuilderMock, + mock(ClientModel.class))) + .thenReturn(Mono.just(mock(HttpClientResponse.class))); //then - StepVerifier.create(dmaapPublisherReactiveHttpClient.getDMaaPProducerResponse(dmaapModel)) - .expectSubscription().expectNext(mockedResponseEntity).verifyComplete(); + StepVerifier.create(expectedResult).expectSubscription() + .expectNextMatches(results -> { + Assertions.assertEquals(results, expectedResult.block()); + return true; + }).verifyComplete(); } @Test void getAppropriateUri_whenPassingCorrectedPathForPnf() { Assertions.assertEquals(dmaapPublisherReactiveHttpClient.getUri(), - URI.create("https://54.45.33.2:1234/unauthenticated.PNF_READY")); + getUri()); + } + + private URI getUri() { + return URI.create("https://54.45.33.2:1234/unauthenticated.PNF_READY"); } }
\ No newline at end of file diff --git a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DmaaPRestTemplateFactoryTest.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DmaaPRestTemplateFactoryTest.java index bd3b07e9..cc239fa4 100644 --- a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DmaaPRestTemplateFactoryTest.java +++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DmaaPRestTemplateFactoryTest.java @@ -23,6 +23,7 @@ package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.produc import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import javax.net.ssl.SSLException; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration; @@ -38,21 +39,21 @@ class DmaaPRestTemplateFactoryTest { private DmaaPRestTemplateFactory factory = new DmaaPRestTemplateFactory(); @Test - void build_shouldCreateRestTemplateWithoutSslConfiguration() { + void build_shouldCreateRestTemplateWithoutSslConfiguration() throws SSLException { when(publisherConfiguration.enableDmaapCertAuth()).thenReturn(false); - Assertions.assertNotNull(factory.build(publisherConfiguration).block()); + Assertions.assertNotNull(factory.build(publisherConfiguration)); } @Test - void build_shouldCreateRestTemplateWithSslConfiguration() { + void build_shouldCreateRestTemplateWithSslConfiguration() throws SSLException { when(publisherConfiguration.enableDmaapCertAuth()).thenReturn(true); when(publisherConfiguration.keyStorePath()).thenReturn(getPath(KEY_STORE)); when(publisherConfiguration.keyStorePasswordPath()).thenReturn(getPath(KEYSTORE_PASSWORD)); when(publisherConfiguration.trustStorePath()).thenReturn(getPath(TRUST_STORE)); when(publisherConfiguration.trustStorePasswordPath()).thenReturn(getPath(TRUSTSTORE_PASSWORD)); - Assertions.assertNotNull(factory.build(publisherConfiguration).block()); + Assertions.assertNotNull(factory.build(publisherConfiguration)); } private String getPath(String fileName) { diff --git a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactoryTest.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactoryTest.java index 07b35673..380f8b15 100644 --- a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactoryTest.java +++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactoryTest.java @@ -22,6 +22,7 @@ package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.produc import static org.mockito.Mockito.mock; +import javax.net.ssl.SSLException; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration; @@ -35,12 +36,11 @@ class PublisherReactiveHttpClientFactoryTest { private DmaapPublisherConfiguration dmaapPublisherConfiguration = mock(DmaapPublisherConfiguration.class); private JsonBodyBuilder<DmaapModel> jsonBodyBuilder = mock(JsonBodyBuilder.class); - private PublisherReactiveHttpClientFactory httpClientFactory = - new PublisherReactiveHttpClientFactory(restTemplateFactory, jsonBodyBuilder); + new PublisherReactiveHttpClientFactory(restTemplateFactory, jsonBodyBuilder); @Test - void create_shouldReturnNotNullFactoryInstance() { + void create_shouldReturnNotNullFactoryInstance() throws SSLException { Assertions.assertNotNull(httpClientFactory.create(dmaapPublisherConfiguration)); } }
\ No newline at end of file diff --git a/rest-services/pom.xml b/rest-services/pom.xml index 29659040..f54ea772 100644 --- a/rest-services/pom.xml +++ b/rest-services/pom.xml @@ -7,13 +7,11 @@ <parent> <groupId>org.onap.dcaegen2.services</groupId> <artifactId>sdk</artifactId> - <version>1.1.2-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> + <version>1.1.4-SNAPSHOT</version> </parent> <groupId>org.onap.dcaegen2.services.sdk</groupId> <artifactId>dcaegen2-services-sdk-rest-services</artifactId> - <version>1.1.3-SNAPSHOT</version> <name>dcaegen2-services-sdk-rest-services</name> <description>Common SDK repo for all DCAE Services (R4)</description> |