Remove usage of Spring in SDK II 93/79193/1
authorpwielebs <piotr.wielebski@nokia.com>
Tue, 26 Feb 2019 15:00:40 +0000 (16:00 +0100)
committerpwielebs <piotr.wielebski@nokia.com>
Tue, 26 Feb 2019 15:00:40 +0000 (16:00 +0100)
- AAI Http Clients

Change-Id: Id83a72699e860d1d71f0bdcd2e977c6c0cfc113e
Issue-ID: DCAEGEN2-1277
Signed-off-by: pwielebs <piotr.wielebski@nokia.com>
rest-services/aai-client/pom.xml
rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/config/AaiClientConfiguration.java
rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiHttpClientFactory.java
rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiReactiveWebClientFactory.java [deleted file]
rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiReactiveHttpPatchClient.java [deleted file]
rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiReactiveHttpPutClient.java [deleted file]
rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiReactiveWebClientFactoryTest.java [deleted file]
rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClientTest.java [deleted file]
rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiReactiveHttpPatchClientTest.java [deleted file]
rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiReactiveHttpPutClientTest.java [deleted file]

index d3805fd..2d2ee1e 100644 (file)
       <artifactId>common-dependency</artifactId>
       <version>${project.version}</version>
     </dependency>
-
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>spring-webflux</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>spring-context</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>spring-web</artifactId>
-    </dependency>
-
     <dependency>
       <groupId>org.junit.jupiter</groupId>
       <artifactId>junit-jupiter-engine</artifactId>
index fc4b0f4..30bf253 100644 (file)
@@ -22,14 +22,11 @@ package org.onap.dcaegen2.services.sdk.rest.services.aai.client.config;
 
 import org.immutables.gson.Gson;
 import org.immutables.value.Value;
-import org.springframework.stereotype.Component;
-
 
 import java.io.Serializable;
 import java.util.Map;
 
 
-@Component
 @Value.Immutable(prehash = true)
 @Value.Style(builder = "new")
 @Gson.TypeAdapters
index 903528b..d304756 100644 (file)
@@ -30,7 +30,6 @@ import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
 import org.onap.dcaegen2.services.sdk.rest.services.ssl.SslFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import reactor.core.publisher.Mono;
 import reactor.netty.Connection;
 import reactor.netty.http.client.HttpClient;
 import reactor.netty.http.client.HttpClientRequest;
diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiReactiveWebClientFactory.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiReactiveWebClientFactory.java
deleted file mode 100644 (file)
index 85ba8ea..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * ============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.aai.client.service;
-
-import io.netty.handler.ssl.SslContext;
-
-import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
-import org.onap.dcaegen2.services.sdk.rest.services.ssl.SslFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.slf4j.MDC;
-import org.springframework.http.client.reactive.ClientHttpConnector;
-import org.springframework.http.client.reactive.ReactorClientHttpConnector;
-import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
-import org.springframework.web.reactive.function.client.WebClient;
-
-import reactor.core.publisher.Mono;
-import reactor.netty.http.client.HttpClient;
-
-import javax.net.ssl.SSLException;
-import java.util.Map;
-
-import static org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables.RESPONSE_CODE;
-import static org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables.SERVICE_NAME;
-import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication;
-
-
-public class AaiReactiveWebClientFactory {
-
-    private static final Logger LOGGER = LoggerFactory.getLogger(AaiReactiveWebClientFactory.class);
-
-    private final String aaiUserName;
-    private final String aaiUserPassword;
-    private final Map<String, String> aaiHeaders;
-    private final Boolean enableAaiCertAuth;
-    private final String trustStorePath;
-    private final String trustStorePasswordPath;
-    private final String keyStorePath;
-    private final String keyStorePasswordPath;
-    private final SslFactory sslFactory;
-
-    /**
-     * Creating AaiReactiveWebClientFactory.
-     *
-     * @param configuration - configuration object
-     * @param sslFactory - factory for ssl setup
-     */
-    public AaiReactiveWebClientFactory(SslFactory sslFactory, AaiClientConfiguration configuration) {
-        this.aaiUserName = configuration.aaiUserName();
-        this.aaiUserPassword = configuration.aaiUserPassword();
-        this.aaiHeaders = configuration.aaiHeaders();
-        this.trustStorePath = configuration.trustStorePath();
-        this.trustStorePasswordPath = configuration.trustStorePasswordPath();
-        this.keyStorePath = configuration.keyStorePath();
-        this.keyStorePasswordPath = configuration.keyStorePasswordPath();
-        this.enableAaiCertAuth = configuration.enableAaiCertAuth();
-        this.sslFactory = sslFactory;
-    }
-
-    /**
-     * Construct Reactive WebClient with appropriate settings.
-     *
-     * @return WebClient
-     */
-    public WebClient build() throws SSLException {
-        LOGGER.debug("Setting ssl context");
-        
-        SslContext sslContext = createSslContext();
-
-        ClientHttpConnector reactorClientHttpConnector = new ReactorClientHttpConnector(
-            HttpClient.create().secure(sslContextSpec -> sslContextSpec.sslContext(sslContext)));
-
-        return WebClient.builder()
-            .clientConnector(reactorClientHttpConnector)
-            .defaultHeaders(httpHeaders -> httpHeaders.setAll(aaiHeaders))
-            .filter(basicAuthentication(aaiUserName, aaiUserPassword))
-            .filter(logRequest())
-            .filter(logResponse())
-            .build();
-    }
-
-    private SslContext createSslContext() throws SSLException {
-        if (enableAaiCertAuth) {
-            return sslFactory.createSecureContext(
-                keyStorePath,
-                keyStorePasswordPath,
-                trustStorePath,
-                trustStorePasswordPath
-            );
-        }
-        return sslFactory.createInsecureContext();
-    }
-    
-    private ExchangeFilterFunction logRequest() {
-        return ExchangeFilterFunction.ofRequestProcessor(clientRequest -> {
-            MDC.put(SERVICE_NAME, String.valueOf(clientRequest.url()));
-            LOGGER.info("Request: {} {}", clientRequest.method(), clientRequest.url());
-            clientRequest.headers()
-                .forEach((name, values) -> values.forEach(value -> LOGGER.info("{}={}", name, value)));
-            MDC.remove(SERVICE_NAME);
-            return Mono.just(clientRequest);
-        });
-    }
-
-    private ExchangeFilterFunction logResponse() {
-        return ExchangeFilterFunction.ofResponseProcessor(clientResponse -> {
-            MDC.put(RESPONSE_CODE, String.valueOf(clientResponse.statusCode()));
-            LOGGER.info("Response Status {}", clientResponse.statusCode());
-            MDC.remove(RESPONSE_CODE);
-            return Mono.just(clientResponse);
-        });
-    }
-}
diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiReactiveHttpPatchClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiReactiveHttpPatchClient.java
deleted file mode 100644 (file)
index 841db6e..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-/*-
- * ============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.aai.client.service.http.patch;
-
-
-import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
-import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel;
-import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
-import org.slf4j.MDC;
-import org.springframework.web.reactive.function.client.ClientResponse;
-import org.springframework.web.reactive.function.client.WebClient;
-import org.springframework.web.util.DefaultUriBuilderFactory;
-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;
-
-
-public class AaiReactiveHttpPatchClient {
-
-    private WebClient webClient;
-    private final String aaiHost;
-    private final String aaiProtocol;
-    private final Integer aaiHostPortNumber;
-    private final String aaiBasePath;
-    private final String aaiPnfPath;
-    private final JsonBodyBuilder jsonBodyBuilder;
-
-    /**
-     * Constructor of AaiProducerReactiveHttpClient.
-     *
-     * @param configuration - AAI producer configuration object
-     */
-    public AaiReactiveHttpPatchClient(AaiClientConfiguration configuration, JsonBodyBuilder jsonBodyBuilder) {
-        this.aaiHost = configuration.aaiHost();
-        this.aaiProtocol = configuration.aaiProtocol();
-        this.aaiHostPortNumber = configuration.aaiPort();
-        this.aaiBasePath = configuration.aaiBasePath();
-        this.aaiPnfPath = configuration.aaiPnfPath();
-        this.jsonBodyBuilder = jsonBodyBuilder;
-    }
-
-    /**
-     * Function for calling AAI Http producer - patch request to AAI database.
-     *
-     * @param aaiModel - object which will be sent to AAI database
-     * @return status code of operation
-     */
-    public Mono<ClientResponse> getAaiProducerResponse(AaiModel aaiModel) {
-        return patchAaiRequest(aaiModel);
-    }
-
-    public AaiReactiveHttpPatchClient createAaiWebClient(WebClient webClient) {
-        this.webClient = webClient;
-        return this;
-    }
-
-    private Mono<ClientResponse> patchAaiRequest(AaiModel aaiModel) {
-        return
-            webClient.patch()
-                .uri(getUri(aaiModel.getCorrelationId()))
-                .header(X_ONAP_REQUEST_ID, MDC.get(REQUEST_ID))
-                .header(X_INVOCATION_ID, UUID.randomUUID().toString())
-                .body(Mono.just(jsonBodyBuilder.createJsonBody(aaiModel)), String.class)
-                .exchange();
-    }
-
-    URI getUri(String pnfName) {
-        return new DefaultUriBuilderFactory().builder().scheme(aaiProtocol).host(aaiHost).port(aaiHostPortNumber)
-            .path(aaiBasePath + aaiPnfPath + "/" + pnfName).build();
-    }
-}
\ No newline at end of file
diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiReactiveHttpPutClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiReactiveHttpPutClient.java
deleted file mode 100644 (file)
index bd5271b..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * DCAEGEN2-SERVICES-SDK
- * ================================================================================
- * Copyright (C) 2018-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.aai.client.service.http.put;
-
-
-import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
-import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel;
-import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
-import org.slf4j.MDC;
-import org.springframework.web.reactive.function.client.ClientResponse;
-import org.springframework.web.reactive.function.client.WebClient;
-import org.springframework.web.util.DefaultUriBuilderFactory;
-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;
-
-
-public class AaiReactiveHttpPutClient {
-
-    private WebClient webClient;
-    private final String aaiHost;
-    private final String aaiProtocol;
-    private final Integer aaiHostPortNumber;
-    private final String aaiBasePath;
-    private final String aaiPnfPath;
-
-    private final JsonBodyBuilder jsonBodyBuilder;
-
-    /**
-     * Constructor of AaiProducerReactiveHttpClient.
-     *
-     * @param configuration - AAI producer configuration object
-     */
-    public AaiReactiveHttpPutClient(AaiClientConfiguration configuration, JsonBodyBuilder jsonBodyBuilder) {
-        this.aaiHost = configuration.aaiHost();
-        this.aaiProtocol = configuration.aaiProtocol();
-        this.aaiHostPortNumber = configuration.aaiPort();
-        this.aaiBasePath = configuration.aaiBasePath();
-        this.aaiPnfPath = configuration.aaiPnfPath();
-        this.jsonBodyBuilder = jsonBodyBuilder;
-    }
-
-    /**
-     * Function for calling AAI Http producer - put request to AAI database.
-     *
-     * @param aaiModel - object which will be sent to AAI database
-     * @return status code of operation
-     */
-    public Mono<ClientResponse> getAaiProducerResponse(AaiModel aaiModel) {
-        return putAaiRequest(aaiModel);
-    }
-
-    public AaiReactiveHttpPutClient createAaiWebClient(WebClient webClient) {
-        this.webClient = webClient;
-        return this;
-    }
-
-    private Mono<ClientResponse> putAaiRequest(AaiModel aaiModel) {
-        return
-                webClient.put()
-                        .uri(getUri(aaiModel.getCorrelationId()))
-                        .header(X_ONAP_REQUEST_ID, MDC.get(REQUEST_ID))
-                        .header(X_INVOCATION_ID, UUID.randomUUID().toString())
-                        .body(Mono.just(jsonBodyBuilder.createJsonBody(aaiModel)), String.class)
-                        .exchange();
-    }
-
-    URI getUri(String pnfName) {
-        return new DefaultUriBuilderFactory().builder().scheme(aaiProtocol).host(aaiHost).port(aaiHostPortNumber)
-                .path(aaiBasePath + aaiPnfPath + "/" + pnfName).build();
-    }
-}
\ No newline at end of file
diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiReactiveWebClientFactoryTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiReactiveWebClientFactoryTest.java
deleted file mode 100644 (file)
index 46a57b6..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/*-
- * ============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.aai.client.service;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import io.netty.handler.ssl.SslContext;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
-import org.onap.dcaegen2.services.sdk.rest.services.ssl.SslFactory;
-
-import javax.net.ssl.SSLException;
-
-
-class AaiReactiveWebClientFactoryTest {
-
-    private static final String TRUST_STORE_PATH = "trust_store_path";
-    private static final String TRUST_STORE_PASS_PATH = "trust_store_pass_path";
-    private static final String KEY_STORE_PATH = "key_store_path";
-    private static final String KEY_STORE_PASS_PATH = "key_store_pass_path";
-    private SslFactory sslFactory = mock(SslFactory.class);
-    private AaiClientConfiguration aaiClientConfiguration = mock(AaiClientConfiguration.class);
-    private AaiReactiveWebClientFactory aaiReactiveWebClientFactory;
-    private SslContext dummySslContext = mock(SslContext.class);
-
-    @Test
-    void shouldCreateWebClientWithSecureSslContext() throws SSLException {
-        givenEnabledAaiCertAuthConfiguration();
-        aaiReactiveWebClientFactory = new AaiReactiveWebClientFactory(sslFactory, aaiClientConfiguration);
-
-        Assertions.assertNotNull(aaiReactiveWebClientFactory.build());
-        verify(sslFactory).createSecureContext(KEY_STORE_PATH, KEY_STORE_PASS_PATH,
-                TRUST_STORE_PATH, TRUST_STORE_PASS_PATH);
-    }
-
-    @Test
-    void shouldCreateWebClientWithInsecureSslContext() throws SSLException {
-        when(aaiClientConfiguration.enableAaiCertAuth()).thenReturn(false);
-        when(sslFactory.createInsecureContext()).thenReturn(dummySslContext);
-        aaiReactiveWebClientFactory = new AaiReactiveWebClientFactory(sslFactory, aaiClientConfiguration);
-
-        Assertions.assertNotNull(aaiReactiveWebClientFactory.build());
-        verify(sslFactory).createInsecureContext();
-    }
-
-    private void givenEnabledAaiCertAuthConfiguration() throws SSLException {
-        when(aaiClientConfiguration.enableAaiCertAuth()).thenReturn(true);
-        when(aaiClientConfiguration.trustStorePath()).thenReturn(TRUST_STORE_PATH);
-        when(aaiClientConfiguration.trustStorePasswordPath()).thenReturn(TRUST_STORE_PASS_PATH);
-        when(aaiClientConfiguration.keyStorePath()).thenReturn(KEY_STORE_PATH);
-        when(aaiClientConfiguration.keyStorePasswordPath()).thenReturn(KEY_STORE_PASS_PATH);
-        when(sslFactory.createSecureContext(KEY_STORE_PATH, KEY_STORE_PASS_PATH, TRUST_STORE_PATH, TRUST_STORE_PASS_PATH))
-                .thenReturn(dummySslContext);
-    }
-}
diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClientTest.java
deleted file mode 100644 (file)
index 41a532d..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * DCAEGEN2-SERVICES-SDK
- * ================================================================================
- * Copyright (C) 2018-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.aai.client.service.http.get;
-
-
-import org.junit.jupiter.api.BeforeEach;
-import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
-import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel;
-import reactor.netty.http.client.HttpClient;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class AaiHttpGetClientTest {
-
-    private static final String SUCCESS_RESPONSE = "{\"correlationId\":\"NOKnhfsadhff\"," +
-            "\"ipaddress-v4\":\"256.22.33.155\", " +
-            "\"ipaddress-v6\":\"200J:0db8:85a3:0000:0000:8a2e:0370:7334\"}";
-
-    private AaiHttpGetClient aaiReactiveHttpGetClient;
-    private HttpClient httpClient;
-
-    private AaiClientConfiguration aaiConfigurationMock;
-    private AaiModel aaiModel;
-    private Map<String,String> aaiHeaders;
-
-
-    @BeforeEach
-    void setUp() {
-        setupHeaders();
-        aaiModel = mock(AaiModel.class);
-        aaiConfigurationMock = mock(AaiClientConfiguration.class);
-
-        when(aaiConfigurationMock.aaiHost()).thenReturn("54.45.33.2");
-        when(aaiConfigurationMock.aaiProtocol()).thenReturn("https");
-        when(aaiConfigurationMock.aaiPort()).thenReturn(1234);
-        when(aaiConfigurationMock.aaiUserName()).thenReturn("PRH");
-        when(aaiConfigurationMock.aaiUserPassword()).thenReturn("PRH");
-        when(aaiConfigurationMock.aaiBasePath()).thenReturn("/aai/v11");
-        when(aaiConfigurationMock.aaiPnfPath()).thenReturn("/network/pnfs/pnf");
-        when(aaiConfigurationMock.aaiHeaders()).thenReturn(aaiHeaders);
-
-        when(aaiModel.getCorrelationId()).thenReturn("NOKnhfsadhff");
-
-
-    }
-
-
-    private void setupHeaders() {
-        aaiHeaders = new HashMap<>();
-        aaiHeaders.put("X-FromAppId", "PRH");
-        aaiHeaders.put("X-TransactionId", "vv-temp");
-        aaiHeaders.put("Accept", "application/json");
-        aaiHeaders.put("Real-Time", "true");
-        aaiHeaders.put("Content-Type", "application/json");
-    }
-
-    private void mockHttpClientObject() {
-        //when(HttpClient.create().)
-    }
-
-}
\ No newline at end of file
diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiReactiveHttpPatchClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiReactiveHttpPatchClientTest.java
deleted file mode 100644 (file)
index 7e34256..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * ============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.aai.client.service.http.patch;
-
-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.aai.client.config.AaiClientConfiguration;
-
-import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel;
-import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
-import org.springframework.web.reactive.function.client.ClientResponse;
-import org.springframework.web.reactive.function.client.WebClient;
-import reactor.core.publisher.Mono;
-import reactor.test.StepVerifier;
-
-import java.net.URI;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication;
-
-
-class AaiReactiveHttpPatchClientTest {
-    private static final Integer SUCCESS_RESPONSE = 200;
-    private static AaiClientConfiguration aaiConfigurationMock = mock(AaiClientConfiguration.class);
-
-
-    private AaiReactiveHttpPatchClient httpClient;
-    private WebClient webClient;
-    private WebClient.RequestBodyUriSpec requestBodyUriSpec;
-    private WebClient.ResponseSpec responseSpec;
-
-    private Map<String, String> aaiHeaders;
-    private ClientResponse clientResponse;
-    private Mono<ClientResponse> clientResponseMono;
-
-    private AaiModel aaiModel = mock(AaiModel.class);
-    private JsonBodyBuilder<AaiModel> jsonBodyBuilder = mock(JsonBodyBuilder.class);
-
-    @BeforeEach
-    void setUp() {
-        setupHeaders();
-        clientResponse = mock(ClientResponse.class);
-        clientResponseMono = Mono.just(clientResponse);
-
-        when(aaiConfigurationMock.aaiHost()).thenReturn("54.45.33.2");
-        when(aaiConfigurationMock.aaiProtocol()).thenReturn("https");
-        when(aaiConfigurationMock.aaiPort()).thenReturn(1234);
-        when(aaiConfigurationMock.aaiUserName()).thenReturn("PRH");
-        when(aaiConfigurationMock.aaiUserPassword()).thenReturn("PRH");
-        when(aaiConfigurationMock.aaiBasePath()).thenReturn("/aai/v11");
-        when(aaiConfigurationMock.aaiPnfPath()).thenReturn("/network/pnfs/pnf");
-        when(aaiConfigurationMock.aaiHeaders()).thenReturn(aaiHeaders);
-
-        when(aaiModel.getCorrelationId()).thenReturn("NOKnhfsadhff");
-
-        when(jsonBodyBuilder.createJsonBody(aaiModel)).thenReturn(
-                "{\"correlationId\":\"NOKnhfsadhff\"," +
-                "\"ipaddress-v4\":\"256.22.33.155\", " +
-                "\"ipaddress-v6\":\"200J:0db8:85a3:0000:0000:8a2e:0370:7334\"}");
-
-        httpClient = new AaiReactiveHttpPatchClient(aaiConfigurationMock, jsonBodyBuilder);
-
-        webClient = spy(WebClient.builder()
-                .defaultHeaders(httpHeaders -> httpHeaders.setAll(aaiHeaders))
-                .filter(basicAuthentication(aaiConfigurationMock.aaiUserName(), aaiConfigurationMock.aaiUserPassword()))
-                .build());
-
-        requestBodyUriSpec = mock(WebClient.RequestBodyUriSpec.class);
-        responseSpec = mock(WebClient.ResponseSpec.class);
-    }
-
-    @Test
-    void getAaiProducerResponse_shouldReturn200() {
-        //given
-        Mono<Integer> expectedResult = Mono.just(SUCCESS_RESPONSE);
-
-        //when
-        mockWebClientDependantObject();
-        doReturn(expectedResult).when(responseSpec).bodyToMono(Integer.class);
-        httpClient.createAaiWebClient(webClient);
-
-        //then
-        StepVerifier.create(httpClient.getAaiProducerResponse(aaiModel)).expectSubscription()
-                .expectNextMatches(results -> {
-                    Assertions.assertEquals(results, clientResponse);
-                    return true;
-                }).verifyComplete();
-    }
-
-
-    @Test
-    void getAppropriateUri_whenPassingCorrectedPathForPnf() {
-        Assertions.assertEquals(httpClient.getUri("NOKnhfsadhff"),
-                URI.create("https://54.45.33.2:1234/aai/v11/network/pnfs/pnf/NOKnhfsadhff"));
-    }
-
-
-    private void setupHeaders() {
-        aaiHeaders = new HashMap<>();
-        aaiHeaders.put("X-FromAppId", "PRH");
-        aaiHeaders.put("X-TransactionId", "vv-temp");
-        aaiHeaders.put("Accept", "application/json");
-        aaiHeaders.put("Real-Time", "true");
-        aaiHeaders.put("Content-Type", "application/merge-patch+json");
-    }
-
-    private void mockWebClientDependantObject() {
-        WebClient.RequestHeadersSpec requestHeadersSpec = mock(WebClient.RequestHeadersSpec.class);
-        when(webClient.patch()).thenReturn(requestBodyUriSpec);
-        when(requestBodyUriSpec.uri((URI) any())).thenReturn(requestBodyUriSpec);
-        when(requestBodyUriSpec.header(any(), any())).thenReturn(requestBodyUriSpec);
-        when(requestBodyUriSpec.body(any(), (Class<Object>) any())).thenReturn(requestHeadersSpec);
-        when(requestHeadersSpec.exchange()).thenReturn(clientResponseMono);
-    }
-}
\ No newline at end of file
diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiReactiveHttpPutClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiReactiveHttpPutClientTest.java
deleted file mode 100644 (file)
index 3b69449..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * ============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.aai.client.service.http.put;
-
-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.aai.client.config.AaiClientConfiguration;
-
-import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel;
-import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
-import org.springframework.web.reactive.function.client.ClientResponse;
-import org.springframework.web.reactive.function.client.WebClient;
-import reactor.core.publisher.Mono;
-import reactor.test.StepVerifier;
-
-import java.net.URI;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication;
-
-
-class AaiReactiveHttpPutClientTest {
-    private static final Integer SUCCESS_RESPONSE = 200;
-    private static AaiClientConfiguration aaiConfigurationMock = mock(AaiClientConfiguration.class);
-
-
-    private AaiReactiveHttpPutClient httpClient;
-    private WebClient webClient;
-    private WebClient.RequestBodyUriSpec requestBodyUriSpec;
-    private WebClient.ResponseSpec responseSpec;
-
-    private Map<String, String> aaiHeaders;
-    private ClientResponse clientResponse;
-    private Mono<ClientResponse> clientResponseMono;
-
-    private AaiModel aaiModel = mock(AaiModel.class);
-    private JsonBodyBuilder<AaiModel> jsonBodyBuilder = mock(JsonBodyBuilder.class);
-
-    @BeforeEach
-    void setUp() {
-        setupHeaders();
-        clientResponse = mock(ClientResponse.class);
-        clientResponseMono = Mono.just(clientResponse);
-
-        when(aaiConfigurationMock.aaiHost()).thenReturn("54.45.33.2");
-        when(aaiConfigurationMock.aaiProtocol()).thenReturn("https");
-        when(aaiConfigurationMock.aaiPort()).thenReturn(1234);
-        when(aaiConfigurationMock.aaiUserName()).thenReturn("PRH");
-        when(aaiConfigurationMock.aaiUserPassword()).thenReturn("PRH");
-        when(aaiConfigurationMock.aaiBasePath()).thenReturn("/aai/v11");
-        when(aaiConfigurationMock.aaiPnfPath()).thenReturn("/network/pnfs/pnf");
-        when(aaiConfigurationMock.aaiHeaders()).thenReturn(aaiHeaders);
-
-        when(aaiModel.getCorrelationId()).thenReturn("NOKnhfsadhff");
-
-        when(jsonBodyBuilder.createJsonBody(aaiModel)).thenReturn(
-                "{\"correlationId\":\"NOKnhfsadhff\"," +
-                        "\"ipaddress-v4\":\"256.22.33.155\", " +
-                        "\"ipaddress-v6\":\"200J:0db8:85a3:0000:0000:8a2e:0370:7334\"}");
-
-        httpClient = new AaiReactiveHttpPutClient(aaiConfigurationMock, jsonBodyBuilder);
-
-        webClient = spy(WebClient.builder()
-                .defaultHeaders(httpHeaders -> httpHeaders.setAll(aaiHeaders))
-                .filter(basicAuthentication(aaiConfigurationMock.aaiUserName(), aaiConfigurationMock.aaiUserPassword()))
-                .build());
-
-        requestBodyUriSpec = mock(WebClient.RequestBodyUriSpec.class);
-        responseSpec = mock(WebClient.ResponseSpec.class);
-    }
-
-    @Test
-    void getAaiProducerResponse_shouldReturn200() {
-        //given
-        Mono<Integer> expectedResult = Mono.just(SUCCESS_RESPONSE);
-
-        //when
-        mockWebClientDependantObject();
-        doReturn(expectedResult).when(responseSpec).bodyToMono(Integer.class);
-        httpClient.createAaiWebClient(webClient);
-
-        //then
-        StepVerifier.create(httpClient.getAaiProducerResponse(aaiModel)).expectSubscription()
-                .expectNextMatches(results -> {
-                    Assertions.assertEquals(results, clientResponse);
-                    return true;
-                }).verifyComplete();
-    }
-
-
-    @Test
-    void getAppropriateUri_whenPassingCorrectedPathForPnf() {
-        Assertions.assertEquals(httpClient.getUri("NOKnhfsadhff"),
-                URI.create("https://54.45.33.2:1234/aai/v11/network/pnfs/pnf/NOKnhfsadhff"));
-    }
-
-
-    private void setupHeaders() {
-        aaiHeaders = new HashMap<>();
-        aaiHeaders.put("X-FromAppId", "PRH");
-        aaiHeaders.put("X-TransactionId", "vv-temp");
-        aaiHeaders.put("Accept", "application/json");
-        aaiHeaders.put("Real-Time", "true");
-        aaiHeaders.put("Content-Type", "application/json");
-    }
-
-    private void mockWebClientDependantObject() {
-        WebClient.RequestHeadersSpec requestHeadersSpec = mock(WebClient.RequestHeadersSpec.class);
-        when(webClient.put()).thenReturn(requestBodyUriSpec);
-        when(requestBodyUriSpec.uri((URI) any())).thenReturn(requestBodyUriSpec);
-        when(requestBodyUriSpec.header(any(), any())).thenReturn(requestBodyUriSpec);
-        when(requestBodyUriSpec.body(any(), (Class<Object>) any())).thenReturn(requestHeadersSpec);
-        when(requestHeadersSpec.exchange()).thenReturn(clientResponseMono);
-    }
-}
\ No newline at end of file