/*
* 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 Tim Quinn
*/
public class FileArchiveTest {
private final Set<String> usualExpectedSubarchiveEntryNames = initUsualExpectedSubarchiveEntryNames();
return expectedEntryNames;
}
return result;
}
return result;
}
public FileArchiveTest() {
}
}
}
archiveDir = tempDir();
}
public void tearDown() {
if (archiveDir != null) {
}
archiveDir = null;
}
f.delete();
f.mkdir();
return f;
}
if (f.isDirectory()) {
clean(f);
}
if ( ! f.delete()) {
f.deleteOnExit();
}
}
dir.deleteOnExit();
};
}
/*
* Add some entries.
*/
}
}
final WritableArchive parent,
final String subarchiveName,
result.closeEntry();
}
}
private void createAndPopulateAndCheckArchive(
}
}
}
}
private void getListOfFilesCheckForLogRecord(FileArchive instance, final Set<String> expectedEntryNames) throws IOException {
.append(": ")
}
fail("Expected 1 log message but received " + logger.logRecords().size() + " as follows:" + LINE_SEP + sb.toString());
}
/*
* We have a stale file under a stale directory. Make sure a direct
* request for the stale file fails. (We know already from above that
* getting the entries list triggers a warning about the skipped stale file.)
*/
}
/**
* Computes the expected entry names for an archive which contains a subarchive.
* <p>
* The archive's entries method will report all the entries in the main
* archive, plus the subarchive name, plus the entries in the subarchive.
* @param expectedFromArchive entries from the main archive
* @param subarchiveName name of the subarchive
* @param expectedFromSubarchive entries in the subarchive
* @return entry names that should be returned from the main archive's entries() method
*/
private Set<String> expectedEntryNames(Set<String> expectedFromArchive, final String subarchiveName, Set<String>expectedFromSubarchive) {
}
}
}
return result;
}
@Test
}
@Test
/*
* Subarchives are a little tricky. The marker file lives only at
* the top level (because that's where undeployment puts it). So
* when a subarchive tests to see if an entry is valid it needs to
* consult the marker file (if any) in the top-level owning archive.
*
* This test creates a directory structure containing a stale file
* in a lower-level directory, creates the top-level marker file
* as undeployment would, then creates an archive for the top level
* and a subarchive for the lower-level directory (as the next
* deployment would). The archive and subarchive need to skip the
* stale file.
*/
/*
* Create a file in the directory before creating the archive.
*/
/*
* Mimic what undeployment does by creating a marker file for the
* archive recording the pre-existing file.
*/
/*
* Now create the archive and subarchive on top of the directories
* which already exist and contain the stale file and directory.
*/
}
private static class ArchiveAndSubarchive {
}
return result;
}
/**
* Test of open method, of class FileArchive.
*/
@Test
}
@Test
}
@Test
/*
* Now add the stale entry explicitly which should make it valid.
*/
}
private ReadableArchive createWithOlderLeftoverEntry(final Set<String> entryNames) throws Exception {
/*
* Create a file in the directory before creating the archive.
*/
/*
* Mimic what undeployment does by creating a marker file for the
* archive recording the pre-existing file.
*/
/*
* Now create the archive. The archive should not see the old file.
*/
return createAndPopulateArchive(entryNames);
}
@Test
System.out.println("Skipping (as successful) testCreateWithOlderLeftoverEntryAndThenOpen because this is not a Windows system");
return;
}
}
@Test
}
f.getParentFile().mkdirs();
f.createNewFile();
}
}
@Test
/*
* The IBM Java implementation seems not to work correctly with
* File.setReadable. So report this test
*/
System.out.println("Skipping testInaccessibleDirectoryInFileArchive (as successful) because the Java vendor seems to be IBM");
return;
}
/*
* FileArchive will log a warning if it cannot list the files in the
* directory. Here's the message key it will use.
*/
/*
* Now make the lower-level directory impossible to execute - therefore
* the attempt to list the files should fail.
*/
lower.setExecutable(false, false);
if ( ! canRead) {
/*
* If we cannot change the permissions then the test will fail.
* We'd like to dynamically ignore this test but that's very involved
* and requirea a custom test runner and notifier. So we just
* say the test passes.
*/
return;
}
/*
* Try to list the files. This should fail with our logger getting
* one record.
*/
if (logRecords.isEmpty()) {
fail("FileArchive logged no message about being unable to list files; expected " + EXPECTED_LOG_KEY);
}
assertEquals("FileArchive did not log expected message (re: being unable to list files)",
/*
* Change the protection back.
*/
lower.setExecutable(true, false);
lower.setReadable(true, false);
assertTrue("FileArchive was incorrectly unable to list files; error key in log record:" +
logRecords.isEmpty());
}
private RecordingLogger() {
super("TestLogger", null);
}
}
void clear() {
}
return records;
}
}
}