aboutsummaryrefslogtreecommitdiffstats
path: root/datafile-dmaap-client/src/test/java/org
diff options
context:
space:
mode:
authorChengkai Yan <martin.c.yan@est.tech>2018-11-23 16:23:56 +0100
committerelinuxhenrik <henrik.b.andersson@est.tech>2018-12-03 13:20:42 +0100
commit693026c6b973c44ade969516be496f966e4fae86 (patch)
tree8398e3e98d79303d5d53c51eeccf3db018e2865b /datafile-dmaap-client/src/test/java/org
parenta3c452af58c12283d76019509dd605f67f14532c (diff)
fix bugs in jira DCAEGEN2-940 and DCAEGEN2-941
Change-Id: Id0b3e295cab0e085746b034caccbf82aca2e0d7b Signed-off-by: Chengkai Yan <martin.c.yan@est.tech> Issue-ID: DCAEGEN2-940 Issue-ID: DCAEGEN2-941
Diffstat (limited to 'datafile-dmaap-client/src/test/java/org')
-rw-r--r--datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectResultTest.java21
-rw-r--r--datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java108
-rw-r--r--datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerReactiveHttpClientTest.java59
-rw-r--r--datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/web/RequestResponseLoggingInterceptorTest.java55
-rw-r--r--datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/web/RestTemplateWrapperTest.java34
5 files changed, 142 insertions, 135 deletions
diff --git a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectResultTest.java b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectResultTest.java
index 083727e4..38d24233 100644
--- a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectResultTest.java
+++ b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectResultTest.java
@@ -2,17 +2,15 @@
* ============LICENSE_START======================================================================
* Copyright (C) 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
+ * 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
+ * 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.
+ * 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========================================================================
*/
@@ -30,7 +28,7 @@ public class FileCollectResultTest {
public void successfulResult() {
FileCollectResult resultUnderTest = new FileCollectResult();
assertTrue(resultUnderTest.downloadSuccessful());
- assertEquals("FileCollectResult: true Error data: ", resultUnderTest.toString());
+ assertEquals("FileCollectResult: successful!", resultUnderTest.toString());
}
@Test
@@ -40,6 +38,7 @@ public class FileCollectResultTest {
errorData.addError("Null", new NullPointerException());
FileCollectResult resultUnderTest = new FileCollectResult(errorData);
assertFalse(resultUnderTest.downloadSuccessful());
- assertEquals("FileCollectResult: false Error data: " + errorData.toString(), resultUnderTest.toString());
+ assertEquals("FileCollectResult: unsuccessful! Error data: " + errorData.toString(),
+ resultUnderTest.toString());
}
}
diff --git a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java
index 2157e176..c134b79c 100644
--- a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java
+++ b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java
@@ -36,6 +36,8 @@ import java.security.KeyStoreException;
import javax.net.ssl.KeyManager;
import javax.net.ssl.TrustManager;
+import org.apache.commons.net.ftp.FTP;
+import org.apache.commons.net.ftp.FTPReply;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.collectors.datafile.io.IFile;
@@ -88,7 +90,7 @@ public class FtpsClientTest {
clientUnderTest.setKeyCertPassword(FTP_KEY_PASSWORD);
clientUnderTest.setTrustedCAPath(TRUSTED_CA_PATH);
clientUnderTest.setTrustedCAPassword(TRUSTED_CA_PASSWORD);
-}
+ }
@Test
public void collectFile_allOk() throws Exception {
@@ -103,6 +105,7 @@ public class FtpsClientTest {
OutputStream osMock = mock(OutputStream.class);
when(outputStreamMock.getOutputStream(fileMock)).thenReturn(osMock);
when(ftpsClientMock.retrieveFile(REMOTE_FILE_PATH, osMock)).thenReturn(true);
+ when(ftpsClientMock.isConnected()).thenReturn(false, true);
ImmutableFileServerData fileServerData = ImmutableFileServerData.builder().serverAddress(XNF_ADDRESS)
.userId(USERNAME).password(PASSWORD).port(PORT).build();
@@ -124,19 +127,22 @@ public class FtpsClientTest {
verify(ftpsClientMock, times(1)).enterLocalPassiveMode();
verify(ftpsClientMock).execPBSZ(0);
verify(ftpsClientMock).execPROT("P");
+ verify(ftpsClientMock).setFileType(FTP.BINARY_FILE_TYPE);
+ verify(ftpsClientMock).setBufferSize(1024 * 1024);
verify(localFileMock).setPath(LOCAL_FILE_PATH);
verify(localFileMock, times(1)).createNewFile();
verify(ftpsClientMock).retrieveFile(REMOTE_FILE_PATH, osMock);
verify(osMock, times(1)).close();
verify(ftpsClientMock, times(1)).logout();
verify(ftpsClientMock, times(1)).disconnect();
+ verify(ftpsClientMock, times(2)).isConnected();
verifyNoMoreInteractions(ftpsClientMock);
}
@Test
public void collectFileFaultyOwnKey_shouldFail() throws Exception {
- doThrow(new IKeyManagerUtils.KeyManagerException(new GeneralSecurityException()))
- .when(keyManagerUtilsMock).setCredentials(FTP_KEY_PATH, FTP_KEY_PASSWORD);
+ doThrow(new IKeyManagerUtils.KeyManagerException(new GeneralSecurityException())).when(keyManagerUtilsMock)
+ .setCredentials(FTP_KEY_PATH, FTP_KEY_PASSWORD);
ImmutableFileServerData fileServerData = ImmutableFileServerData.builder().serverAddress(XNF_ADDRESS)
.userId(USERNAME).password(PASSWORD).port(PORT).build();
@@ -144,6 +150,10 @@ public class FtpsClientTest {
FileCollectResult result = clientUnderTest.collectFile(fileServerData, REMOTE_FILE_PATH, LOCAL_FILE_PATH);
assertFalse(result.downloadSuccessful());
+ verify(ftpsClientMock).setNeedClientAuth(true);
+ verify(keyManagerUtilsMock).setCredentials(FTP_KEY_PATH, FTP_KEY_PASSWORD);
+ verify(ftpsClientMock, times(1)).isConnected();
+ verifyNoMoreInteractions(ftpsClientMock);
}
@Test
@@ -160,6 +170,15 @@ public class FtpsClientTest {
FileCollectResult result = clientUnderTest.collectFile(fileServerData, REMOTE_FILE_PATH, LOCAL_FILE_PATH);
assertFalse(result.downloadSuccessful());
+ verify(ftpsClientMock).setNeedClientAuth(true);
+ verify(keyManagerUtilsMock).setCredentials(FTP_KEY_PATH, FTP_KEY_PASSWORD);
+ verify(ftpsClientMock).setKeyManager(keyManagerMock);
+ verify(fileResourceMock).setPath(TRUSTED_CA_PATH);
+ verify(keyStoreWrapperMock).load(inputStreamMock, TRUSTED_CA_PASSWORD.toCharArray());
+ verify(inputStreamMock, times(1)).close();
+ verify(trustManagerFactoryMock).init(keyStoreMock);
+ verify(ftpsClientMock, times(1)).isConnected();
+ verifyNoMoreInteractions(ftpsClientMock);
}
@Test
@@ -175,8 +194,19 @@ public class FtpsClientTest {
FileCollectResult result = clientUnderTest.collectFile(fileServerData, REMOTE_FILE_PATH, LOCAL_FILE_PATH);
- verify(ftpsClientMock, times(1)).logout();
assertFalse(result.downloadSuccessful());
+ verify(ftpsClientMock).setNeedClientAuth(true);
+ verify(keyManagerUtilsMock).setCredentials(FTP_KEY_PATH, FTP_KEY_PASSWORD);
+ verify(ftpsClientMock).setKeyManager(keyManagerMock);
+ verify(fileResourceMock).setPath(TRUSTED_CA_PATH);
+ verify(keyStoreWrapperMock).load(inputStreamMock, TRUSTED_CA_PASSWORD.toCharArray());
+ verify(inputStreamMock, times(1)).close();
+ verify(trustManagerFactoryMock).init(keyStoreMock);
+ verify(ftpsClientMock).setTrustManager(trustManagerMock);
+ verify(ftpsClientMock).connect(XNF_ADDRESS, PORT);
+ verify(ftpsClientMock).login(USERNAME, PASSWORD);
+ verify(ftpsClientMock, times(3)).isConnected();
+ verifyNoMoreInteractions(ftpsClientMock);
}
@Test
@@ -186,15 +216,27 @@ public class FtpsClientTest {
when(keyStoreWrapperMock.getKeyStore()).thenReturn(keyStoreMock);
when(trustManagerFactoryMock.getTrustManagers()).thenReturn(new TrustManager[] {trustManagerMock});
when(ftpsClientMock.login(USERNAME, PASSWORD)).thenReturn(true);
- when(ftpsClientMock.getReplyCode()).thenReturn(HttpStatus.BAD_REQUEST.value());
+ when(ftpsClientMock.getReplyCode()).thenReturn(FTPReply.BAD_COMMAND_SEQUENCE);
ImmutableFileServerData fileServerData = ImmutableFileServerData.builder().serverAddress(XNF_ADDRESS)
.userId(USERNAME).password(PASSWORD).port(PORT).build();
FileCollectResult result = clientUnderTest.collectFile(fileServerData, REMOTE_FILE_PATH, LOCAL_FILE_PATH);
- verify(ftpsClientMock, times(1)).disconnect();
assertFalse(result.downloadSuccessful());
+ verify(ftpsClientMock).setNeedClientAuth(true);
+ verify(keyManagerUtilsMock).setCredentials(FTP_KEY_PATH, FTP_KEY_PASSWORD);
+ verify(ftpsClientMock).setKeyManager(keyManagerMock);
+ verify(fileResourceMock).setPath(TRUSTED_CA_PATH);
+ verify(keyStoreWrapperMock).load(inputStreamMock, TRUSTED_CA_PASSWORD.toCharArray());
+ verify(inputStreamMock, times(1)).close();
+ verify(trustManagerFactoryMock).init(keyStoreMock);
+ verify(ftpsClientMock).setTrustManager(trustManagerMock);
+ verify(ftpsClientMock).connect(XNF_ADDRESS, PORT);
+ verify(ftpsClientMock).login(USERNAME, PASSWORD);
+ verify(ftpsClientMock, times(2)).getReplyCode();
+ verify(ftpsClientMock, times(3)).isConnected();
+ verifyNoMoreInteractions(ftpsClientMock);
}
@Test
@@ -212,6 +254,17 @@ public class FtpsClientTest {
FileCollectResult result = clientUnderTest.collectFile(fileServerData, REMOTE_FILE_PATH, LOCAL_FILE_PATH);
assertFalse(result.downloadSuccessful());
+ verify(ftpsClientMock).setNeedClientAuth(true);
+ verify(keyManagerUtilsMock).setCredentials(FTP_KEY_PATH, FTP_KEY_PASSWORD);
+ verify(ftpsClientMock).setKeyManager(keyManagerMock);
+ verify(fileResourceMock).setPath(TRUSTED_CA_PATH);
+ verify(keyStoreWrapperMock).load(inputStreamMock, TRUSTED_CA_PASSWORD.toCharArray());
+ verify(inputStreamMock, times(1)).close();
+ verify(trustManagerFactoryMock).init(keyStoreMock);
+ verify(ftpsClientMock).setTrustManager(trustManagerMock);
+ verify(ftpsClientMock).connect(XNF_ADDRESS, PORT);
+ verify(ftpsClientMock, times(3)).isConnected();
+ verifyNoMoreInteractions(ftpsClientMock);
}
@Test
@@ -232,6 +285,26 @@ public class FtpsClientTest {
assertFalse(result.downloadSuccessful());
verify(localFileMock, times(1)).delete();
+ verify(ftpsClientMock).setNeedClientAuth(true);
+ verify(keyManagerUtilsMock).setCredentials(FTP_KEY_PATH, FTP_KEY_PASSWORD);
+ verify(ftpsClientMock).setKeyManager(keyManagerMock);
+ verify(fileResourceMock).setPath(TRUSTED_CA_PATH);
+ verify(keyStoreWrapperMock).load(inputStreamMock, TRUSTED_CA_PASSWORD.toCharArray());
+ verify(inputStreamMock, times(1)).close();
+ verify(trustManagerFactoryMock).init(keyStoreMock);
+ verify(ftpsClientMock).setTrustManager(trustManagerMock);
+ verify(ftpsClientMock).connect(XNF_ADDRESS, PORT);
+ verify(ftpsClientMock).login(USERNAME, PASSWORD);
+ verify(ftpsClientMock).getReplyCode();
+ verify(ftpsClientMock, times(1)).enterLocalPassiveMode();
+ verify(ftpsClientMock).execPBSZ(0);
+ verify(ftpsClientMock).execPROT("P");
+ verify(ftpsClientMock).setFileType(FTP.BINARY_FILE_TYPE);
+ verify(ftpsClientMock).setBufferSize(1024 * 1024);
+ verify(localFileMock).setPath(LOCAL_FILE_PATH);
+ verify(localFileMock, times(1)).createNewFile();
+ verify(ftpsClientMock, times(2)).isConnected();
+ verifyNoMoreInteractions(ftpsClientMock);
}
@Test
@@ -254,5 +327,26 @@ public class FtpsClientTest {
FileCollectResult result = clientUnderTest.collectFile(fileServerData, REMOTE_FILE_PATH, LOCAL_FILE_PATH);
assertFalse(result.downloadSuccessful());
+ verify(ftpsClientMock).setNeedClientAuth(true);
+ verify(keyManagerUtilsMock).setCredentials(FTP_KEY_PATH, FTP_KEY_PASSWORD);
+ verify(ftpsClientMock).setKeyManager(keyManagerMock);
+ verify(fileResourceMock).setPath(TRUSTED_CA_PATH);
+ verify(keyStoreWrapperMock).load(inputStreamMock, TRUSTED_CA_PASSWORD.toCharArray());
+ verify(inputStreamMock, times(1)).close();
+ verify(trustManagerFactoryMock).init(keyStoreMock);
+ verify(ftpsClientMock).setTrustManager(trustManagerMock);
+ verify(ftpsClientMock).connect(XNF_ADDRESS, PORT);
+ verify(ftpsClientMock).login(USERNAME, PASSWORD);
+ verify(ftpsClientMock).getReplyCode();
+ verify(ftpsClientMock, times(1)).enterLocalPassiveMode();
+ verify(ftpsClientMock).execPBSZ(0);
+ verify(ftpsClientMock).execPROT("P");
+ verify(ftpsClientMock).setFileType(FTP.BINARY_FILE_TYPE);
+ verify(ftpsClientMock).setBufferSize(1024 * 1024);
+ verify(localFileMock).setPath(LOCAL_FILE_PATH);
+ verify(localFileMock, times(1)).createNewFile();
+ verify(ftpsClientMock).retrieveFile(REMOTE_FILE_PATH, osMock);
+ verify(ftpsClientMock, times(2)).isConnected();
+ verifyNoMoreInteractions(ftpsClientMock);
}
-} \ 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 d8296e1c..bf2f73d6 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
@@ -19,7 +19,6 @@ package org.onap.dcaegen2.collectors.datafile.service.producer;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import com.google.gson.JsonElement;
@@ -30,9 +29,16 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.charset.StandardCharsets;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;
+import org.apache.http.HttpResponse;
+import org.apache.http.StatusLine;
+import org.apache.http.client.methods.HttpPut;
+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;
@@ -40,13 +46,8 @@ 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.web.IRestTemplate;
-import org.springframework.http.HttpEntity;
+import org.onap.dcaegen2.collectors.datafile.service.HttpUtils;
import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
import org.springframework.web.util.DefaultUriBuilderFactory;
import reactor.test.StepVerifier;
@@ -77,11 +78,12 @@ class DmaapProducerReactiveHttpClientTest {
private ConsumerDmaapModel consumerDmaapModel;
private IFileSystemResource fileSystemResourceMock = mock(IFileSystemResource.class);
- private IRestTemplate restTemplateMock = mock(IRestTemplate.class);
- private ResponseEntity<String> responseEntityMock = mock(ResponseEntity.class);
+ private CloseableHttpAsyncClient clientMock;
+ private HttpResponse responseMock = mock(HttpResponse.class);
+ private Future<HttpResponse> futureMock = mock(Future.class);
+ private StatusLine statusLine = mock(StatusLine.class);
private InputStream fileStream;
-
@BeforeEach
void setUp() {
when(dmaapPublisherConfigurationMock.dmaapHostName()).thenReturn(HOST);
@@ -111,59 +113,60 @@ class DmaapProducerReactiveHttpClientTest {
dmaapProducerReactiveHttpClient = new DmaapProducerReactiveHttpClient(dmaapPublisherConfigurationMock);
dmaapProducerReactiveHttpClient.setFileSystemResource(fileSystemResourceMock);
- dmaapProducerReactiveHttpClient.setRestTemplate(restTemplateMock);
+ clientMock = mock(CloseableHttpAsyncClient.class);
+ dmaapProducerReactiveHttpClient.setWebClient(clientMock);
}
@Test
void getHttpResponse_Success() throws Exception {
mockWebClientDependantObject(true);
- StepVerifier.create(dmaapProducerReactiveHttpClient.getDmaapProducerResponse(consumerDmaapModel))
- .expectNext(HttpStatus.OK.toString()).verifyComplete();
-
URI expectedUri = new DefaultUriBuilderFactory().builder().scheme(HTTPS_SCHEME).host(HOST).port(PORT)
.path(PUBLISH_TOPIC + URI_SEPARATOR + DEFAULT_FEED_ID + URI_SEPARATOR + FILE_NAME).build();
- HttpHeaders headers = new HttpHeaders();
-
- headers.setContentType(MediaType.parseMediaType(APPLICATION_OCTET_STREAM_CONTENT_TYPE));
+ HttpPut httpPut = new HttpPut();
+ httpPut.addHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_OCTET_STREAM_CONTENT_TYPE);
JsonElement metaData = new JsonParser().parse(CommonFunctions.createJsonBody(consumerDmaapModel));
metaData.getAsJsonObject().remove(NAME_JSON_TAG).getAsString();
metaData.getAsJsonObject().remove(INTERNAL_LOCATION_JSON_TAG);
- headers.set(X_ATT_DR_META, metaData.toString());
+ httpPut.addHeader(X_ATT_DR_META, metaData.toString());
+ httpPut.setURI(expectedUri);
String plainCreds = "dradmin" + ":" + "dradmin";
byte[] plainCredsBytes = plainCreds.getBytes(StandardCharsets.ISO_8859_1);
byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes);
String base64Creds = new String(base64CredsBytes);
- headers.add("Authorization", "Basic " + base64Creds);
+ httpPut.addHeader("Authorization", "Basic " + base64Creds);
fileStream.reset();
+ StepVerifier.create(dmaapProducerReactiveHttpClient.getDmaapProducerResponse(consumerDmaapModel))
+ .expectNext(responseMock.toString()).verifyComplete();
- HttpEntity<byte[]> requestEntity = new HttpEntity<>(IOUtils.toByteArray(fileStream), headers);
verify(fileSystemResourceMock).setPath("target/" + FILE_NAME);
- verify(restTemplateMock).exchange(expectedUri, HttpMethod.PUT, requestEntity, String.class);
- verifyNoMoreInteractions(restTemplateMock);
+ InputStream fileInputStream = fileSystemResourceMock.getInputStream();
+ httpPut.setEntity(new ByteArrayEntity(IOUtils.toByteArray(fileInputStream)));
}
@Test
void getHttpResponse_Fail() throws Exception {
mockWebClientDependantObject(false);
-
StepVerifier.create(dmaapProducerReactiveHttpClient.getDmaapProducerResponse(consumerDmaapModel))
.verifyComplete();
}
- private void mockWebClientDependantObject(boolean success) throws IOException {
+ private void mockWebClientDependantObject(boolean success)
+ throws IOException, InterruptedException, ExecutionException {
fileStream = new ByteArrayInputStream(FILE_CONTENT.getBytes());
when(fileSystemResourceMock.getInputStream()).thenReturn(fileStream);
-
if (success) {
- when(restTemplateMock.exchange(any(), any(), any(), any())).thenReturn(responseEntityMock);
- when(responseEntityMock.getStatusCode()).thenReturn(HttpStatus.OK);
+ when(clientMock.execute(any(HttpPut.class), any())).thenReturn(futureMock);
+ when(futureMock.get()).thenReturn(responseMock);
+ when(responseMock.getStatusLine()).thenReturn(statusLine);
+ when(statusLine.getStatusCode()).thenReturn(HttpUtils.SC_OK);
} else {
- when(restTemplateMock.exchange(any(), any(), any(), any())).thenThrow(new RuntimeException());
+ when(clientMock.execute(any(HttpPut.class), any())).thenReturn(futureMock);
+ when(futureMock.get()).thenThrow(new InterruptedException());
}
}
}
diff --git a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/web/RequestResponseLoggingInterceptorTest.java b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/web/RequestResponseLoggingInterceptorTest.java
deleted file mode 100644
index b0f5c931..00000000
--- a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/web/RequestResponseLoggingInterceptorTest.java
+++ /dev/null
@@ -1,55 +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.web;
-
-
-import org.junit.jupiter.api.Test;
-import org.springframework.http.HttpRequest;
-import org.springframework.http.client.ClientHttpRequestExecution;
-import org.springframework.http.client.ClientHttpResponse;
-
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-
-class RequestResponseLoggingInterceptorTest {
-
- @Test
- void intercept_shouldReturnObject() throws URISyntaxException, IOException {
-
- //given
- RequestResponseLoggingInterceptor requestResponseLoggingInterceptor = new RequestResponseLoggingInterceptor();
-
- ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);
- HttpRequest request = mock(HttpRequest.class);
- ClientHttpResponse response = mock(ClientHttpResponse.class);
-
- byte[] BODY = new byte[] { (byte)0xe0, 0x4f, (byte)0xd0, 0x20, (byte)0xa2 };
- URI uri = new URI("www.someuri.com");
-
- //when
- when(execution.execute(request, BODY)).thenReturn(response);
-
- //then
- assertNotNull(requestResponseLoggingInterceptor.intercept(request, BODY, execution));
- }
-}
diff --git a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/web/RestTemplateWrapperTest.java b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/web/RestTemplateWrapperTest.java
deleted file mode 100644
index 3a0701ff..00000000
--- a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/web/RestTemplateWrapperTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * ============LICENSE_START======================================================================
- * Copyright (C) 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.web;
-
-import org.junit.jupiter.api.Test;
-
-import java.security.KeyManagementException;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-
-class RestTemplateWrapperTest {
-
- @Test
- void constructor_shouldReturnNotNullObject() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
- RestTemplateWrapper restTemplateWrapper = new RestTemplateWrapper();
- assertNotNull(restTemplateWrapper);
- }
-}