summaryrefslogtreecommitdiffstats
path: root/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImplTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImplTest.java')
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImplTest.java53
1 files changed, 30 insertions, 23 deletions
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImplTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImplTest.java
index 54259397..f5cc6b24 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImplTest.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImplTest.java
@@ -29,8 +29,9 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
+import javax.net.ssl.SSLException;
import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
@@ -40,6 +41,8 @@ import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.service.producer.AaiProducerReactiveHttpClient;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.reactive.function.client.ClientResponse;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -56,14 +59,16 @@ class AaiProducerTaskImplTest {
private static final String BASE_PATH = "/aai/v11";
private static final String PNF_PATH = "/network/pnfs/pnf";
- private static ConsumerDmaapModel consumerDmaapModel;
- private static AaiProducerTaskImpl aaiProducerTask;
- private static AaiClientConfiguration aaiClientConfiguration;
- private static AaiProducerReactiveHttpClient aaiProducerReactiveHttpClient;
- private static AppConfig appConfig;
+ private ConsumerDmaapModel consumerDmaapModel;
+ private AaiProducerTaskImpl aaiProducerTask;
+ private AaiClientConfiguration aaiClientConfiguration;
+ private AaiProducerReactiveHttpClient aaiProducerReactiveHttpClient;
+ private AppConfig appConfig;
+ private ClientResponse clientResponse;
- @BeforeAll
- static void setUp() {
+ @BeforeEach
+ void setUp() {
+ clientResponse = mock(ClientResponse.class);
aaiClientConfiguration = new ImmutableAaiClientConfiguration.Builder()
.aaiHost(AAI_HOST)
.aaiPort(PORT)
@@ -81,17 +86,6 @@ class AaiProducerTaskImplTest {
}
- private static void getAaiProducerTask_whenMockingResponseObject(Integer statusCode) {
- //given
- aaiProducerReactiveHttpClient = mock(AaiProducerReactiveHttpClient.class);
- when(aaiProducerReactiveHttpClient.getAaiProducerResponse(any()))
- .thenReturn(Mono.just(statusCode));
- when(appConfig.getAaiClientConfiguration()).thenReturn(aaiClientConfiguration);
- aaiProducerTask = spy(new AaiProducerTaskImpl(appConfig));
- when(aaiProducerTask.resolveConfiguration()).thenReturn(aaiClientConfiguration);
- doReturn(aaiProducerReactiveHttpClient).when(aaiProducerTask).resolveClient();
- }
-
@Test
void whenPassedObjectDoesntFit_ThrowsPrhTaskException() {
//given/when/
@@ -105,10 +99,10 @@ class AaiProducerTaskImplTest {
}
@Test
- void whenPassedObjectFits_ReturnsCorrectStatus() throws PrhTaskException {
+ void whenPassedObjectFits_ReturnsCorrectStatus() throws PrhTaskException, SSLException {
//given/when
getAaiProducerTask_whenMockingResponseObject(200);
- Mono<ConsumerDmaapModel> response = aaiProducerTask.execute(Mono.just(consumerDmaapModel));
+ Mono<ConsumerDmaapModel> response = aaiProducerTask.execute(consumerDmaapModel);
//then
verify(aaiProducerReactiveHttpClient, times(1)).getAaiProducerResponse(any());
@@ -118,13 +112,26 @@ class AaiProducerTaskImplTest {
}
@Test
- void whenPassedObjectFits_butIncorrectResponseReturns() throws PrhTaskException {
+ void whenPassedObjectFits_butIncorrectResponseReturns() throws PrhTaskException, SSLException {
//given/when
getAaiProducerTask_whenMockingResponseObject(400);
- StepVerifier.create(aaiProducerTask.execute(Mono.just(consumerDmaapModel))).expectSubscription()
+ StepVerifier.create(aaiProducerTask.execute(consumerDmaapModel)).expectSubscription()
.expectError(PrhTaskException.class).verify();
//then
verify(aaiProducerReactiveHttpClient, times(1)).getAaiProducerResponse(any());
verifyNoMoreInteractions(aaiProducerReactiveHttpClient);
}
+
+ private void getAaiProducerTask_whenMockingResponseObject(int statusCode) throws SSLException {
+ //given
+ doReturn(HttpStatus.valueOf(statusCode)).when(clientResponse).statusCode();
+ Mono<ClientResponse> clientResponseMono = Mono.just(clientResponse);
+ aaiProducerReactiveHttpClient = mock(AaiProducerReactiveHttpClient.class);
+ when(aaiProducerReactiveHttpClient.getAaiProducerResponse(any()))
+ .thenReturn(clientResponseMono);
+ when(appConfig.getAaiClientConfiguration()).thenReturn(aaiClientConfiguration);
+ aaiProducerTask = spy(new AaiProducerTaskImpl(appConfig));
+ when(aaiProducerTask.resolveConfiguration()).thenReturn(aaiClientConfiguration);
+ doReturn(aaiProducerReactiveHttpClient).when(aaiProducerTask).resolveClient();
+ }
} \ No newline at end of file