summaryrefslogtreecommitdiffstats
path: root/datafile-dmaap-client
diff options
context:
space:
mode:
authorVijay Venkatesh Kumar <vv770d@att.com>2018-11-15 03:56:50 +0000
committerGerrit Code Review <gerrit@onap.org>2018-11-15 03:56:50 +0000
commitf5781dc662781851da563be9a9671d0270c19576 (patch)
tree1a83987024581acef11bc08360092adc3fc28232 /datafile-dmaap-client
parent6c3a8e063d203e88a9f0ae1107587692c84c0d08 (diff)
parentcf1221cac89cc3310017d6c72ee0638ddec24cea (diff)
Merge "Add test for FtpsClient, Improve code coverage."
Diffstat (limited to 'datafile-dmaap-client')
-rw-r--r--datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectResult.java2
-rw-r--r--datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/ErrorDataTest.java57
-rw-r--r--datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java22
3 files changed, 80 insertions, 1 deletions
diff --git a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectResult.java b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectResult.java
index c5962172..9b6eacb0 100644
--- a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectResult.java
+++ b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectResult.java
@@ -44,6 +44,6 @@ public class FileCollectResult {
@Override
public String toString() {
- return "Download successful: " + result + " Error data: " + getErrorData();
+ return "FileCollectResult: " + result + " Error data: " + getErrorData();
}
}
diff --git a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/ErrorDataTest.java b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/ErrorDataTest.java
new file mode 100644
index 00000000..e40d7d78
--- /dev/null
+++ b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/ErrorDataTest.java
@@ -0,0 +1,57 @@
+/*
+ * ============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.ftp;
+
+import static org.mockito.Mockito.mock;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class ErrorDataTest {
+ private List<String> errorMessages = new ArrayList<>();
+ private List<Throwable> errorCauses = new ArrayList<>();
+ private ErrorData errorData = new ErrorData();
+
+ @BeforeEach
+ protected void setUp() {
+ int testSize = 3;
+ for (int i = 0; i < testSize; i++) {
+ errorMessages.add("test");
+ errorCauses.add(mock(Throwable.class));
+ }
+ for (int i = 0; i < testSize; i++) {
+ errorData.addError(errorMessages.get(i), errorCauses.get(i));
+ }
+ }
+
+ public String getMessageAsString() {
+ StringBuilder message = new StringBuilder();
+ for (int i = 0; i < errorMessages.size(); i++) {
+ message.append(errorMessages.get(i)).append(" Cause: ").append(errorCauses.get(i)).append("\n");
+ }
+ return message.toString();
+ }
+
+ @Test
+ public void testToString_returnExpectedString() {
+ Assertions.assertEquals(getMessageAsString(), errorData.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 e5693d50..66d3b00c 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
@@ -233,4 +233,26 @@ public class FtpsClientTest {
assertFalse(result.downloadSuccessful());
verify(localFileMock, times(1)).delete();
}
+
+ @Test
+ public void collectFileFailingFileRetrieve_shouldFail() throws Exception {
+ when(keyManagerUtilsMock.getClientKeyManager()).thenReturn(keyManagerMock);
+ when(fileResourceMock.getInputStream()).thenReturn(inputStreamMock);
+ when(keyStoreWrapperMock.getKeyStore()).thenReturn(keyStoreMock);
+ when(trustManagerFactoryMock.getTrustManagers()).thenReturn(new TrustManager[] {trustManagerMock});
+ when(ftpsClientMock.login(USERNAME, PASSWORD)).thenReturn(true);
+ when(ftpsClientMock.getReplyCode()).thenReturn(HttpStatus.OK.value());
+ File fileMock = mock(File.class);
+ when(localFileMock.getFile()).thenReturn(fileMock);
+ OutputStream osMock = mock(OutputStream.class);
+ when(outputStreamMock.getOutputStream(fileMock)).thenReturn(osMock);
+ when(ftpsClientMock.retrieveFile(REMOTE_FILE_PATH, osMock)).thenReturn(false);
+
+ 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);
+
+ assertFalse(result.downloadSuccessful());
+ }
} \ No newline at end of file