Author: rob.stryker(a)jboss.com
Date: 2008-02-25 16:31:03 -0500 (Mon, 25 Feb 2008)
New Revision: 6561
Added:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/FileIOTest.java
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/MarshallUnmarshallTest.java
Removed:
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
Modified:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTestSuite.java
Log:
moving unit tests around
Modified:
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 2008-02-25
20:25:36 UTC (rev 6560)
+++
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTestSuite.java 2008-02-25
21:31:03 UTC (rev 6561)
@@ -1,5 +1,8 @@
package org.jboss.ide.eclipse.archives.test;
+import org.jboss.ide.eclipse.archives.test.xb.FileIOTest;
+import org.jboss.ide.eclipse.archives.test.xb.MarshallUnmarshallTest;
+
import junit.framework.Test;
import junit.framework.TestSuite;
Deleted:
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 2008-02-25
20:25:36 UTC (rev 6560)
+++
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/FileIOTest.java 2008-02-25
21:31:03 UTC (rev 6561)
@@ -1,163 +0,0 @@
-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;
- }
- }
-}
Deleted:
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 2008-02-25
20:25:36 UTC (rev 6560)
+++
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/MarshallUnmarshallTest.java 2008-02-25
21:31:03 UTC (rev 6561)
@@ -1,175 +0,0 @@
-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());
- }
-}
Copied:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/FileIOTest.java
(from rev 6560,
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/xb/FileIOTest.java
(rev 0)
+++
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/FileIOTest.java 2008-02-25
21:31:03 UTC (rev 6561)
@@ -0,0 +1,163 @@
+package org.jboss.ide.eclipse.archives.test.xb;
+
+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.ArchivesTest;
+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;
+ }
+ }
+}
Copied:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/MarshallUnmarshallTest.java
(from rev 6560,
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/xb/MarshallUnmarshallTest.java
(rev 0)
+++
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/MarshallUnmarshallTest.java 2008-02-25
21:31:03 UTC (rev 6561)
@@ -0,0 +1,176 @@
+package org.jboss.ide.eclipse.archives.test.xb;
+
+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.ArchivesTest;
+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());
+ }
+}