1 package org.openecomp.core.utilities.file;
3 import org.testng.Assert;
4 import org.testng.annotations.Test;
6 import java.io.IOException;
7 import java.util.Arrays;
8 import java.util.Optional;
10 import static org.testng.Assert.assertEquals;
11 import static org.testng.Assert.assertFalse;
12 import static org.testng.Assert.assertTrue;
18 public class FileContentHandlerTest {
20 private static final String FILE_NAME = "test-file.txt";
23 public void testProcessFileContent() throws Exception {
26 FileContentHandler contentHandler = new FileContentHandler();
27 final byte[] content = new byte[size];
28 Arrays.fill(content, (byte) 44);
29 contentHandler.addFile(FILE_NAME, content);
31 byte[] actualContent = contentHandler.processFileContent(FILE_NAME, optional -> {
34 byte[] buffer = new byte[size];
35 assertTrue(optional.isPresent());
36 assertEquals(size, optional.get().read(buffer));
38 } catch (IOException e) {
39 throw new RuntimeException("Unexpected error", e);
43 Assert.assertTrue(Arrays.equals(actualContent, content));
47 public void testProcessEmptyFileContent() throws Exception {
48 FileContentHandler contentHandler = new FileContentHandler();
49 contentHandler.addFile(FILE_NAME, new byte[0]);
50 assertFalse(contentHandler.processFileContent(FILE_NAME, Optional::isPresent));
54 public void testProcessNoFileContent() throws Exception {
55 FileContentHandler contentHandler = new FileContentHandler();
56 assertFalse(contentHandler.processFileContent("filename", Optional::isPresent));