use of org.glassfish.api.admin.Payload.Inbound in project Payara by payara.
the class PayloadFilesManagerTest method simplePermanentTransferTest.
// @Test
// public void testWindowsPath() throws Exception {
// //System.out.println("testWindowsPath");
// testForBadChars("C:\\Program Files\\someDir");
// }
//
// @Test
// public void testNonWindowsPath() throws Exception {
// //System.out.println("testNonWindowsPath");
// testForBadChars("/Users/whoever/someDir");
//
// }
@Test
public void simplePermanentTransferTest() throws Exception {
final String FILE_A_PREFIX = "";
final String FILE_A_NAME = "fileA.txt";
final String FILE_B_PREFIX = "x/y/z";
final String FILE_B_NAME = "fileB.txt";
final Set<File> desiredResults = new HashSet<File>();
/*
* Create a directory into which we'll transfer some small files.
*/
final File origDir = File.createTempFile("pfm", "");
origDir.delete();
File targetDir = null;
try {
/*
* Choose the directory into which we want the PayloadFilesManager to
* deliver the files.
*/
targetDir = File.createTempFile("tgt", "");
targetDir.delete();
targetDir.mkdir();
origDir.mkdir();
final File fileA = new File(origDir, FILE_A_NAME);
writeFile(fileA, "This is File A", "and another line");
desiredResults.add(new File(targetDir.toURI().resolve(FILE_A_PREFIX + FILE_A_NAME)));
final File fileB = new File(origDir, FILE_B_NAME);
desiredResults.add(new File(targetDir.toURI().resolve(FILE_B_PREFIX + FILE_B_NAME)));
writeFile(fileB, "Here is File B", "which has an", "additional line");
new CommonPermTest() {
@Override
protected CommonPermTest init(File targetDir) {
super.init(targetDir);
return this;
}
@Override
protected void addParts(Outbound ob, PayloadFilesManager instance) throws Exception {
ob.attachFile("application/octet-stream", URI.create(FILE_A_PREFIX + fileA.getName()), "test-xfer", fileA);
ob.attachFile("text/plain", URI.create(FILE_B_PREFIX + fileB.getName()), "test-xfer", fileB);
}
@Override
protected void checkResults(Inbound ib, PayloadFilesManager instance) throws Exception {
/*
* Extract files to where we want them.
*/
instance.processParts(ib);
final Set<File> missing = new HashSet<File>();
for (File f : desiredResults) {
if (!f.exists()) {
missing.add(f);
}
}
assertEquals("Unexpected missing files after extraction", Collections.EMPTY_SET, missing);
}
@Override
protected void cleanup() {
for (File f : desiredResults) {
f.delete();
}
PayloadFilesManagerTest.cleanup(origDir);
}
}.init(targetDir).run("simplePermanentTransferTest");
} finally {
if (targetDir != null) {
FileUtils.whack(targetDir);
}
}
}
use of org.glassfish.api.admin.Payload.Inbound in project Payara by payara.
the class PayloadFilesManagerTest method simplePermanentRecursiveTransferTest.
@Test
public void simplePermanentRecursiveTransferTest() throws Exception {
final String DIR = "x/";
final String Y_SUBDIR = "y/";
final String Z_SUBDIR = "z/";
final String FILE_A_PREFIX = DIR + Y_SUBDIR;
final String FILE_A_NAME = "fileA.txt";
final String FILE_B_PREFIX = DIR + Y_SUBDIR + Z_SUBDIR;
final String FILE_B_NAME = "fileB.txt";
final Set<File> desiredResults = new HashSet<File>();
/*
* Create a directory into which we'll copy some small files.
*/
final File origDir = File.createTempFile("pfm", "");
origDir.delete();
origDir.mkdir();
final File dir = new File(origDir, DIR);
dir.mkdir();
final File ySubdir = new File(dir, Y_SUBDIR);
ySubdir.mkdir();
final File zSubdir = new File(dir, Y_SUBDIR + Z_SUBDIR);
zSubdir.mkdir();
final File fileA = new File(ySubdir, FILE_A_NAME);
final File fileB = new File(zSubdir, FILE_B_NAME);
writeFile(fileA, "This is FileA", "with two lines of content");
writeFile(fileB, "This is FileB", "with a", "third line");
File targetDir = null;
try {
/*
* Choose the directory into which we want the PayloadFilesManager to
* deliver the files.
*/
targetDir = File.createTempFile("tgt", "");
targetDir.delete();
targetDir.mkdir();
desiredResults.add(new File(targetDir.toURI().resolve(FILE_A_PREFIX + FILE_A_NAME)));
desiredResults.add(new File(targetDir.toURI().resolve(FILE_B_PREFIX + FILE_B_NAME)));
/*
* Add the original directory recursively.
*/
new CommonPermTest() {
@Override
protected CommonPermTest init(File targetDir) {
super.init(targetDir);
return this;
}
@Override
protected void addParts(Outbound ob, PayloadFilesManager instance) throws Exception {
ob.attachFile("application/octet-stream", URI.create("x/"), "test-xfer", dir, true);
}
@Override
protected void checkResults(Inbound ib, PayloadFilesManager instance) throws Exception {
/*
* Extract files to where we want them.
*/
final List<File> files = instance.processParts(ib);
final Set<File> missing = new HashSet<File>();
for (File f : desiredResults) {
if (!f.exists()) {
missing.add(f);
}
}
assertEquals("Unexpected missing files after extraction", Collections.EMPTY_SET, missing);
}
@Override
protected void cleanup() {
for (File f : desiredResults) {
f.delete();
}
PayloadFilesManagerTest.cleanup(origDir);
}
}.init(targetDir).run("simplePermanentRecursiveTransferTest");
} finally {
if (targetDir != null) {
FileUtils.whack(targetDir);
}
}
}
Aggregations