Author: rob.stryker(a)jboss.com
Date: 2007-07-27 16:21:34 -0400 (Fri, 27 Jul 2007)
New Revision: 2710
Added:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/.classpath
trunk/core/tests/org.jboss.ide.eclipse.archives.test/.project
trunk/core/tests/org.jboss.ide.eclipse.archives.test/META-INF/
trunk/core/tests/org.jboss.ide.eclipse.archives.test/META-INF/MANIFEST.MF
trunk/core/tests/org.jboss.ide.eclipse.archives.test/bin/
trunk/core/tests/org.jboss.ide.eclipse.archives.test/build.properties
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/archiveDescriptors/
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/archiveDescriptors/descriptor1.xml
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/flatTextFiles/
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/flatTextFiles/one.txt
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/flatTextFiles/three.txt
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/flatTextFiles/two.txt
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/multiple_files.gif
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/new_package.gif
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/prop_ps.gif
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/rug.xml
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/secretImages/
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/secretImages/new_jar_wiz.png
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/secretImages/new_war_wiz.png
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/single_file.gif
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/someHtml.html
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/projects/
trunk/core/tests/org.jboss.ide.eclipse.archives.test/output/
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTest.java
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTestSuite.java
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/FileIOTest.java
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/MarshallUnmarshallTest.java
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ModelUtilTest.java
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/util/
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/util/FileIOUtil.java
trunk/core/tests/org.jboss.ide.eclipse.archives.test/tmp/
Log:
Initial import.
Added: trunk/core/tests/org.jboss.ide.eclipse.archives.test/.classpath
===================================================================
--- trunk/core/tests/org.jboss.ide.eclipse.archives.test/.classpath
(rev 0)
+++ trunk/core/tests/org.jboss.ide.eclipse.archives.test/.classpath 2007-07-27 20:21:34
UTC (rev 2710)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: trunk/core/tests/org.jboss.ide.eclipse.archives.test/.project
===================================================================
--- trunk/core/tests/org.jboss.ide.eclipse.archives.test/.project
(rev 0)
+++ trunk/core/tests/org.jboss.ide.eclipse.archives.test/.project 2007-07-27 20:21:34 UTC
(rev 2710)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.jboss.ide.eclipse.archives.test</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.jboss.ide.eclipse.archives.core.archivesBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.jboss.ide.eclipse.archives.core.archivesNature</nature>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added: trunk/core/tests/org.jboss.ide.eclipse.archives.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/core/tests/org.jboss.ide.eclipse.archives.test/META-INF/MANIFEST.MF
(rev 0)
+++ trunk/core/tests/org.jboss.ide.eclipse.archives.test/META-INF/MANIFEST.MF 2007-07-27
20:21:34 UTC (rev 2710)
@@ -0,0 +1,12 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Archives Test Plug-in
+Bundle-SymbolicName: org.jboss.ide.eclipse.archives.test
+Bundle-Version: 1.0.0
+Bundle-Activator: org.jboss.ide.eclipse.archives.test.ArchivesTest
+Require-Bundle: org.eclipse.core.runtime,
+ org.junit,
+ org.jboss.ide.eclipse.archives.core,
+ org.eclipse.core.resources
+Eclipse-LazyStart: true
+Bundle-ClassPath: archivestest.jar
Added: trunk/core/tests/org.jboss.ide.eclipse.archives.test/build.properties
===================================================================
--- trunk/core/tests/org.jboss.ide.eclipse.archives.test/build.properties
(rev 0)
+++ trunk/core/tests/org.jboss.ide.eclipse.archives.test/build.properties 2007-07-27
20:21:34 UTC (rev 2710)
@@ -0,0 +1,5 @@
+source.. = src/
+output.archivestest.jar = bin/
+bin.includes = META-INF/,\
+ archivestest.jar
+source.archivestest.jar = src/
Added:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/archiveDescriptors/descriptor1.xml
===================================================================
---
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/archiveDescriptors/descriptor1.xml
(rev 0)
+++
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/archiveDescriptors/descriptor1.xml 2007-07-27
20:21:34 UTC (rev 2710)
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<packages>
+ <package name="TestProject.jar" type="jar"
todir="/some/external/path" exploded="false"
inWorkspace="false">
+ <folder name="folder">
+ <properties></properties>
+ </folder>
+ <folder name="folder2">
+ <folder name="inner1">
+ <fileset dir="/some/global/path" includes="**/*.xml"
inWorkspace="false">
+ <properties></properties>
+ </fileset>
+ <properties></properties>
+ </folder>
+ <properties></properties>
+ </folder>
+ </package>
+ <package name="TestProject2.jar" type="jar"
todir="/SomeProject" exploded="true" inWorkspace="true">
+ </package>
+ <properties></properties>
+</packages>
\ No newline at end of file
Added:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/flatTextFiles/one.txt
===================================================================
---
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/flatTextFiles/one.txt
(rev 0)
+++
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/flatTextFiles/one.txt 2007-07-27
20:21:34 UTC (rev 2710)
@@ -0,0 +1 @@
+File One
\ No newline at end of file
Added:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/flatTextFiles/three.txt
===================================================================
---
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/flatTextFiles/three.txt
(rev 0)
+++
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/flatTextFiles/three.txt 2007-07-27
20:21:34 UTC (rev 2710)
@@ -0,0 +1 @@
+Third File
\ No newline at end of file
Added:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/flatTextFiles/two.txt
===================================================================
---
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/flatTextFiles/two.txt
(rev 0)
+++
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/flatTextFiles/two.txt 2007-07-27
20:21:34 UTC (rev 2710)
@@ -0,0 +1 @@
+Lorum Ipsum
\ No newline at end of file
Added:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/multiple_files.gif
===================================================================
(Binary files differ)
Property changes on:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/multiple_files.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/new_package.gif
===================================================================
(Binary files differ)
Property changes on:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/new_package.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/prop_ps.gif
===================================================================
(Binary files differ)
Property changes on:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/prop_ps.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/rug.xml
===================================================================
--- trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/rug.xml
(rev 0)
+++
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/rug.xml 2007-07-27
20:21:34 UTC (rev 2710)
@@ -0,0 +1,7 @@
+<rug>
+ <color>Red</color>
+ <shape>Circle</shape>
+ <size><w unit="inches">60</w>
+ <l unit="cm">300</l>
+ </size>
+</rug>
\ No newline at end of file
Added:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/secretImages/new_jar_wiz.png
===================================================================
(Binary files differ)
Property changes on:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/secretImages/new_jar_wiz.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/secretImages/new_war_wiz.png
===================================================================
(Binary files differ)
Property changes on:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/secretImages/new_war_wiz.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/single_file.gif
===================================================================
(Binary files differ)
Property changes on:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/single_file.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/someHtml.html
===================================================================
---
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/someHtml.html
(rev 0)
+++
trunk/core/tests/org.jboss.ide.eclipse.archives.test/inputs/fileTrees/misc/someHtml.html 2007-07-27
20:21:34 UTC (rev 2710)
@@ -0,0 +1,4 @@
+<html>I'm an html file! I swear!
+
+No seriously. <i>there... </i> do you believe me now?
+</html>
\ No newline at end of file
Added:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTest.java
===================================================================
---
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTest.java
(rev 0)
+++
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTest.java 2007-07-27
20:21:34 UTC (rev 2710)
@@ -0,0 +1,50 @@
+package org.jboss.ide.eclipse.archives.test;
+
+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class ArchivesTest extends Plugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.jboss.ide.eclipse.archives.test";
+
+ // The shared instance
+ private static ArchivesTest plugin;
+
+ /**
+ * The constructor
+ */
+ public ArchivesTest() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static ArchivesTest getDefault() {
+ return plugin;
+ }
+
+}
Added:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTestSuite.java
===================================================================
---
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTestSuite.java
(rev 0)
+++
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTestSuite.java 2007-07-27
20:21:34 UTC (rev 2710)
@@ -0,0 +1,17 @@
+package org.jboss.ide.eclipse.archives.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class ArchivesTestSuite extends TestSuite {
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Archives Tests");
+
+ suite.addTestSuite(FileIOTest.class);
+ suite.addTestSuite(MarshallUnmarshallTest.class);
+ suite.addTestSuite(ModelUtilTest.class);
+
+ return suite;
+ }
+
+}
Added:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/FileIOTest.java
===================================================================
---
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/FileIOTest.java
(rev 0)
+++
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/FileIOTest.java 2007-07-27
20:21:34 UTC (rev 2710)
@@ -0,0 +1,163 @@
+package org.jboss.ide.eclipse.archives.test;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.jboss.ide.eclipse.archives.core.util.internal.TrueZipUtil;
+import org.jboss.ide.eclipse.archives.test.util.FileIOUtil;
+import org.osgi.framework.Bundle;
+
+public class FileIOTest extends TestCase {
+ private Bundle bundle;
+ private IPath bundlePath;
+ protected void setUp() {
+ if( bundlePath == null ) {
+ try {
+ bundle = ArchivesTest.getDefault().getBundle();
+ URL bundleURL = FileLocator.toFileURL(bundle.getEntry(""));
+ bundlePath = new Path(bundleURL.getFile());
+ } catch( IOException ioe) {}
+ }
+ }
+
+ protected void tearDown() {
+ try {
+ de.schlichtherle.io.File.umount();
+ } catch( Exception e ) {}
+ FileIOUtil.clearFolder(bundlePath.append("tmp").toFile().listFiles());
+ }
+
+
+ public void testPathExists() {
+ IPath inputs = bundlePath.append("inputs");
+ assertTrue(TrueZipUtil.pathExists(bundlePath));
+ assertTrue(TrueZipUtil.pathExists(inputs));
+ assertTrue(TrueZipUtil.pathExists(inputs.append("fileTrees")));
+ assertTrue(TrueZipUtil.pathExists(inputs.append("fileTrees").append("flatTextFiles").append("one.txt")));
+
+ assertFalse(TrueZipUtil.pathExists(bundlePath.append("doesNotExist")));
+ assertFalse(TrueZipUtil.pathExists(inputs.append("doesNotExist")));
+ assertFalse(TrueZipUtil.pathExists(inputs.append("fileTrees").append("flatTextFiles").append("doesNotExist.txt")));
+ }
+
+ public void testCreationAndDeletion() {
+ IPath tmpDir = bundlePath.append("tmp");
+
+ // create archives via both APIs,
+ IPath creationArchive1 = tmpDir.append("creationArchive1.jar");
+ IPath creationArchive2 = tmpDir.append("creationArchive2.zip");
+ IPath creationArchive3 = tmpDir.append("creationArchive3");
+
+ assertFalse(TrueZipUtil.pathExists(creationArchive1));
+ TrueZipUtil.createArchive(creationArchive1);
+ assertTrue(TrueZipUtil.pathExists(creationArchive1));
+ assertFalse(creationArchive1.toFile().isDirectory());
+
+ assertFalse(TrueZipUtil.pathExists(creationArchive2));
+ TrueZipUtil.createArchive(creationArchive2);
+ assertTrue(TrueZipUtil.pathExists(creationArchive2));
+ assertFalse(creationArchive2.toFile().isDirectory());
+
+ // and also create an archive with no suffix
+ assertFalse(TrueZipUtil.pathExists(creationArchive3));
+ TrueZipUtil.createArchive(creationArchive3);
+ assertTrue(TrueZipUtil.pathExists(creationArchive3));
+ assertFalse(creationArchive3.toFile().isDirectory());
+
+
+ // create folders with various names
+ IPath creationFolder1 = tmpDir.append("creationFolder1.jar");
+ IPath creationFolder2 = tmpDir.append("creationFolder2.zip");
+ IPath creationFolder3 = tmpDir.append("creationFolder3");
+
+ assertFalse(TrueZipUtil.pathExists(creationFolder1));
+ TrueZipUtil.createFolder(creationFolder1);
+ assertTrue(TrueZipUtil.pathExists(creationFolder1));
+ assertTrue(creationFolder1.toFile().isDirectory());
+
+ assertFalse(TrueZipUtil.pathExists(creationFolder2));
+ TrueZipUtil.createFolder(creationFolder2);
+ assertTrue(TrueZipUtil.pathExists(creationFolder2));
+ assertTrue(creationFolder2.toFile().isDirectory());
+
+ assertFalse(TrueZipUtil.pathExists(creationFolder3));
+ TrueZipUtil.createFolder(creationFolder3);
+ assertTrue(TrueZipUtil.pathExists(creationFolder3));
+ assertTrue(creationFolder3.toFile().isDirectory());
+
+
+ // folders and archives of all extensions work.
+ // keep one folder and one archive and add to each
+ // another folder, archive, and file
+
+ IPath archiveFolder = creationArchive1.append("folderName");
+ IPath archiveArchive = creationArchive1.append("archiveName.war");
+
+ IPath folderFolder = creationFolder1.append("folderName");
+ IPath folderArchive = creationFolder1.append("archiveName.war");
+
+
+ assertFalse(TrueZipUtil.pathExists(archiveFolder));
+ assertFalse(TrueZipUtil.pathExists(archiveArchive));
+ TrueZipUtil.createFolder(archiveFolder);
+ TrueZipUtil.createArchive(archiveArchive);
+ try {de.schlichtherle.io.File.umount();} catch( Exception e ) {}
+ assertTrue(TrueZipUtil.pathExists(archiveFolder));
+ assertTrue(TrueZipUtil.pathExists(archiveArchive));
+ assertFalse(archiveFolder.toFile().exists());
+ assertFalse(archiveArchive.toFile().exists());
+
+
+ assertFalse(TrueZipUtil.pathExists(folderFolder));
+ assertFalse(TrueZipUtil.pathExists(folderArchive));
+ TrueZipUtil.createFolder(folderFolder);
+ TrueZipUtil.createArchive(folderArchive);
+ try {de.schlichtherle.io.File.umount();} catch( Exception e ) {}
+ assertTrue(TrueZipUtil.pathExists(archiveFolder));
+ assertTrue(TrueZipUtil.pathExists(archiveArchive));
+ assertTrue(folderFolder.toFile().exists());
+ assertTrue(folderArchive.toFile().exists());
+
+ // copy a file into them
+ IPath archiveFile = creationArchive1.append("file.txt");
+ IPath folderFile = creationArchive1.append("file.txt");
+
+ String srcPath = bundlePath.append("inputs").append("fileTrees")
+ .append("flatTextFiles").append("two.txt").toOSString();
+ try {
+ assertFalse(TrueZipUtil.pathExists(archiveFile));
+ assertFalse(TrueZipUtil.pathExists(folderFile));
+ TrueZipUtil.copyFile(srcPath, archiveFile);
+ TrueZipUtil.copyFile(srcPath, folderFile);
+ assertTrue(TrueZipUtil.pathExists(archiveFile));
+ assertTrue(TrueZipUtil.pathExists(folderFile));
+ } catch( Exception e ) {
+ fail("IOException: " + e.getMessage());
+ }
+
+ de.schlichtherle.io.File f = TrueZipUtil.getFile(creationFolder1);
+ int numChildren = f.list().length;
+ assertEquals(2, numChildren);
+ TrueZipUtil.deleteEmptyChildren(f);
+ int numChildren2 = f.list().length;
+ assertEquals(0, numChildren2);
+
+ de.schlichtherle.io.File f2 = TrueZipUtil.getFile(creationArchive1);
+ TrueZipUtil.deleteAll(creationArchive1);
+ assertFalse(TrueZipUtil.pathExists(f2));
+ }
+
+ protected IPath bundleEntryToGlobalPath(String entry) {
+ try {
+ return new Path(FileLocator.toFileURL(bundle.getEntry(entry)).getFile());
+ } catch( IOException e ) {
+ return null;
+ }
+ }
+}
Added:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/MarshallUnmarshallTest.java
===================================================================
---
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/MarshallUnmarshallTest.java
(rev 0)
+++
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/MarshallUnmarshallTest.java 2007-07-27
20:21:34 UTC (rev 2710)
@@ -0,0 +1,175 @@
+package org.jboss.ide.eclipse.archives.test;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbFileSet;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbFolder;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackage;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackages;
+import org.jboss.ide.eclipse.archives.test.util.FileIOUtil;
+import org.osgi.framework.Bundle;
+
+public class MarshallUnmarshallTest extends TestCase {
+ private Bundle bundle;
+ private IPath bundlePath;
+ private IPath archiveDescriptors;
+ protected void setUp() {
+ if( bundlePath == null ) {
+ try {
+ bundle = ArchivesTest.getDefault().getBundle();
+ URL bundleURL = FileLocator.toFileURL(bundle.getEntry(""));
+ bundlePath = new Path(bundleURL.getFile());
+ archiveDescriptors =
bundlePath.append("inputs").append("archiveDescriptors");
+ } catch( IOException ioe) {}
+ }
+ }
+
+
+ public void tearDown() {
+ FileIOUtil.clearFolder(bundlePath.append("tmp").toFile().listFiles());
+ }
+
+ public void testUnmarshall() {
+ // unmarshall from file
+ FileInputStream fis = null;
+ try {
+ fis = new
FileInputStream(archiveDescriptors.append("descriptor1.xml").toFile());
+ } catch( Exception e ) {
+ fail(e.getMessage());
+ }
+ XbPackages packs = XMLBinding.unmarshal(fis, new NullProgressMonitor());
+ assertDescriptor1Accurate(packs);
+
+ // unmarshall from string
+ try {
+ String content =
fileAsString(archiveDescriptors.append("descriptor1.xml").toFile());
+ packs = XMLBinding.unmarshal(content, new NullProgressMonitor());
+ assertDescriptor1Accurate(packs);
+ } catch( Exception e ) {
+ fail(e.getMessage());
+ }
+
+ }
+
+ public String fileAsString(File f) throws Exception {
+ FileInputStream fis = new FileInputStream(f);
+ int x= fis.available();
+ byte b[]= new byte[x];
+ fis.read(b);
+ return new String(b);
+ }
+
+ public void testMarshall() {
+ IPath tmpFolder = bundlePath.append("tmp");
+
+ XbPackages packs = new XbPackages();
+ XbPackage pack1 = new XbPackage();
+ pack1.setName("TestProject.jar");
+ pack1.setPackageType("jar");
+ pack1.setToDir("/some/external/path");
+ pack1.setExploded(false);
+ pack1.setInWorkspace(false);
+ packs.addChild(pack1);
+
+ XbPackage pack2 = new XbPackage();
+ pack2.setName("TestProject2.jar");
+ pack2.setPackageType("jar");
+ pack2.setToDir("/SomeProject");
+ pack2.setExploded(true);
+ pack2.setInWorkspace(true);
+ packs.addChild(pack2);
+
+ XbFolder folder1 = new XbFolder();
+ folder1.setName("folder");
+ pack1.addChild(folder1);
+
+ XbFolder folder2 = new XbFolder();
+ folder2.setName("folder2");
+ pack1.addChild(folder2);
+
+ XbFolder inner1 = new XbFolder();
+ inner1.setName("inner1");
+ folder2.addChild(inner1);
+
+ XbFileSet fs = new XbFileSet();
+ fs.setDir("/some/global/path");
+ fs.setIncludes("**/*.xml");
+ fs.setInWorkspace(false);
+ inner1.addChild(fs);
+
+ assertDescriptor1Accurate(packs);
+
+ String packsAsString = XMLBinding.serializePackages(packs, new
NullProgressMonitor());
+ XbPackages packsFromString = XMLBinding.unmarshal(packsAsString, new
NullProgressMonitor());
+ assertDescriptor1Accurate(packsFromString);
+
+ try {
+ OutputStreamWriter writer = new OutputStreamWriter(new
FileOutputStream(tmpFolder.append("marshallTest.xml").toFile()));
+ XMLBinding.marshall(packs, writer, new NullProgressMonitor());
+ writer.close();
+
+ XbPackages packsFromFile = XMLBinding.unmarshal(new
FileInputStream(tmpFolder.append("marshallTest.xml").toFile()), new
NullProgressMonitor());
+ assertDescriptor1Accurate(packsFromFile);
+ } catch(Exception e) {
+ fail(e.getMessage());
+ }
+
+ }
+
+ void assertDescriptor1Accurate(XbPackages packs) {
+ assertEquals(2, packs.getAllChildren().size());
+ assertEquals(2, packs.getChildren(XbPackage.class).size());
+
+ XbPackage pack1 = (XbPackage)packs.getAllChildren().get(0);
+ XbPackage pack2 = (XbPackage)packs.getAllChildren().get(1);
+
+ // pack 1
+ assertEquals("TestProject.jar", pack1.getName());
+ assertEquals("/some/external/path", pack1.getToDir());
+ assertEquals("jar", pack1.getPackageType());
+ assertFalse(pack1.isExploded());
+ assertFalse(pack1.isInWorkspace());
+ assertEquals(2, pack1.getAllChildren().size());
+ assertEquals(2, pack1.getChildren(XbFolder.class).size());
+
+ XbFolder folder1 = (XbFolder)pack1.getAllChildren().get(0);
+ XbFolder folder2 = (XbFolder)pack1.getAllChildren().get(1);
+
+ assertEquals(0, folder1.getAllChildren().size());
+ assertEquals("folder", folder1.getName());
+
+ assertEquals(1, folder2.getAllChildren().size());
+ assertEquals(1, folder2.getChildren(XbFolder.class).size());
+ assertEquals("folder2", folder2.getName());
+
+ XbFolder innerFolder = (XbFolder)folder2.getAllChildren().get(0);
+ assertEquals("inner1", innerFolder.getName());
+ assertEquals(1, innerFolder.getAllChildren().size());
+ assertEquals(1, innerFolder.getChildren(XbFileSet.class).size());
+
+ XbFileSet fs = (XbFileSet)innerFolder.getAllChildren().get(0);
+ assertEquals(fs.getIncludes(), "**/*.xml");
+ assertEquals(fs.getDir(), "/some/global/path");
+ assertFalse(fs.isInWorkspace());
+
+ // pack 2
+ assertEquals(0, pack2.getAllChildren().size());
+ assertEquals("TestProject2.jar", pack2.getName());
+ assertEquals("/SomeProject", pack2.getToDir());
+ assertEquals("jar", pack2.getPackageType());
+ assertTrue(pack2.isExploded());
+ assertTrue(pack2.isInWorkspace());
+ }
+}
Added:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ModelUtilTest.java
===================================================================
---
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ModelUtilTest.java
(rev 0)
+++
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ModelUtilTest.java 2007-07-27
20:21:34 UTC (rev 2710)
@@ -0,0 +1,141 @@
+package org.jboss.ide.eclipse.archives.test;
+
+import java.io.IOException;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.jboss.ide.eclipse.archives.core.model.ArchiveNodeFactory;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveFileSet;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveFolder;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
+import org.jboss.ide.eclipse.archives.core.model.internal.ArchiveNodeImpl;
+import org.jboss.ide.eclipse.archives.core.util.ModelUtil;
+import org.osgi.framework.Bundle;
+
+public class ModelUtilTest extends TestCase {
+ private Bundle bundle;
+ private IPath bundlePath;
+ private IPath outputs;
+ private IPath inputs;
+ private IArchive rootArchive;
+ protected void setUp() {
+ if( bundlePath == null ) {
+ try {
+ bundle = ArchivesTest.getDefault().getBundle();
+ URL bundleURL = FileLocator.toFileURL(bundle.getEntry(""));
+ bundlePath = new Path(bundleURL.getFile());
+ outputs = bundlePath.append("output");
+ inputs = bundlePath.append("inputs");
+ } catch( IOException ioe) {}
+ }
+ rootArchive = createArchive();
+ }
+
+ public void tearDown() {
+ rootArchive = null;
+ }
+
+
+
+ protected IArchive createArchive() {
+ IPath fileTrees = inputs.append("fileTrees");
+
+ IArchive root = ArchiveNodeFactory.createArchive();
+ root.setArchiveType("jar");
+ root.setDestinationPath(outputs);
+ root.setName("output.jar");
+ root.setExploded(false);
+ root.setInWorkspace(false);
+
+ IArchiveFolder topFolder = ArchiveNodeFactory.createFolder();
+ topFolder.setName("topFolder");
+ root.addChild(topFolder);
+
+ IArchiveFolder inner1 = ArchiveNodeFactory.createFolder();
+ inner1.setName("inner1");
+ topFolder.addChild(inner1);
+
+ IArchiveFolder images = ArchiveNodeFactory.createFolder();
+ images.setName("images");
+ topFolder.addChild(images);
+
+ IArchiveFileSet outerFileset = ArchiveNodeFactory.createFileset();
+ outerFileset.setInWorkspace(false);
+ outerFileset.setSourcePath(fileTrees.append("misc"));
+ outerFileset.setExcludesPattern("**/*.gif,**/*.png");
+ outerFileset.setIncludesPattern("**/*");
+ topFolder.addChild(outerFileset);
+
+ IArchiveFileSet imageFileset = ArchiveNodeFactory.createFileset();
+ imageFileset.setInWorkspace(false);
+ imageFileset.setSourcePath(fileTrees.append("misc"));
+ imageFileset.setIncludesPattern("**/*.gif,**/*.png,**/*.xml");
+ images.addChild(imageFileset);
+
+ ((ArchiveNodeImpl)root).clearDeltas();
+ return root;
+ }
+
+ public void testFindAllDescendentFilesets() {
+ IArchiveFileSet[] fsets = ModelUtil.findAllDescendentFilesets(rootArchive);
+ assertTrue(fsets.length == 2);
+ assertTrue(fsets[0].getParent().getNodeType() == IArchiveNode.TYPE_ARCHIVE_FOLDER);
+ assertTrue(fsets[1].getParent().getNodeType() == IArchiveNode.TYPE_ARCHIVE_FOLDER);
+ assertTrue(ModelUtil.findAllDescendentFilesets(ArchiveNodeFactory.createFileset()).length
== 1);
+ }
+
+ public void testFindAllDescendentFolders() {
+ IArchiveFolder[] folders = ModelUtil.findAllDescendentFolders(rootArchive);
+ assertTrue(folders.length == 3);
+ }
+
+ public void testFindAllDescendentsGeneric() {
+ assertTrue(ModelUtil.findAllDescendents(rootArchive, IArchiveNode.TYPE_ARCHIVE,
false).size() == 0);
+ assertTrue(ModelUtil.findAllDescendents(rootArchive, IArchiveNode.TYPE_ARCHIVE,
true).size() == 1);
+ assertTrue(ModelUtil.findAllDescendents(rootArchive, IArchiveNode.TYPE_ARCHIVE_FOLDER,
false).size() == 3);
+ assertTrue(ModelUtil.findAllDescendents(rootArchive, IArchiveNode.TYPE_ARCHIVE_FILESET,
false).size() == 2);
+ }
+
+ public void testGetMatchingFileSets() {
+ IPath misc = inputs.append("fileTrees").append("misc");
+ IPath gif = misc.append("multiple_files.gif");
+ IPath xml = misc.append("rug.xml");
+ IPath html = misc.append("someHtml.html");
+
+ IArchiveFileSet[] gifFS = ModelUtil.getMatchingFilesets(rootArchive, gif);
+ IArchiveFileSet[] xmlFS = ModelUtil.getMatchingFilesets(rootArchive, xml);
+ IArchiveFileSet[] htmlFS = ModelUtil.getMatchingFilesets(rootArchive, html);
+
+ assertEquals(1, gifFS.length);
+ assertEquals(2, xmlFS.length);
+ assertEquals(1, htmlFS.length);
+
+ }
+
+ public void testOtherFilesetMatchesPath() {
+ IPath xml =
inputs.append("fileTrees").append("misc").append("rug.xml");
+ IArchiveFileSet[] xmlFS = ModelUtil.getMatchingFilesets(rootArchive, xml);
+ assertTrue(xmlFS.length == 2);
+ assertFalse(ModelUtil.otherFilesetMatchesPathAndOutputLocation(xmlFS[0], xml,
rootArchive));
+ assertFalse(ModelUtil.otherFilesetMatchesPathAndOutputLocation(xmlFS[1], xml,
rootArchive));
+
+ IPath html =
inputs.append("fileTrees").append("misc").append("someHtml.html");
+ IArchiveFileSet[] htmlFS = ModelUtil.getMatchingFilesets(rootArchive, html);
+ assertTrue(htmlFS.length == 1);
+ assertFalse(ModelUtil.otherFilesetMatchesPathAndOutputLocation(htmlFS[0], html,
rootArchive));
+
+ // add a temporary fileset that will match exactly
+ IArchiveFileSet otherFS = ArchiveNodeFactory.createFileset();
+ otherFS.setIncludesPattern(xmlFS[0].getIncludesPattern());
+ otherFS.setInWorkspace(xmlFS[0].isInWorkspace());
+ otherFS.setSourcePath(xmlFS[0].getSourcePath());
+ xmlFS[0].getParent().addChild(otherFS);
+
+ assertTrue(ModelUtil.otherFilesetMatchesPathAndOutputLocation(xmlFS[0], xml,
rootArchive));
+ }
+}
Added:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/util/FileIOUtil.java
===================================================================
---
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/util/FileIOUtil.java
(rev 0)
+++
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/util/FileIOUtil.java 2007-07-27
20:21:34 UTC (rev 2710)
@@ -0,0 +1,16 @@
+package org.jboss.ide.eclipse.archives.test.util;
+
+import java.io.File;
+
+public class FileIOUtil {
+
+ public static void clearFolder(File[] children) {
+ for( int i = 0; i < children.length; i++ ) {
+ File[] second = children[i].listFiles();
+ if( second != null && second.length > 0 )
+ clearFolder(second);
+ children[i].delete();
+ }
+ }
+
+}