aboutsummaryrefslogtreecommitdiffstats
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.java79
1 files changed, 40 insertions, 39 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 32e66386..0077a6a6 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
@@ -20,34 +20,28 @@
package org.onap.dcaegen2.services.prh.tasks;
-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.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
-
-
-import javax.net.ssl.SSLException;
+import com.google.gson.JsonObject;
+import io.netty.handler.codec.http.HttpResponseStatus;
import org.junit.jupiter.api.Assertions;
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.TestAppConfiguration;
-import org.onap.dcaegen2.services.prh.configuration.AppConfig;
+import org.onap.dcaegen2.services.prh.configuration.CbsConfiguration;
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.sdk.rest.services.aai.client.config.AaiClientConfiguration;
-import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.patch.AaiReactiveHttpPatchClient;
-
-import org.springframework.http.HttpStatus;
-import org.springframework.web.reactive.function.client.ClientResponse;
+import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.patch.AaiHttpPatchClient;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
+import javax.net.ssl.SSLException;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/14/18
*/
@@ -56,26 +50,35 @@ class AaiProducerTaskImplTest {
private ConsumerDmaapModel consumerDmaapModel;
private AaiProducerTaskImpl aaiProducerTask;
private AaiClientConfiguration aaiClientConfiguration;
- private AaiReactiveHttpPatchClient aaiReactiveHttpPatchClient;
- private AppConfig appConfig;
- private ClientResponse clientResponse;
+ private AaiHttpPatchClient aaiReactiveHttpPatchClient;
+ private CbsConfiguration cbsConfiguration;
+ private HttpResponse clientResponse;
@BeforeEach
void setUp() {
- clientResponse = mock(ClientResponse.class);
+ clientResponse = mock(HttpResponse.class);
aaiClientConfiguration = TestAppConfiguration.createDefaultAaiClientConfiguration();
- consumerDmaapModel = ImmutableConsumerDmaapModel.builder().ipv4("10.16.123.234")
- .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
- .correlationId("NOKQTFCOC540002E").build();
- appConfig = mock(AppConfig.class);
+ consumerDmaapModel = ImmutableConsumerDmaapModel.builder()
+ .ipv4("10.16.123.234")
+ .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
+ .correlationId("NOKQTFCOC540002E")
+ .serialNumber("QTFCOC540002E")
+ .equipVendor("nokia")
+ .equipModel("3310")
+ .equipType("type")
+ .nfRole("role")
+ .swVersion("v4.5.0.1")
+ .additionalFields(new JsonObject())
+ .build();
+ cbsConfiguration = mock(CbsConfiguration.class);
}
@Test
void whenPassedObjectDoesntFit_ThrowsPrhTaskException() {
//given/when/
- when(appConfig.getAaiClientConfiguration()).thenReturn(aaiClientConfiguration);
- aaiProducerTask = new AaiProducerTaskImpl(appConfig);
+ when(cbsConfiguration.getAaiClientConfiguration()).thenReturn(aaiClientConfiguration);
+ aaiProducerTask = new AaiProducerTaskImpl(aaiReactiveHttpPatchClient);
Executable executableCode = () -> aaiProducerTask.execute(null);
//then
@@ -86,11 +89,11 @@ class AaiProducerTaskImplTest {
@Test
void whenPassedObjectFits_ReturnsCorrectStatus() throws PrhTaskException, SSLException {
//given/when
- getAaiProducerTask_whenMockingResponseObject(200);
+ getAaiProducerTask_whenMockingResponseObject(HttpResponseStatus.OK);
Mono<ConsumerDmaapModel> response = aaiProducerTask.execute(consumerDmaapModel);
//then
- verify(aaiReactiveHttpPatchClient, times(1)).getAaiProducerResponse(any());
+ verify(aaiReactiveHttpPatchClient, times(1)).getAaiResponse(any());
verifyNoMoreInteractions(aaiReactiveHttpPatchClient);
Assertions.assertEquals(consumerDmaapModel, response.block());
@@ -99,24 +102,22 @@ class AaiProducerTaskImplTest {
@Test
void whenPassedObjectFits_butIncorrectResponseReturns() throws PrhTaskException, SSLException {
//given/when
- getAaiProducerTask_whenMockingResponseObject(400);
+ getAaiProducerTask_whenMockingResponseObject(HttpResponseStatus.BAD_REQUEST);
StepVerifier.create(aaiProducerTask.execute(consumerDmaapModel)).expectSubscription()
.expectError(PrhTaskException.class).verify();
//then
- verify(aaiReactiveHttpPatchClient, times(1)).getAaiProducerResponse(any());
+ verify(aaiReactiveHttpPatchClient, times(1)).getAaiResponse(any());
verifyNoMoreInteractions(aaiReactiveHttpPatchClient);
}
- private void getAaiProducerTask_whenMockingResponseObject(int statusCode) throws SSLException {
+ private void getAaiProducerTask_whenMockingResponseObject(HttpResponseStatus httpResponseStatus) throws SSLException {
//given
- doReturn(HttpStatus.valueOf(statusCode)).when(clientResponse).statusCode();
- Mono<ClientResponse> clientResponseMono = Mono.just(clientResponse);
- aaiReactiveHttpPatchClient = mock(AaiReactiveHttpPatchClient.class);
- when(aaiReactiveHttpPatchClient.getAaiProducerResponse(any()))
+ doReturn(httpResponseStatus.code()).when(clientResponse).statusCode();
+ Mono<HttpResponse> clientResponseMono = Mono.just(clientResponse);
+ aaiReactiveHttpPatchClient = mock(AaiHttpPatchClient.class);
+ when(aaiReactiveHttpPatchClient.getAaiResponse(any()))
.thenReturn(clientResponseMono);
- when(appConfig.getAaiClientConfiguration()).thenReturn(aaiClientConfiguration);
- aaiProducerTask = spy(new AaiProducerTaskImpl(appConfig));
- when(aaiProducerTask.resolveConfiguration()).thenReturn(aaiClientConfiguration);
- doReturn(aaiReactiveHttpPatchClient).when(aaiProducerTask).resolveClient();
+ when(cbsConfiguration.getAaiClientConfiguration()).thenReturn(aaiClientConfiguration);
+ aaiProducerTask = spy(new AaiProducerTaskImpl(aaiReactiveHttpPatchClient));
}
} \ No newline at end of file