*/
package org.onap.dcaegen2.services.prh.tasks;
-import java.util.Optional;
+import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
+import org.onap.dcaegen2.services.prh.service.DMaaPReactiveWebClient;
import org.onap.dcaegen2.services.prh.service.consumer.DMaaPConsumerReactiveHttpClient;
+import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
/**
abstract void initConfigs();
+ protected abstract DmaapConsumerConfiguration resolveConfiguration();
+
protected abstract Mono<ConsumerDmaapModel> execute(String object) throws PrhTaskException;
+
+ WebClient buildWebClient() {
+ DmaapConsumerConfiguration dmaapConsumerConfiguration = resolveConfiguration();
+ return new DMaaPReactiveWebClient.WebClientBuilder()
+ .dmaapContentType(dmaapConsumerConfiguration.dmaapContentType())
+ .dmaapUserName(dmaapConsumerConfiguration.dmaapUserName())
+ .dmaapUserPassword(dmaapConsumerConfiguration.dmaapUserPassword()).build();
+ }
}
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
import org.onap.dcaegen2.services.prh.configuration.Config;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.services.prh.service.DMaaPReactiveWebClient;
import org.onap.dcaegen2.services.prh.service.DmaapConsumerJsonParser;
import org.onap.dcaegen2.services.prh.service.consumer.DMaaPConsumerReactiveHttpClient;
import org.slf4j.Logger;
prhAppConfig.initFileStreamReader();
}
+ @Override
protected DmaapConsumerConfiguration resolveConfiguration() {
return prhAppConfig.getDmaapConsumerConfiguration();
}
@Override
DMaaPConsumerReactiveHttpClient resolveClient() {
-
return Optional.ofNullable(dMaaPConsumerReactiveHttpClient)
- .orElseGet(() -> {
- DmaapConsumerConfiguration dmaapConsumerConfiguration = resolveConfiguration();
- return new DMaaPConsumerReactiveHttpClient(dmaapConsumerConfiguration).createDMaaPWebClient(
- new DMaaPReactiveWebClient.WebClientBuilder()
- .dmaapContentType(dmaapConsumerConfiguration.dmaapContentType())
- .dmaapUserName(dmaapConsumerConfiguration.dmaapUserName())
- .dmaapUserPassword(dmaapConsumerConfiguration.dmaapUserPassword()).build());
- });
+ .orElseGet(() -> new DMaaPConsumerReactiveHttpClient(resolveConfiguration()).createDMaaPWebClient(
+ buildWebClient()));
}
}
*/
package org.onap.dcaegen2.services.prh.tasks;
+import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration;
import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
+import org.onap.dcaegen2.services.prh.service.DMaaPReactiveWebClient;
import org.onap.dcaegen2.services.prh.service.producer.DMaaPProducerReactiveHttpClient;
+import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
/**
abstract DMaaPProducerReactiveHttpClient resolveClient();
+ protected abstract DmaapPublisherConfiguration resolveConfiguration();
+
protected abstract Mono<Integer> execute(Mono<ConsumerDmaapModel> consumerDmaapModel) throws PrhTaskException;
+
+ WebClient buildWebClient() {
+ DmaapPublisherConfiguration dmaapPublisherConfiguration = resolveConfiguration();
+ return new DMaaPReactiveWebClient.WebClientBuilder()
+ .dmaapContentType(dmaapPublisherConfiguration.dmaapContentType())
+ .dmaapUserName(dmaapPublisherConfiguration.dmaapUserName())
+ .dmaapUserPassword(dmaapPublisherConfiguration.dmaapUserPassword()).build();
+ }
}
import org.onap.dcaegen2.services.prh.configuration.Config;
import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.services.prh.service.DMaaPReactiveWebClient;
import org.onap.dcaegen2.services.prh.service.producer.DMaaPProducerReactiveHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
return publish(consumerDmaapModel);
}
+ @Override
protected DmaapPublisherConfiguration resolveConfiguration() {
return prhAppConfig.getDmaapPublisherConfiguration();
}
@Override
DMaaPProducerReactiveHttpClient resolveClient() {
return Optional.ofNullable(dMaaPProducerReactiveHttpClient)
- .orElseGet(() -> {
- DmaapPublisherConfiguration dmaapPublisherConfiguration = resolveConfiguration();
- return new DMaaPProducerReactiveHttpClient(dmaapPublisherConfiguration).createDMaaPWebClient(
- new DMaaPReactiveWebClient.WebClientBuilder()
- .dmaapContentType(dmaapPublisherConfiguration.dmaapContentType())
- .dmaapUserName(dmaapPublisherConfiguration.dmaapUserName())
- .dmaapUserPassword(dmaapPublisherConfiguration.dmaapUserPassword()).build());
- });
+ .orElseGet(() -> new DMaaPProducerReactiveHttpClient(resolveConfiguration())
+ .createDMaaPWebClient(buildWebClient()));
}
}
\ No newline at end of file
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * 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.prh.service;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.springframework.web.reactive.function.client.WebClient;
+
+/**
+ * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 7/5/18
+ */
+public class DMaaPReactiveWebClientTest {
+
+ @Test
+ public void builder_shouldBuildDMaaPReactiveWebClient() {
+ //given
+ WebClient dMaaPReactiveWebClient;
+ String dMaaPContentType = "*/*";
+ String dMaaPUserName = "DMaaP";
+ String dMaaPUserPassword = "DMaaP";
+
+ //when
+ dMaaPReactiveWebClient = new DMaaPReactiveWebClient.WebClientBuilder()
+ .dmaapContentType(dMaaPContentType)
+ .dmaapUserName(dMaaPUserName)
+ .dmaapUserPassword(dMaaPUserPassword).build();
+
+ //then
+ Assertions.assertNotNull(dMaaPReactiveWebClient);
+
+ }
+}
\ No newline at end of file
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
DmaapPublisherConfiguration.class);
private static final Integer RESPONSE_SUCCESS = 200;
private static ConsumerDmaapModel consumerDmaapModel = new ConsumerDmaapModelForUnitTest();
- private static Mono<Integer> expectedResult = Mono.empty();
private static WebClient webClient = mock(WebClient.class);
private static RequestBodyUriSpec requestBodyUriSpec;
private static ResponseSpec responseSpec;
@Test
public void getHttpResponse_Success() {
//given
- expectedResult = Mono.just(RESPONSE_SUCCESS);
+ Mono<Integer> expectedResult = Mono.just(RESPONSE_SUCCESS);
//when
mockWebClientDependantObject();