/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
/**
*
* @author tjquinn
*/
public class PayloadFilesManagerTest {
public PayloadFilesManagerTest() {
}
}
}
public void setUp() {
try {
} catch (Exception e) {
}
}
public void tearDown() {
}
/**
* Test of getOutputFileURI method, of class PayloadFilesManager.
*/
@Test
////System.out.println("getOutputFileURI");
////System.out.println(" " + originalPath + " -> " + result);
}
@Test
////System.out.println("testBraces");
final Part testPart = PayloadImpl.Part.newInstance("text/plain", originalPath, null, "random content");
////System.out.println(" " + originalPath + " -> " + result);
}
@Test
new CommonTempTest() {
}
boolean success = true;
// Make sure all files have the same parent - since in this test
// they all came from the same path originally.
////System.out.println(" " + f.toURI().toASCIIString());
parent = f.getParentFile();
} else {
}
}
}
}.run("diffFilesFromSamePath");
}
@Test
new CommonTempTest() {
}
boolean success = true;
} else {
}
////System.out.println(" " + f.toURI().toASCIIString());
}
assertTrue("Failed because temp file names did not match or at least two had a parent in common", success);
}
}.run("sameFilesInDiffPaths");
}
@Test
new CommonTempTest() {
}
////System.out.println(" Original: " + originalFile.toURI().toASCIIString());
////System.out.println(" Temp file: " + f.toURI().toASCIIString());
if (f.equals(originalFile)) {
fail("Temp file was created at original top-level path; should have been in a temp dir");
}
}
}
}.run("testLeadingSlashes");
}
@Test
new CommonTempTest() {
}
boolean success = true;
}
////System.out.println(" " + f.toURI().toASCIIString());
}
////System.out.println(" Done");
}
}.run("testPathlessFile");
}
// @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");
//
// }
@Test
/*
* Create a directory into which we'll transfer some small files.
*/
try {
/*
* Choose the directory into which we want the PayloadFilesManager to
* deliver the files.
*/
new CommonPermTest() {
return this;
}
"test-xfer",
fileA);
"test-xfer",
fileB);
}
/*
* Extract files to where we want them.
*/
for (File f : desiredResults) {
if ( ! f.exists()) {
}
}
}
protected void cleanup() {
for (File f : desiredResults) {
f.delete();
}
}
} finally {
}
}
}
@Test
/*
* Create a directory into which we'll transfer some small files.
*/
try {
/*
* Choose the directory into which we want the PayloadFilesManager to
* deliver the files.
*/
/*
* In this test result, we want file B to be absent after we transfer
* it (with files A and C) and then use a second PayloadFilesManager
* to request B's removal.
*/
writeFile(fileC, "Here is File C", "which has an", "additional line", "even beyond what fileB has");
new CommonPermTest() {
return this;
}
"test-xfer",
fileA);
"test-xfer",
fileB);
"test-xfer",
fileC);
}
/*
* Extract files to where we want them.
*/
/*
* Now ask another PayloadFilesManager to remove one of the
* just-extracted files.
*/
"removeTest" /* dataRequestName */,
null /* props */);
final PayloadFilesManager remover =
for (File f : desiredPresent) {
if ( ! f.exists()) {
}
}
for (File f : desiredAbsent) {
if (f.exists()) {
}
}
assertEquals("Unexpected files remain after removal request",
}
protected void cleanup() {
for (File f : desiredPresent) {
f.delete();
}
}
} finally {
}
}
}
@Test
/*
* Create a directory into which we'll copy some small files.
*/
try {
/*
* Choose the directory into which we want the PayloadFilesManager to
* deliver the files.
*/
new CommonPermTest() {
return this;
}
"test-xfer",
dir,
true /* isRecursive */);
}
/*
* Extract files to where we want them.
*/
// listDir("After creation, before deletion", myTargetDir);
/*
* Now ask another PayloadFilesManager to remove a directory
* recursively.
*/
"removeTest" /* dataRequestName */,
null /* props */,
true /* isRecursive */);
"removeTest",
null,
true);
final PayloadFilesManager remover =
debugLogger());
// listDir("After deletion" , myTargetDir);
for (File f : desiredAbsent) {
if (f.exists()) {
}
}
assertEquals("Unexpected files remain after removal request",
}
protected void cleanup() {
for (File f : desiredAbsent) {
if (f.exists()) {
f.delete();
}
}
}
} finally {
}
}
}
@Test
/*
* Populate the target directory with a subdirectory containing a file,
* then replace the subdirectory via a replacement request in a Payload.
*/
origSubDir.mkdirs();
try {
new CommonPermTest() {
return this;
}
"test-xfer",
null, /* props */
true /* isRecursive */);
}
/*
* Process files.
*/
for (File f : desiredAbsent) {
if (f.exists()) {
}
}
assertEquals("Unexpected files remain after replacement request",
for (File f : desiredPresent) {
if ( ! f.exists()) {
}
}
assertEquals("Unexpected files absent after replacement request",
}
protected void cleanup() {
for (File f : desiredAbsent) {
if (f.exists()) {
f.delete();
}
}
}
} finally {
}
}
}
////System.out.println(title);
////System.out.println();
}
//System.out.println("Directory " + dir.getAbsolutePath() + " does not exist");
} else {
//System.out.println((f.isDirectory() ? "dir " : " ") + f.getAbsolutePath());
if (f.isDirectory()) {
listDir(f);
}
}
}
}
@Test
/*
* Create a directory into which we'll transfer some small files.
*/
try {
/*
* Choose the directory into which we want the PayloadFilesManager to
* deliver the files.
*/
/*
* Add the directory first, then add a file in the directory. That
* will let us check to make sure the PayloadFileManager set the
* lastModified time on the directory correctly.
*/
new CommonPermTest() {
return this;
}
"test-xfer",
dir);
"test-xfer",
file);
}
/*
* Extract files to where we want them.
*/
assertEquals("Directory lastModified mismatch after extraction",
}
protected void cleanup() {
for (File f : desiredResults) {
f.delete();
}
}
} finally {
}
}
}
@Test
/*
* Create a directory into which we'll copy some small files.
*/
try {
/*
* Choose the directory into which we want the PayloadFilesManager to
* deliver the files.
*/
/*
* Add the original directory recursively.
*/
new CommonPermTest() {
return this;
}
"test-xfer",
dir,
true /* isRecursive */);
}
/*
* Extract files to where we want them.
*/
for (File f : desiredResults) {
if ( ! f.exists()) {
}
}
}
protected void cleanup() {
for (File f : desiredResults) {
f.delete();
}
}
} finally {
}
}
}
@Test
/*
* Create a directory into which we'll copy some small files.
*/
try {
/*
* Choose the directory into which we want the PayloadFilesManager to
* deliver the files.
*/
/*
* Add the original directory recursively.
*/
new CommonPermTest() {
return this;
}
"test-xfer",
dir,
true /* isRecursive */);
}
/*
* Extract files to where we want them.
*/
for (File f : desiredResults) {
if ( ! f.exists()) {
}
}
}
protected void cleanup() {
for (File f : desiredResults) {
f.delete();
}
}
} finally {
}
}
}
@Test
/*
* Create a directory into which we'll copy some small files.
*/
try {
/*
* Choose the directory into which we want the PayloadFilesManager to
* deliver the files.
*/
/*
* Add the original directory recursively.
*/
new CommonTempTest() {
"test-xfer",
dir,
true /* isRecursive */);
}
/*
* Extract files to where we want them.
*/
continue checkNextFile;
}
}
}
assertEquals("Unexpected missing files after extraction", Collections.EMPTY_LIST, desiredResultsNamePrefixes);
}
protected void cleanup() {
}
}.run("simpleTempRecursiveTransferDirOnlyTest");
} finally {
}
}
}
}
}
return props;
}
// private void testForBadChars(String initialPath) {
// URI uri = null;
// URI targetDirURI = null;
// try {
// PayloadFilesManager.Temp instance = new PayloadFilesManager.Temp(Logger.getAnonymousLogger());
// uri = URI.create(initialPath.replace(File.separator, "/"));
// targetDirURI = instance.getTargetDir().toURI();
//
// //System.out.println(" " + initialPath + " -> " + uri.toASCIIString());
// String uriString = targetDirURI.relativize(uri).toASCIIString();
//
// // trim the trailing slash for the directory
// if (uriString.endsWith("/")) {
// uriString = uriString.substring(0, uriString.length() - 1);
// }
// assertFalse("path " + uriString + " still contains bad character(s)",
// uriString.contains("/") ||
// uriString.contains("\\") ||
// (uriString.contains(":") && File.separatorChar == '\\')); } catch (Exception e) {
// fail("unexpected exception " + e.getMessage());
// }
// }
private abstract class CommonTest {
protected abstract void cleanup();
//System.out.println(testName);
try {
Payload.Inbound ib = PayloadImpl.Inbound.newInstance(payloadType, new BufferedInputStream(new FileInputStream(tempZipFile)));
cleanup();
} finally {
if (tempZipFile != null) {
}
}
}
}
return tempInstance;
}
protected void cleanup() {
}
}
return this;
}
return permInstance;
}
}
/**
* Makes it easy to turn on or off FINE-level logging in the PayloadFilesManager
* during the tests.
* <p>
* Uncomment the comment lines below to turn on FINE logging for the test.
*
*
* @return
*/
{
// this.setLevel(Level.INFO);
}
//System.out.println(record.getMessage());
}
public void flush() {
//System.out.flush();
}
public void close() throws SecurityException {
// no-op
}
});
return logger;
}
}