vfs: .jar refresh test extended

This commit is contained in:
Roman Shevchenko
2014-04-24 11:28:09 +02:00
parent 115aaf1034
commit 91e3ed4c1c
2 changed files with 19 additions and 10 deletions
@@ -75,6 +75,9 @@ public class JarFileSystemTest extends PlatformLangTestCase {
VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(jar);
assertNotNull(vFile);
VirtualFile jarRoot = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR);
assertEquals(1, jarRoot.getChildren().length);
final VirtualFile entry = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR + JarFile.MANIFEST_NAME);
assertContent(entry, "");
@@ -94,12 +97,15 @@ public class JarFileSystemTest extends PlatformLangTestCase {
}
);
IoTestUtil.writeEntry(jar, JarFile.MANIFEST_NAME, "update");
IoTestUtil.createTestJar(jar, JarFile.MANIFEST_NAME, "update", "some.txt", "some text");
vFile.refresh(false, false);
assertTrue(updated.get());
assertTrue(entry.isValid());
assertContent(entry, "update");
assertEquals(2, jarRoot.getChildren().length);
VirtualFile newEntry = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR + "some.txt");
assertContent(newEntry, "some text");
}
public void testInvalidJar() throws Exception {
@@ -26,9 +26,9 @@ import java.io.*;
import java.net.URL;
import java.util.Locale;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import static org.junit.Assert.*;
@@ -217,20 +217,23 @@ public class IoTestUtil {
@NotNull
public static File createTestJar(File jarFile) throws IOException {
writeEntry(jarFile, JarFile.MANIFEST_NAME, "");
return jarFile;
return createTestJar(jarFile, JarFile.MANIFEST_NAME, "");
}
public static void writeEntry(@NotNull File jarFile, @NotNull String name, @NotNull String content) throws IOException {
JarOutputStream stream = new JarOutputStream(new FileOutputStream(jarFile));
@NotNull
public static File createTestJar(@NotNull File jarFile, @NotNull String... data) throws IOException {
ZipOutputStream stream = new ZipOutputStream(new FileOutputStream(jarFile));
try {
stream.putNextEntry(new JarEntry(name));
stream.write(content.getBytes("UTF-8"));
stream.closeEntry();
for (int i = 0; i < data.length; i += 2) {
stream.putNextEntry(new ZipEntry(data[i]));
stream.write(data[i + 1].getBytes("UTF-8"));
stream.closeEntry();
}
}
finally {
stream.close();
}
return jarFile;
}
@NotNull