aboutsummaryrefslogtreecommitdiffstats
path: root/datafile-dmaap-client/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'datafile-dmaap-client/src/test')
-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
2 files changed, 79 insertions, 0 deletions
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