diff options
Diffstat (limited to 'datafile-dmaap-client/src')
11 files changed, 10 insertions, 482 deletions
diff --git a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/config/DmaapConsumerConfiguration.java b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/config/DmaapConsumerConfiguration.java deleted file mode 100644 index 568d4ecc..00000000 --- a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/config/DmaapConsumerConfiguration.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * ============LICENSE_START====================================================================== - * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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.collectors.datafile.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 -public abstract class DmaapConsumerConfiguration implements DmaapCustomConfig { - - private static final long serialVersionUID = 1L; - - @Value.Parameter - public abstract String consumerId(); - - @Value.Parameter - public abstract String consumerGroup(); - - @Value.Parameter - public abstract Integer timeoutMS(); - - @Value.Parameter - public abstract Integer messageLimit(); -} diff --git a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/config/DmaapCustomConfig.java b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/config/DmaapCustomConfig.java deleted file mode 100644 index 0b1d99eb..00000000 --- a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/config/DmaapCustomConfig.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * ============LICENSE_START====================================================================== - * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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.collectors.datafile.config; - -import java.io.Serializable; - -import org.immutables.value.Value; - -/** - * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/28/18 - */ -public interface DmaapCustomConfig extends Serializable { - - @Value.Parameter - String dmaapHostName(); - - @Value.Parameter - Integer dmaapPortNumber(); - - @Value.Parameter - String dmaapTopicName(); - - @Value.Parameter - String dmaapProtocol(); - - @Value.Parameter - String dmaapUserName(); - - @Value.Parameter - String dmaapUserPassword(); - - @Value.Parameter - String dmaapContentType(); - - - interface Builder<T extends DmaapCustomConfig, B extends Builder<T, B>> { - - B dmaapHostName(String dmaapHostName); - - B dmaapPortNumber(Integer dmaapPortNumber); - - B dmaapTopicName(String dmaapTopicName); - - B dmaapProtocol(String dmaapProtocol); - - B dmaapUserName(String dmaapUserName); - - B dmaapUserPassword(String dmaapUserPassword); - - B dmaapContentType(String dmaapContentType); - - T build(); - } -} diff --git a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/config/DmaapPublisherConfiguration.java b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/config/DmaapPublisherConfiguration.java deleted file mode 100644 index 06d20f73..00000000 --- a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/config/DmaapPublisherConfiguration.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * ============LICENSE_START====================================================================== - * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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.collectors.datafile.config; - -import org.immutables.gson.Gson; -import org.immutables.value.Value; - -/** - * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18 - */ -@Value.Immutable(prehash = true) -@Value.Style(builder = "new") -@Gson.TypeAdapters -public abstract class DmaapPublisherConfiguration implements DmaapCustomConfig { - - private static final long serialVersionUID = 1L; -} diff --git a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapReactiveWebClient.java b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapReactiveWebClient.java index 7249c083..2e9c8488 100644 --- a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapReactiveWebClient.java +++ b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapReactiveWebClient.java @@ -18,7 +18,7 @@ package org.onap.dcaegen2.collectors.datafile.service; import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication; -import org.onap.dcaegen2.collectors.datafile.config.DmaapCustomConfig; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapCustomConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpHeaders; diff --git a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/consumer/DmaapConsumerReactiveHttpClient.java b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/consumer/DmaapConsumerReactiveHttpClient.java deleted file mode 100644 index c4bf1611..00000000 --- a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/consumer/DmaapConsumerReactiveHttpClient.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * ============LICENSE_START====================================================================== - * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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.collectors.datafile.service.consumer; - -import java.net.URI; -import java.util.function.Consumer; - -import org.onap.dcaegen2.collectors.datafile.config.DmaapConsumerConfiguration; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.web.reactive.function.client.WebClient; -import org.springframework.web.util.DefaultUriBuilderFactory; - -import reactor.core.publisher.Mono; - -/** - * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 6/26/18 - * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a> - */ -public class DmaapConsumerReactiveHttpClient { - - private WebClient webClient; - 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; - - /** - * Constructor of DmaapConsumerReactiveHttpClient. - * - * @param consumerConfiguration - DMaaP consumer configuration object - */ - public DmaapConsumerReactiveHttpClient(DmaapConsumerConfiguration consumerConfiguration) { - 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(); - } - - /** - * Function for calling DMaaP HTTP consumer - consuming messages from Kafka/DMaaP from topic. - * - * @return reactive response from DMaaP in string format - */ - public Mono<String> getDmaapConsumerResponse() { - return webClient.get().uri(getUri()).headers(getHeaders()).retrieve() - .onStatus(HttpStatus::is4xxClientError, clientResponse -> Mono.error(new Exception("HTTP 400"))) - .onStatus(HttpStatus::is5xxServerError, clientResponse -> Mono.error(new Exception("HTTP 500"))) - .bodyToMono(String.class); - } - - private Consumer<HttpHeaders> getHeaders() { - return httpHeaders -> httpHeaders.set(HttpHeaders.CONTENT_TYPE, contentType); - } - - private String createRequestPath() { - return dmaapTopicName + "/" + consumerGroup + "/" + consumerId; - } - - public DmaapConsumerReactiveHttpClient createDmaapWebClient(WebClient webClient) { - this.webClient = webClient; - return this; - } - - URI getUri() { - return new DefaultUriBuilderFactory().builder().scheme(dmaapProtocol).host(dmaapHostName).port(dmaapPortNumber) - .path(createRequestPath()).build(); - } -} diff --git a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerReactiveHttpClient.java b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerReactiveHttpClient.java index 0e95b0b0..a4b37c58 100644 --- a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerReactiveHttpClient.java +++ b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerReactiveHttpClient.java @@ -36,13 +36,14 @@ import org.apache.http.entity.ByteArrayEntity; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.apache.http.impl.nio.client.HttpAsyncClients; import org.apache.http.ssl.SSLContextBuilder; -import org.onap.dcaegen2.collectors.datafile.config.DmaapPublisherConfiguration; + import org.onap.dcaegen2.collectors.datafile.io.FileSystemResourceWrapper; import org.onap.dcaegen2.collectors.datafile.io.IFileSystemResource; import org.onap.dcaegen2.collectors.datafile.model.CommonFunctions; import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel; import org.onap.dcaegen2.collectors.datafile.service.HttpUtils; import org.onap.dcaegen2.collectors.datafile.web.PublishRedirectStrategy; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpHeaders; @@ -141,7 +142,7 @@ public class DmaapProducerReactiveHttpClient { private void prepareHead(ConsumerDmaapModel model, HttpPut put) { put.addHeader(HttpHeaders.CONTENT_TYPE, dmaapContentType); - JsonElement metaData = new JsonParser().parse(CommonFunctions.createJsonBody(model)); + JsonElement metaData = new JsonParser().parse(new CommonFunctions().createJsonBody(model)); String name = metaData.getAsJsonObject().remove(NAME_JSON_TAG).getAsString(); metaData.getAsJsonObject().remove(INTERNAL_LOCATION_JSON_TAG); put.addHeader(X_ATT_DR_META, metaData.toString()); diff --git a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapReactiveWebClientTest.java b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapReactiveWebClientTest.java index 2eac5899..128f78f5 100644 --- a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapReactiveWebClientTest.java +++ b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapReactiveWebClientTest.java @@ -25,7 +25,9 @@ import static org.mockito.Mockito.when; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; -import org.onap.dcaegen2.collectors.datafile.config.DmaapConsumerConfiguration; + + +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration; import org.springframework.web.reactive.function.client.WebClient; class DmaapReactiveWebClientTest { diff --git a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/config/DmaapConsumerConfigurationTest.java b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/config/DmaapConsumerConfigurationTest.java deleted file mode 100644 index b67946b2..00000000 --- a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/config/DmaapConsumerConfigurationTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * ============LICENSE_START====================================================================== - * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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.collectors.datafile.service.config; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.onap.dcaegen2.collectors.datafile.config.DmaapConsumerConfiguration; -import org.onap.dcaegen2.collectors.datafile.config.ImmutableDmaapConsumerConfiguration; - -public class DmaapConsumerConfigurationTest { - - @Test - public void builder_shouldBuildConfigurationObject() { - - // Given - DmaapConsumerConfiguration configuration; - String consumerId = "1"; - String dmaapHostName = "localhost"; - Integer dmaapPortNumber = 2222; - String dmaapTopicName = "temp"; - String dmaapProtocol = "http"; - String dmaapUserName = "admin"; - String dmaapUserPassword = "admin"; - String dmaapContentType = "application/json"; - String consumerGroup = "other"; - Integer timeoutMs = 1000; - Integer messageLimit = 1000; - - // When - configuration = new ImmutableDmaapConsumerConfiguration.Builder().consumerId(consumerId) - .dmaapHostName(dmaapHostName).dmaapPortNumber(dmaapPortNumber).dmaapTopicName(dmaapTopicName) - .dmaapProtocol(dmaapProtocol).dmaapUserName(dmaapUserName).dmaapUserPassword(dmaapUserPassword) - .dmaapContentType(dmaapContentType).consumerGroup(consumerGroup).timeoutMS(timeoutMs) - .messageLimit(messageLimit).build(); - - // Then - Assertions.assertNotNull(configuration); - Assertions.assertEquals(consumerId, configuration.consumerId()); - Assertions.assertEquals(dmaapHostName, configuration.dmaapHostName()); - Assertions.assertEquals(dmaapPortNumber, configuration.dmaapPortNumber()); - Assertions.assertEquals(dmaapTopicName, configuration.dmaapTopicName()); - Assertions.assertEquals(dmaapProtocol, configuration.dmaapProtocol()); - Assertions.assertEquals(dmaapUserName, configuration.dmaapUserName()); - Assertions.assertEquals(dmaapUserPassword, configuration.dmaapUserPassword()); - Assertions.assertEquals(consumerGroup, configuration.consumerGroup()); - Assertions.assertEquals(timeoutMs, configuration.timeoutMS()); - Assertions.assertEquals(messageLimit, configuration.messageLimit()); - } -} diff --git a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/config/DmaapPublisherConfigurationTest.java b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/config/DmaapPublisherConfigurationTest.java deleted file mode 100644 index fb8e8751..00000000 --- a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/config/DmaapPublisherConfigurationTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * ============LICENSE_START====================================================================== - * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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.collectors.datafile.service.config; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.onap.dcaegen2.collectors.datafile.config.DmaapPublisherConfiguration; -import org.onap.dcaegen2.collectors.datafile.config.ImmutableDmaapPublisherConfiguration; - -public class DmaapPublisherConfigurationTest { - - - @Test - public void builder_shouldBuildConfigurationObject() { - - // Given - DmaapPublisherConfiguration configuration; - String dmaapHostName = "localhost"; - Integer dmaapPortNumber = 2222; - String dmaapTopicName = "temp"; - String dmaapProtocol = "http"; - String dmaapUserName = "admin"; - String dmaapUserPassword = "admin"; - String dmaapContentType = "application/json"; - - // When - configuration = new ImmutableDmaapPublisherConfiguration.Builder().dmaapHostName(dmaapHostName) - .dmaapPortNumber(dmaapPortNumber).dmaapTopicName(dmaapTopicName).dmaapProtocol(dmaapProtocol) - .dmaapUserName(dmaapUserName).dmaapUserPassword(dmaapUserPassword).dmaapContentType(dmaapContentType) - .build(); - - // Then - Assertions.assertNotNull(configuration); - Assertions.assertEquals(dmaapHostName, configuration.dmaapHostName()); - Assertions.assertEquals(dmaapPortNumber, configuration.dmaapPortNumber()); - Assertions.assertEquals(dmaapTopicName, configuration.dmaapTopicName()); - Assertions.assertEquals(dmaapProtocol, configuration.dmaapProtocol()); - Assertions.assertEquals(dmaapUserName, configuration.dmaapUserName()); - Assertions.assertEquals(dmaapUserPassword, configuration.dmaapUserPassword()); - } -} diff --git a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/consumer/DmaapConsumerReactiveHttpClientTest.java b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/consumer/DmaapConsumerReactiveHttpClientTest.java deleted file mode 100644 index 4568bdde..00000000 --- a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/consumer/DmaapConsumerReactiveHttpClientTest.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * ============LICENSE_START====================================================================== - * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. 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.collectors.datafile.service.consumer; - -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; - -import java.net.URI; -import java.net.URISyntaxException; - -import org.apache.http.HttpHeaders; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.onap.dcaegen2.collectors.datafile.config.DmaapConsumerConfiguration; -import org.springframework.web.reactive.function.client.WebClient; -import org.springframework.web.reactive.function.client.WebClient.RequestHeadersUriSpec; -import org.springframework.web.reactive.function.client.WebClient.ResponseSpec; - -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; - -/** - * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 6/27/18 - */ -class DmaapConsumerReactiveHttpClientTest { - - private DmaapConsumerReactiveHttpClient dmaapConsumerReactiveHttpClient; - - private DmaapConsumerConfiguration consumerConfigurationMock = mock(DmaapConsumerConfiguration.class); - private static final String JSON_MESSAGE = "{ \"responseFromDmaap\": \"Success\"}"; - private Mono<String> expectedResult = Mono.empty(); - private WebClient webClient; - private RequestHeadersUriSpec requestHeadersSpecMock; - private ResponseSpec responseSpecMock; - - - @BeforeEach - void setUp() { - when(consumerConfigurationMock.dmaapHostName()).thenReturn("54.45.33.2"); - when(consumerConfigurationMock.dmaapProtocol()).thenReturn("https"); - when(consumerConfigurationMock.dmaapPortNumber()).thenReturn(1234); - when(consumerConfigurationMock.dmaapUserName()).thenReturn("DATAFILE"); - when(consumerConfigurationMock.dmaapUserPassword()).thenReturn("DATFILE"); - when(consumerConfigurationMock.dmaapContentType()).thenReturn("application/json"); - when(consumerConfigurationMock.dmaapTopicName()).thenReturn("unauthenticated.VES_NOTIFICATION_OUTPUT"); - when(consumerConfigurationMock.consumerGroup()).thenReturn("OpenDCAE-c12"); - when(consumerConfigurationMock.consumerId()).thenReturn("c12"); - - dmaapConsumerReactiveHttpClient = new DmaapConsumerReactiveHttpClient(consumerConfigurationMock); - webClient = spy(WebClient.builder() - .defaultHeader(HttpHeaders.CONTENT_TYPE, consumerConfigurationMock.dmaapContentType()) - .filter(basicAuthentication(consumerConfigurationMock.dmaapUserName(), - consumerConfigurationMock.dmaapUserPassword())) - .build()); - requestHeadersSpecMock = mock(RequestHeadersUriSpec.class); - responseSpecMock = mock(ResponseSpec.class); - } - - - @Test - void getHttpResponse_Success() { - //given - expectedResult = Mono.just(JSON_MESSAGE); - - //when - mockDependantObjects(); - doReturn(expectedResult).when(responseSpecMock).bodyToMono(String.class); - dmaapConsumerReactiveHttpClient.createDmaapWebClient(webClient); - - Mono<String> response = dmaapConsumerReactiveHttpClient.getDmaapConsumerResponse(); - - //then - StepVerifier.create(response).expectSubscription() - .expectNextMatches(results -> { - Assertions.assertEquals(results, expectedResult.block()); - return true; - }).verifyComplete(); - } - - @Test - void getAppropriateUri_whenPassingCorrectedUriData() throws URISyntaxException { - Assertions.assertEquals(dmaapConsumerReactiveHttpClient.getUri(), - URI.create("https://54.45.33.2:1234/unauthenticated.VES_NOTIFICATION_OUTPUT/OpenDCAE-c12/c12")); - } - - private void mockDependantObjects() { - when(webClient.get()).thenReturn(requestHeadersSpecMock); - when(requestHeadersSpecMock.uri((URI) any())).thenReturn(requestHeadersSpecMock); - when(requestHeadersSpecMock.headers(any())).thenReturn(requestHeadersSpecMock); - when(requestHeadersSpecMock.retrieve()).thenReturn(responseSpecMock); - doReturn(responseSpecMock).when(responseSpecMock).onStatus(any(), any()); - } - -}
\ No newline at end of file diff --git a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerReactiveHttpClientTest.java b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerReactiveHttpClientTest.java index bf2f73d6..3fbd57cc 100644 --- a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerReactiveHttpClientTest.java +++ b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerReactiveHttpClientTest.java @@ -41,12 +41,13 @@ import org.apache.http.entity.ByteArrayEntity; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.onap.dcaegen2.collectors.datafile.config.DmaapPublisherConfiguration; + import org.onap.dcaegen2.collectors.datafile.io.IFileSystemResource; import org.onap.dcaegen2.collectors.datafile.model.CommonFunctions; import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel; import org.onap.dcaegen2.collectors.datafile.model.ImmutableConsumerDmaapModel; import org.onap.dcaegen2.collectors.datafile.service.HttpUtils; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration; import org.springframework.http.HttpHeaders; import org.springframework.web.util.DefaultUriBuilderFactory; @@ -127,7 +128,7 @@ class DmaapProducerReactiveHttpClientTest { HttpPut httpPut = new HttpPut(); httpPut.addHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_OCTET_STREAM_CONTENT_TYPE); - JsonElement metaData = new JsonParser().parse(CommonFunctions.createJsonBody(consumerDmaapModel)); + JsonElement metaData = new JsonParser().parse(new CommonFunctions().createJsonBody(consumerDmaapModel)); metaData.getAsJsonObject().remove(NAME_JSON_TAG).getAsString(); metaData.getAsJsonObject().remove(INTERNAL_LOCATION_JSON_TAG); httpPut.addHeader(X_ATT_DR_META, metaData.toString()); |