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.*;
16 public class FileContentHandlerTest {
18 private static final String FILE_NAME = "test-file.txt";
21 public void testProcessFileContent() throws Exception {
24 FileContentHandler contentHandler = new FileContentHandler();
25 final byte[] content = new byte[size];
26 Arrays.fill(content, (byte) 44);
27 contentHandler.addFile(FILE_NAME, content);
29 byte[] actualContent = contentHandler.processFileContent(FILE_NAME, optional -> {
32 byte[] buffer = new byte[size];
33 assertTrue(optional.isPresent());
34 assertEquals(size, optional.get().read(buffer));
36 } catch (IOException e) {
37 throw new RuntimeException("Unexpected error", e);
41 Assert.assertTrue(Arrays.equals(actualContent, content));
45 public void testProcessEmptyFileContent() throws Exception {
46 FileContentHandler contentHandler = new FileContentHandler();
47 contentHandler.addFile(FILE_NAME, new byte[0]);
48 assertFalse(contentHandler.processFileContent(FILE_NAME, Optional::isPresent));
52 public void testProcessNoFileContent() throws Exception {
53 FileContentHandler contentHandler = new FileContentHandler();
54 assertFalse(contentHandler.processFileContent("filename", Optional::isPresent));