You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by st...@apache.org on 2015/02/17 21:40:27 UTC
[36/51] [partial] incubator-taverna-language git commit: temporarily
empty repository
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/316e4a8a/taverna-robundle/src/test/java/org/apache/taverna/robundle/TestExample.java
----------------------------------------------------------------------
diff --git a/taverna-robundle/src/test/java/org/apache/taverna/robundle/TestExample.java b/taverna-robundle/src/test/java/org/apache/taverna/robundle/TestExample.java
deleted file mode 100644
index 51767f5..0000000
--- a/taverna-robundle/src/test/java/org/apache/taverna/robundle/TestExample.java
+++ /dev/null
@@ -1,107 +0,0 @@
-package org.apache.taverna.robundle;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.OutputStream;
-import java.net.URI;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.StandardCopyOption;
-import java.nio.file.StandardOpenOption;
-
-import org.apache.taverna.robundle.Bundle;
-import org.apache.taverna.robundle.Bundles;
-import org.junit.Test;
-
-public class TestExample {
- @Test
- public void example() throws Exception {
- // Create a new (temporary) RO bundle
- Bundle bundle = Bundles.createBundle();
-
- // Get the inputs
- Path inputs = bundle.getRoot().resolve("inputs");
- Files.createDirectory(inputs);
-
- // Get an input port:
- Path in1 = inputs.resolve("in1");
-
- // Setting a string value for the input port:
- Bundles.setStringValue(in1, "Hello");
-
- // And retrieving it
- assertTrue(Bundles.isValue(in1));
- assertEquals("Hello", Bundles.getStringValue(in1));
-
- // Or just use the regular Files methods:
- int lines = 0;
- for (String line : Files.readAllLines(in1, Charset.forName("UTF-8"))) {
- assertEquals("Hello", line);
- lines++;
- }
- assertEquals(1, lines);
-
- // Binaries and large files are done through the Files API
- try (OutputStream out = Files.newOutputStream(in1,
- StandardOpenOption.APPEND)) {
- out.write(32);
- }
- // Or Java 7 style
- Path localFile = Files.createTempFile("", ".txt");
- Files.copy(in1, localFile, StandardCopyOption.REPLACE_EXISTING);
- //System.out.println("Written to: " + localFile);
-
- Files.copy(localFile, bundle.getRoot().resolve("out1"));
-
- // Representing references
- URI ref = URI.create("http://example.com/external.txt");
- Path out3 = bundle.getRoot().resolve("out3");
- Bundles.setReference(out3, ref);
- if (Bundles.isReference(out3)) {
- URI resolved = Bundles.getReference(out3);
- assertNotNull(resolved);
- //System.out.println(resolved);
- }
-
- // Saving a bundle:
- Path zip = Files.createTempFile("bundle", ".zip");
- Bundles.closeAndSaveBundle(bundle, zip);
- // NOTE: From now "bundle" and its Path's are CLOSED
- // and can no longer be accessed
-
- //System.out.println("Saved to " + zip);
-
- // Loading a bundle back from disk
- try (Bundle bundle2 = Bundles.openBundle(zip)) {
- assertEquals(zip, bundle2.getSource());
- }
-
- // if (Desktop.isDesktopSupported()) {
- // // Open ZIP file for browsing
- // Desktop.getDesktop().open(zip.toFile());
- // }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/316e4a8a/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/Helper.java
----------------------------------------------------------------------
diff --git a/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/Helper.java b/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/Helper.java
deleted file mode 100644
index 8538c30..0000000
--- a/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/Helper.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package org.apache.taverna.robundle.fs;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-
-import org.apache.taverna.robundle.Bundles;
-import org.apache.taverna.robundle.fs.BundleFileSystem;
-import org.apache.taverna.robundle.fs.BundleFileSystemProvider;
-import org.junit.After;
-import org.junit.Before;
-
-public class Helper {
- protected BundleFileSystem fs;
-
- @Before
- public void makeFS() throws IOException {
- fs = BundleFileSystemProvider.newFileSystemFromTemporary();
- }
-
- @After
- public void closeAndDeleteFS() throws IOException {
- fs.close();
- Path source = fs.getSource();
- Files.deleteIfExists(source);
- if (source.getParent().getFileName().toString().startsWith("robundle")) {
- Bundles.deleteRecursively(source.getParent());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/316e4a8a/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/MemoryEfficiencyIT.java
----------------------------------------------------------------------
diff --git a/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/MemoryEfficiencyIT.java b/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/MemoryEfficiencyIT.java
deleted file mode 100644
index a0d7ed3..0000000
--- a/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/MemoryEfficiencyIT.java
+++ /dev/null
@@ -1,255 +0,0 @@
-package org.apache.taverna.robundle.fs;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.StandardOpenOption;
-import java.util.Date;
-import java.util.Random;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.taverna.robundle.Bundles;
-import org.apache.taverna.robundle.utils.RecursiveCopyFileVisitor.RecursiveCopyOption;
-import org.junit.Assume;
-import org.junit.Test;
-
-public class MemoryEfficiencyIT extends Helper {
- private static final int MANY_FOLDERS = 100;
- private static final int MANY_FILS = 10000;
- private Runtime rt = Runtime.getRuntime();
-
- // delays to allow garbage collection to run
- private static final long GC_DELAY = 300;
- private static final int kiB = 1024;
-
- private static final int MiB = 1024 * 1024;
- private static final long GiB = 1024l * 1024l * 1024l;
-
- Random rand = new Random();
- int MAX_WORKERS = 10;
-
- @Test
- public void writeManyFiles() throws Exception {
-
- long usedBefore = usedMemory();
-
- Path folder = fs.getPath("folder");
-
- for (int i = 0; i < MANY_FOLDERS; i++) {
- Path dir = folder.resolve("dir" + i);
- Files.createDirectories(dir);
- }
-
- final byte[] pattern = new byte[8 * kiB];
- rand.nextBytes(pattern);
-
- ExecutorService pool = Executors.newFixedThreadPool(MAX_WORKERS);
- try {
- int numFiles = MANY_FILS;
- System.out.println("Writing " + numFiles
- + " files in parallell over max " + MAX_WORKERS
- + " threads");
- for (int i = 0; i < numFiles; i++) {
- int folderNo = i % 100;
- Path dir = folder.resolve("dir" + folderNo);
- final Path file = dir.resolve("file" + i);
- pool.submit(new Runnable() {
- @Override
- public void run() {
- try (OutputStream newOutputStream = Files
- .newOutputStream(file)) {
- newOutputStream.write(pattern);
- } catch (IOException e) {
- e.printStackTrace();
- }
- };
- });
- }
- pool.shutdown();
- assertTrue("Timed out waiting for threads",
- pool.awaitTermination(60, TimeUnit.SECONDS));
- System.out.println("Done");
- } finally {
- pool.shutdownNow();
- }
- long usedAfterCloseFile = usedMemory();
- assertTrue(usedAfterCloseFile - usedBefore < 10 * MiB);
-
- Date startedRecurse = new Date();
- System.out.println("Recursively copying folder");
- Bundles.copyRecursively(folder, fs.getPath("copy"),
- RecursiveCopyOption.IGNORE_ERRORS);
- long duration = new Date().getTime() - startedRecurse.getTime();
- System.out.println("Done in " + duration / 1000 + "s");
-
- long usedAfterRecursive = usedMemory();
- assertTrue(usedAfterRecursive - usedBefore < 20 * MiB);
-
- fs.close();
- long zipSize = Files.size(fs.getSource());
- System.out.println("ZIP: " + zipSize / MiB + " MiB");
- long usedAfterCloseFS = usedMemory();
- assertTrue(usedAfterCloseFS - usedBefore < 20 * MiB);
- assertTrue(usedAfterCloseFS < zipSize);
-
- }
-
- /**
- * This file may take a few minutes to complete depending on your OS and
- * disk
- *
- */
- @Test
- public void writeGigaFile() throws Exception {
-
- long usedBefore = usedMemory();
-
- Path file = fs.getPath("bigfile");
- long size = 5l * GiB;
- Assume.assumeTrue("This test requires at least " + size / GiB
- + "GiB free disk space",
- fs.getFileStore().getUsableSpace() < size);
- System.out.println("Writing " + size / GiB + "GiB to bundle");
-
- // We'll use FileChannel as it allows calling .position. This should
- // be very fast on UNIX which allows zero-padding, but on Windows
- // this will still take a while as it writes 5 GiB of \00s to disk.
-
- // Another downside is that the ZipFileProvider compresses the file
- // once the file channel is closed, requiring ~5 GB disk space
- try (FileChannel bc = FileChannel.open(file, StandardOpenOption.WRITE,
- StandardOpenOption.SPARSE, StandardOpenOption.CREATE_NEW)) {
- bc.position(size);
- ByteBuffer src = ByteBuffer.allocateDirect(1024);
- bc.write(src);
- }
-
- long fileSize = Files.size(file);
- assertTrue(fileSize > size);
- System.out.println("Written " + fileSize / MiB);
- long usedAfterCloseFile = usedMemory();
- assertTrue(usedAfterCloseFile - usedBefore < 10 * MiB);
-
- fs.close();
- long zipSize = Files.size(fs.getSource());
- System.out.println("ZIP: " + zipSize / MiB + " MiB");
- // Zeros should compress fairly well
- assertTrue(zipSize < 10 * MiB);
-
- long usedAfterCloseFS = usedMemory();
- assertTrue(usedAfterCloseFS - usedBefore < 10 * MiB);
- }
-
- @Test
- public void writeBigFile() throws Exception {
-
- long usedBefore = usedMemory();
- long size = sufficientlyBig();
- long limit = size / 2;
-
- Path file = fs.getPath("bigfile");
-
- // Big enough random bytes to blow ZIP's compression buffer
- byte[] pattern = new byte[MiB];
- rand.nextBytes(pattern);
-
- long written = 0;
- try (OutputStream newOutputStream = Files.newOutputStream(file)) {
- while (written < size) {
- newOutputStream.write(pattern);
- written += pattern.length;
- }
- pattern = null;
- rand = null;
- long usedAfterWrite = usedMemory();
- assertTrue(usedAfterWrite - usedBefore < limit);
- }
- long fileSize = Files.size(file);
- assertTrue(fileSize >= size);
- // System.out.println("Written " + fileSize/MiB + ", needed " +
- // size/MiB);
- long usedAfterCloseFile = usedMemory();
- assertTrue(usedAfterCloseFile - usedBefore < limit);
-
- fs.close();
- long zipSize = Files.size(fs.getSource());
- System.out.println("ZIP: " + zipSize / MiB + " MiB");
- assertTrue(zipSize > limit);
-
- long usedAfterCloseFS = usedMemory();
- assertTrue(usedAfterCloseFS - usedBefore < 10 * MiB);
- }
-
- private long sufficientlyBig() throws IOException {
- long usableSpace = fs.getFileStore().getUsableSpace();
- long need = 64 * MiB;
- if (need * 2 > usableSpace) {
- String msg = "Not enough disk space (%s MiB < %s)";
- long freeSpace = usableSpace / MiB;
- long needSpace = need * 2 / MiB;
- throw new IllegalStateException(String.format(msg, freeSpace,
- needSpace));
- }
- return need;
- }
-
- @Test
- public void testUsedMemory() throws Exception {
- long before = usedMemory();
- byte[] waste = new byte[50 * MiB];
- waste[0] = 13;
- waste[waste.length - 1] = 37;
- long after = usedMemory();
-
- assertTrue((after - before) > 10 * MiB);
- waste = null;
- long now = usedMemory();
- // and it should have been freed again
- assertTrue((after - now) > 10 * MiB);
-
- }
-
- public long usedMemory() throws InterruptedException {
- runGC();
- long used = rt.totalMemory() - rt.freeMemory();
- System.out.println("Used memory: " + used / MiB + " MiB");
- return used;
- }
-
- public void runGC() {
- System.gc();
- try {
- Thread.sleep(GC_DELAY);
- System.gc();
- Thread.sleep(GC_DELAY);
- } catch (InterruptedException e) {
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/316e4a8a/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/TestBundleFileSystem.java
----------------------------------------------------------------------
diff --git a/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/TestBundleFileSystem.java b/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/TestBundleFileSystem.java
deleted file mode 100644
index 6a4b7bd..0000000
--- a/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/TestBundleFileSystem.java
+++ /dev/null
@@ -1,236 +0,0 @@
-package org.apache.taverna.robundle.fs;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.nio.file.FileAlreadyExistsException;
-import java.nio.file.Files;
-import java.nio.file.NoSuchFileException;
-import java.nio.file.Path;
-import java.nio.file.attribute.BasicFileAttributeView;
-import java.nio.file.attribute.FileTime;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.taverna.robundle.Bundle;
-import org.apache.taverna.robundle.Bundles;
-import org.junit.Test;
-
-public class TestBundleFileSystem extends Helper {
-
- @Test
- public void writeToNewFile() throws Exception {
- Path file = fs.getPath("test.txt");
- Files.newBufferedWriter(file, Charset.defaultCharset()).close();
- }
-
- @Test
- public void reopenNew() throws Exception {
- Path x = Files.createTempFile("temp", ".zip");
- Bundle bundle = Bundles.createBundle(x);
- Path newFile = Files.createTempFile("temp", ".zip");
- Bundles.closeAndSaveBundle(bundle, newFile);
- Bundles.openBundle(newFile);
- }
-
- @Test
- public void closeAndSaveToPreserveOriginal() throws Exception {
- Path x = Files.createTempFile("temp", ".zip");
- Bundle bundle = Bundles.createBundle(x);
- Path newFile = Files.createTempFile("temp", ".zip");
- Bundles.closeAndSaveBundle(bundle, newFile);
- Bundles.openBundle(x);
- }
-
- /**
- * Test that BundleFileSystem does not allow a ZIP file to also become a
- * directory. See http://stackoverflow.com/questions/16588321/ as Java 7'z
- * ZIPFS normally allows this (!)
- *
- * @throws Exception
- */
- @Test
- public void fileAndDirectory() throws Exception {
- Path folder = fs.getPath("folder");
-
- // To test on local file system, uncomment next 2 lines:
- // Path test = Files.createTempDirectory("test");
- // folder = test.resolve("folder");
-
- assertFalse(Files.exists(folder));
- Files.createFile(folder);
- assertTrue(Files.exists(folder));
- assertTrue(Files.isRegularFile(folder));
- assertFalse(Files.isDirectory(folder));
-
- try {
- Files.createDirectory(folder);
- fail("Should have thrown FileAlreadyExistsException");
- } catch (FileAlreadyExistsException ex) {
- }
- assertFalse(Files.isDirectory(folder));
-
- try {
- Files.createDirectories(folder);
- fail("Should have thrown FileAlreadyExistsException");
- } catch (FileAlreadyExistsException ex) {
- }
- assertFalse(Files.isDirectory(folder));
-
- Path child = folder.resolve("child");
-
- try {
- Files.createFile(child);
- fail("Should have thrown NoSuchFileException");
- } catch (NoSuchFileException ex) {
- }
- assertFalse(Files.exists(child));
-
- assertTrue(Files.isRegularFile(folder));
- assertFalse(Files.isDirectory(folder));
- assertFalse(Files.isDirectory(child.getParent()));
- assertFalse(Files.isDirectory(fs.getPath("folder/")));
- }
-
- /**
- * Test that BundleFileSystem does not allow a ZIP directory to also become
- * a file. See http://stackoverflow.com/questions/16588321/ as Java 7'z
- * ZIPFS normally allows this (!)
- *
- * @throws Exception
- */
- @Test
- public void directoryAndFile() throws Exception {
- Path folderSlash = fs.getPath("folder/");
- Path folder = fs.getPath("folder");
-
- // Uncomment next 3 lines to test on local FS
- // Path test = Files.createTempDirectory("test");
- // folderSlash = test.resolve("folder/");
- // folder = test.resolve("folder");
-
- assertFalse(Files.exists(folderSlash));
-
- Files.createDirectory(folderSlash);
- assertTrue(Files.exists(folderSlash));
- assertFalse(Files.isRegularFile(folderSlash));
- assertTrue(Files.isDirectory(folderSlash));
-
- try {
- Files.createDirectory(folderSlash);
- fail("Should have thrown FileAlreadyExistsException");
- } catch (FileAlreadyExistsException ex) {
- }
-
- try {
- Files.createFile(folderSlash);
- fail("Should have thrown IOException");
- } catch (IOException ex) {
- }
-
- try {
- Files.createFile(folder);
- fail("Should have thrown IOException");
- } catch (IOException ex) {
- }
-
- Path child = folderSlash.resolve("child");
- Files.createFile(child);
-
- assertTrue(Files.exists(folder));
- assertTrue(Files.exists(folderSlash));
-
- assertFalse(Files.isRegularFile(folder));
- assertFalse(Files.isRegularFile(folderSlash));
-
- assertTrue(Files.isDirectory(folder));
- assertTrue(Files.isDirectory(folderSlash));
-
- }
-
- @Test
- public void setLastModifiedTime() throws Exception {
- Path root = fs.getRootDirectories().iterator().next();
-
- Path folder = root.resolve("folder");
- Files.createDirectory(folder);
-
- Path file = root.resolve("file");
- Files.createFile(file);
-
- int manyDays = 365 * 12;
- FileTime someTimeAgo = FileTime.from(manyDays, TimeUnit.DAYS);
- Files.setLastModifiedTime(folder, someTimeAgo);
- Files.setLastModifiedTime(file, someTimeAgo);
- Files.setLastModifiedTime(root, someTimeAgo);
-
- // Should be equal, +/- 2 seconds (allowing precision loss)
- assertEquals((double) someTimeAgo.toMillis(), Files
- .getLastModifiedTime(folder).toMillis(), 2001);
- assertEquals((double) someTimeAgo.toMillis(), Files
- .getLastModifiedTime(file).toMillis(), 2001);
-
- // Fails as we'll get back -1 instead
- // assertEquals((double)someTimeAgo.toMillis(),
- // Files.getLastModifiedTime(root).toMillis(), 2001);
- }
-
- @Test
- public void creationTime() throws Exception {
- Path root = fs.getRootDirectories().iterator().next();
-
- Path folder = root.resolve("folder");
- Files.createDirectory(folder);
-
- Path file = root.resolve("file");
- Files.createFile(file);
-
- int manyDays = 365 * 12;
- FileTime someTimeAgo = FileTime.from(manyDays, TimeUnit.DAYS);
-
- Files.getFileAttributeView(folder, BasicFileAttributeView.class)
- .setTimes(null, null, someTimeAgo);
- Files.getFileAttributeView(file, BasicFileAttributeView.class)
- .setTimes(null, null, someTimeAgo);
- Files.getFileAttributeView(root, BasicFileAttributeView.class)
- .setTimes(null, null, someTimeAgo);
-
- // Should be equal, +/- 2 seconds
- assertEquals((double) someTimeAgo.toMillis(),
- (double) ((FileTime) Files.getAttribute(file, "creationTime"))
- .toMillis(), 2001);
- assertEquals(
- (double) someTimeAgo.toMillis(),
- (double) ((FileTime) Files.getAttribute(folder, "creationTime"))
- .toMillis(), 2001);
-
- // FIXME: FAils with NullPointerException! :(
- // assertEquals((double)someTimeAgo.toMillis(), (double)
- // ((FileTime)Files.getAttribute(root, "creationTime")).toMillis(),
- // 2001);
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/316e4a8a/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/TestBundleFileTypeDetector.java
----------------------------------------------------------------------
diff --git a/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/TestBundleFileTypeDetector.java b/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/TestBundleFileTypeDetector.java
deleted file mode 100644
index ca116b0..0000000
--- a/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/TestBundleFileTypeDetector.java
+++ /dev/null
@@ -1,97 +0,0 @@
-package org.apache.taverna.robundle.fs;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.nio.charset.Charset;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Arrays;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
-import org.apache.taverna.robundle.Bundle;
-import org.apache.taverna.robundle.Bundles;
-import org.apache.taverna.robundle.fs.BundleFileTypeDetector;
-import org.junit.Test;
-
-public class TestBundleFileTypeDetector {
- @Test
- public void detectRoBundle() throws Exception {
- BundleFileTypeDetector detector = new BundleFileTypeDetector();
- try (Bundle bundle = Bundles.createBundle()) {
- assertEquals("application/vnd.wf4ever.robundle+zip",
- detector.probeContentType(bundle.getSource()));
- }
- }
-
- @Test
- public void detectEmptyZip() throws Exception {
- BundleFileTypeDetector detector = new BundleFileTypeDetector();
-
- Path zip = Files.createTempFile("test", ".bin");
- zip.toFile().deleteOnExit();
- try (ZipOutputStream zout = new ZipOutputStream(
- Files.newOutputStream(zip))) {
- ZipEntry entry = new ZipEntry("e");
- zout.putNextEntry(entry);
- zout.closeEntry();
-
- }
- assertEquals("application/zip", detector.probeContentType(zip));
- }
-
- @Test
- public void detectNonZip() throws Exception {
- BundleFileTypeDetector detector = new BundleFileTypeDetector();
-
- Path file = Files.createTempFile("test", ".bin");
- file.toFile().deleteOnExit();
- Files.write(file, Arrays.asList("This is just some text",
- "added here to make the file", "larger than 38 bytes"), Charset
- .forName("UTF8"));
- assertTrue(Files.size(file) > 38);
- assertNull(detector.probeContentType(file));
- }
-
- @Test
- public void detectEmpty() throws Exception {
- BundleFileTypeDetector detector = new BundleFileTypeDetector();
-
- Path file = Files.createTempFile("test", ".bin");
- file.toFile().deleteOnExit();
- assertEquals(0, Files.size(file));
- assertNull(detector.probeContentType(file));
- }
-
- @Test
- public void detectorSPI() throws Exception {
- try (Bundle bundle = Bundles.createBundle()) {
- assertEquals("application/vnd.wf4ever.robundle+zip",
- Files.probeContentType(bundle.getSource()));
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/316e4a8a/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/TestBundlePaths.java
----------------------------------------------------------------------
diff --git a/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/TestBundlePaths.java b/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/TestBundlePaths.java
deleted file mode 100644
index 93f3cdb..0000000
--- a/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/TestBundlePaths.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package org.apache.taverna.robundle.fs;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.nio.file.Path;
-
-import org.junit.Test;
-
-public class TestBundlePaths extends Helper {
-
- @Test
- public void endsWith() throws Exception {
- Path root = fs.getRootDirectory();
- Path barBazAbs = root.resolve("bar/baz");
- System.out.println(barBazAbs);
- Path barBaz = root.relativize(barBazAbs);
- assertEquals("bar/baz", barBaz.toString());
- assertTrue(barBaz.endsWith("bar/baz"));
- assertFalse(barBaz.endsWith("bar/../bar/baz"));
- Path climber = barBaz.resolve("../baz");
- assertEquals("bar/baz/../baz", climber.toString());
- assertTrue(climber.endsWith("../baz"));
- assertFalse(climber.endsWith("bar/baz"));
- Path climberNorm = climber.normalize();
- assertFalse(climberNorm.endsWith("../baz"));
- assertTrue(climberNorm.endsWith("bar/baz"));
- }
-
- @Test
- public void parent() throws Exception {
- Path root = fs.getRootDirectory();
- assertNull(root.getParent());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/316e4a8a/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/TestFileSystemProvider.java
----------------------------------------------------------------------
diff --git a/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/TestFileSystemProvider.java b/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/TestFileSystemProvider.java
deleted file mode 100644
index cdbcae4..0000000
--- a/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/TestFileSystemProvider.java
+++ /dev/null
@@ -1,278 +0,0 @@
-package org.apache.taverna.robundle.fs;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.net.URI;
-import java.nio.charset.Charset;
-import java.nio.file.FileSystem;
-import java.nio.file.FileSystems;
-import java.nio.file.Files;
-import java.nio.file.InvalidPathException;
-import java.nio.file.Path;
-import java.nio.file.spi.FileSystemProvider;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.taverna.robundle.fs.BundleFileSystem;
-import org.apache.taverna.robundle.fs.BundleFileSystemProvider;
-import org.junit.Assume;
-import org.junit.Test;
-
-public class TestFileSystemProvider {
-
- @Test
- public void getInstance() throws Exception {
- assertSame(BundleFileSystemProvider.getInstance(),
- BundleFileSystemProvider.getInstance());
- }
-
- @SuppressWarnings("deprecation")
- @Test
- public void getInstanceEquals() throws Exception {
- assertEquals(BundleFileSystemProvider.getInstance(),
- new BundleFileSystemProvider());
- }
-
- @SuppressWarnings("deprecation")
- @Test
- public void getInstanceHashCode() throws Exception {
- assertEquals(BundleFileSystemProvider.getInstance().hashCode(),
- new BundleFileSystemProvider().hashCode());
- }
-
- @SuppressWarnings({ "deprecation", "static-access" })
- @Test
- public void sameOpen() throws Exception {
- assertSame(BundleFileSystemProvider.getInstance().openFilesystems,
- new BundleFileSystemProvider().openFilesystems);
- }
-
- @Test
- public void installedProviders() throws Exception {
- for (FileSystemProvider provider : FileSystemProvider
- .installedProviders()) {
- if (provider instanceof BundleFileSystemProvider) {
- assertSame(provider, BundleFileSystemProvider.getInstance());
- return;
- }
- }
- fail("Could not find BundleFileSystemProvider as installed provider");
- }
-
- @Test
- public void newByURI() throws Exception {
-
- Path path = Files.createTempFile("test", "zip");
- path.toFile().deleteOnExit();
- BundleFileSystemProvider.createBundleAsZip(path, null);
-
- // HACK: Use a opaque version of app: with the file URI as scheme
- // specific part
- URI w = new URI("app", path.toUri().toASCIIString(), null);
- try (FileSystem fs = FileSystems.newFileSystem(w,
- Collections.<String, Object> emptyMap())) {
- assertTrue(fs instanceof BundleFileSystem);
- }
- }
-
- @Test
- public void bundleWithSpaces() throws Exception {
- Path path = Files.createTempFile("with several spaces", ".zip");
- path.toFile().deleteOnExit();
- Files.delete(path);
-
- URI app = new URI("app", path.toUri().toString(), null);
- assertTrue(app.toASCIIString().contains("with%2520several%2520spaces"));
-
- Map<String, Object> env = new HashMap<>();
- env.put("create", "true");
-
- try (FileSystem fs = FileSystems.newFileSystem(app, env)) {
- }
- assertTrue(Files.exists(path));
- // Reopen from now-existing Path to check that the URI is
- // escaped in the same way
- try (FileSystem fs = BundleFileSystemProvider
- .newFileSystemFromExisting(path)) {
- }
- }
-
- @Test
- public void bundleWithSpacesSource() throws Exception {
- Path path = Files.createTempFile("with several spaces", ".zip");
- path.toFile().deleteOnExit();
- Files.delete(path);
-
- try (BundleFileSystem fs = BundleFileSystemProvider
- .newFileSystemFromNew(path)) {
- assertTrue(Files.exists(fs.getSource()));
- assertEquals(path.toAbsolutePath(), fs.getSource());
- }
- assertTrue(Files.exists(path));
- }
-
- @Test
- public void bundleWithUnicode() throws Exception {
- Path path;
- try {
- path = Files.createTempFile("with\u2301unicode\u263bhere", ".zip");
- } catch (InvalidPathException ex) {
- Assume.assumeNoException(
- "Can't test unicode filename, as -Dfile.encoding="
- + System.getProperty("file.encoding"), ex);
- return;
- }
- path.toFile().deleteOnExit();
- Files.delete(path);
- // System.out.println(path); // Should contain a electrical symbol and
- // smiley
- URI app = new URI("app", path.toUri().toString(), null);
- // FIXME: The below passes on Windows 8 but not in Linux!?
- // System.out.println(app);
- // assertTrue(app.toString().contains("\u2301"));
- // assertTrue(app.toString().contains("\u263b"));
-
- Map<String, Object> env = new HashMap<>();
- env.put("create", "true");
-
- try (FileSystem fs = FileSystems.newFileSystem(app, env)) {
- }
- assertTrue(Files.exists(path));
- // Reopen from now-existing Path to check that the URI is
- // escaped in the same way
- try (FileSystem fs = BundleFileSystemProvider
- .newFileSystemFromExisting(path)) {
- }
- }
-
- @Test
- public void newFileSystemFromExisting() throws Exception {
- Path path = Files.createTempFile("test", null);
- path.toFile().deleteOnExit();
- Files.delete(path);
- // Make the Bundle first
- BundleFileSystemProvider.createBundleAsZip(path, "application/x-test");
- assertTrue(Files.exists(path));
-
- try (BundleFileSystem f = BundleFileSystemProvider
- .newFileSystemFromExisting(path)) {
- assertEquals(path, f.getSource());
- assertEquals(
- "application/x-test",
- Files.readAllLines(
- f.getRootDirectory().resolve("mimetype"),
- Charset.forName("ASCII")).get(0));
- }
- }
-
- @Test
- public void newFileSystemFromExistingPath() throws Exception {
- Path path = Files.createTempFile("test", null);
- path.toFile().deleteOnExit();
- Files.delete(path);
- // Make the Bundle first as we can't pass inn create=true :/
- BundleFileSystemProvider.createBundleAsZip(path, "application/x-test");
- assertTrue(Files.exists(path));
-
- try (FileSystem fs = FileSystems.newFileSystem(path, getClass()
- .getClassLoader())) {
- assertEquals(
- "application/x-test",
- Files.readAllLines(fs.getPath("mimetype"),
- Charset.forName("ASCII")).get(0));
- }
- }
-
- @Test
- public void newFileSystemFromNewDefaultMime() throws Exception {
- Path path = Files.createTempFile("test", null);
- path.toFile().deleteOnExit();
- Files.delete(path);
- BundleFileSystem f = BundleFileSystemProvider
- .newFileSystemFromNew(path);
- assertTrue(Files.exists(path));
- assertEquals(path, f.getSource());
- assertEquals(
- "application/vnd.wf4ever.robundle+zip",
- Files.readAllLines(f.getRootDirectory().resolve("mimetype"),
- Charset.forName("ASCII")).get(0));
- }
-
- @Test
- public void newFileSystemURI() throws Exception {
- Path path = Files.createTempFile("test", null);
- path.toFile().deleteOnExit();
- Files.delete(path);
-
- URI uri = new URI("app", path.toUri().toASCIIString(), (String) null);
-
- Map<String, String> env = new HashMap<>();
- env.put("create", "true");
- // And the optional mimetype
- env.put("mimetype", "application/x-test2");
- FileSystem f = FileSystems.newFileSystem(uri, env, getClass()
- .getClassLoader());
- assertTrue(Files.exists(path));
- assertEquals(
- "application/x-test2",
- Files.readAllLines(f.getPath("mimetype"),
- Charset.forName("ASCII")).get(0));
- }
-
- @Test
- public void newFileSystemFromNew() throws Exception {
- Path path = Files.createTempFile("test", null);
- path.toFile().deleteOnExit();
- Files.delete(path);
- path.toUri();
- BundleFileSystem f = BundleFileSystemProvider.newFileSystemFromNew(
- path, "application/x-test2");
- assertTrue(Files.exists(path));
- assertEquals(path, f.getSource());
- assertEquals(
- "application/x-test2",
- Files.readAllLines(f.getRootDirectory().resolve("mimetype"),
- Charset.forName("ASCII")).get(0));
- }
-
- @Test
- public void newFileSystemFromTemporary() throws Exception {
- Path source;
- try (BundleFileSystem f = BundleFileSystemProvider
- .newFileSystemFromTemporary()) {
- source = f.getSource();
- assertTrue(Files.exists(source));
- assertEquals(
- "application/vnd.wf4ever.robundle+zip",
- Files.readAllLines(
- f.getRootDirectory().resolve("mimetype"),
- Charset.forName("ASCII")).get(0));
- }
- Files.delete(source);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/316e4a8a/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/TestZipFS.java
----------------------------------------------------------------------
diff --git a/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/TestZipFS.java b/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/TestZipFS.java
deleted file mode 100644
index 95939a8..0000000
--- a/taverna-robundle/src/test/java/org/apache/taverna/robundle/fs/TestZipFS.java
+++ /dev/null
@@ -1,213 +0,0 @@
-package org.apache.taverna.robundle.fs;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.io.IOException;
-import java.net.URI;
-import java.nio.channels.FileChannel;
-import java.nio.file.DirectoryStream;
-import java.nio.file.FileAlreadyExistsException;
-import java.nio.file.FileSystem;
-import java.nio.file.FileSystems;
-import java.nio.file.Files;
-import java.nio.file.NoSuchFileException;
-import java.nio.file.Path;
-import java.nio.file.StandardOpenOption;
-import java.nio.file.attribute.FileTime;
-import java.util.ArrayList;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-public class TestZipFS {
-
- private static Path zip;
- private FileSystem fs;
-
- @Test
- public void fileChannelCreateNew() throws Exception {
- Path test = fs.getPath("test.txt");
- EnumSet<StandardOpenOption> options = EnumSet.<StandardOpenOption> of(
- StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE);
- fs.provider().newFileChannel(test, options);
- }
-
- @Test
- public void fileChannelCreate() throws Exception {
- try {
- Path test = fs.getPath("test.txt");
- FileChannel.open(test, StandardOpenOption.WRITE,
- StandardOpenOption.CREATE).close();
- } catch (NoSuchFileException ex) {
- System.err.println("Unexpected exception");
- ex.printStackTrace();
- // Bug in JDK
- }
- }
-
- @Test(expected = FileAlreadyExistsException.class)
- public void fileChannelCreateFails() throws Exception {
- Path test = fs.getPath("test.txt");
- Files.createFile(test);
- FileChannel.open(test, StandardOpenOption.WRITE,
- StandardOpenOption.CREATE_NEW).close();
- }
-
- @Test
- public void fileChannelTruncate() throws Exception {
- Path test = fs.getPath("test.txt");
- Files.write(test, new byte[1024]);
- assertEquals(1024, Files.size(test));
- FileChannel.open(test, StandardOpenOption.WRITE,
- StandardOpenOption.TRUNCATE_EXISTING).close();
- assertEquals(0, Files.size(test));
- }
-
- /**
- * Verifies http://stackoverflow.com/questions/16588321/ as both ZIP format
- * and Java 7 ZIPFS allows a folder and file to have the same name.
- *
- */
- @Test
- public void directoryOrFile() throws Exception {
- Path folder = fs.getPath("folder");
- assertFalse(Files.exists(folder));
- Files.createFile(folder);
- assertTrue(Files.exists(folder));
- assertTrue(Files.isRegularFile(folder));
- assertFalse(Files.isDirectory(folder));
-
- try {
- Path folderCreated = Files.createDirectory(folder);
- assertEquals(folder, folderCreated);
- folder = folderCreated;
- System.out.println(folder + " " + folderCreated);
-
- // Disable for now, just to see where this leads
- // fail("Should have thrown FileAlreadyExistsException");
- } catch (FileAlreadyExistsException ex) {
- }
-
- // For some reason the second createDirectory() fails correctly
- try {
- Files.createDirectory(folder);
- fail("Should have thrown FileAlreadyExistsException");
- } catch (FileAlreadyExistsException ex) {
- }
-
- Path child = folder.resolve("child");
- Files.createFile(child);
-
- // Look, it's both a file and folder!
- // Can this be asserted?
- assertTrue(Files.isRegularFile(folder));
- // Yes, if you include the final /
- assertTrue(Files.isDirectory(fs.getPath("folder/")));
- // But not the parent
- // assertTrue(Files.isDirectory(child.getParent()));
- // Or the original Path
- // assertTrue(Files.isDirectory(folder));
-
- fs.close();
- // What if we open it again.. can we find both?
- try (FileSystem fs2 = FileSystems.newFileSystem(zip, null)) {
- assertTrue(Files.isRegularFile(fs2.getPath("folder")));
- assertTrue(Files.isRegularFile(fs2.getPath("folder/child")));
- assertTrue(Files.isDirectory(fs2.getPath("folder/")));
-
- // We can even list the folder
- try (DirectoryStream<Path> s = Files.newDirectoryStream(fs2
- .getPath("folder/"))) {
- boolean found = false;
- for (Path p : s) {
- found = p.endsWith("child");
- }
- assertTrue("Did not find 'child'", found);
- }
- // But if we list the root, do we find "folder" or "folder/"?
- Path root = fs2.getRootDirectories().iterator().next();
- try (DirectoryStream<Path> s = Files.newDirectoryStream(root)) {
- List<String> paths = new ArrayList<>();
- for (Path p : s) {
- paths.add(p.toString());
- }
- // We find both!
- assertEquals(2, paths.size());
- assertTrue(paths.contains("/folder"));
- assertTrue(paths.contains("/folder/"));
- }
- // SO does that mean this is a feature, and not a bug?
- // See http://stackoverflow.com/questions/16588321/ for more
- }
-
- }
-
- @Test
- public void setLastModifiedTime() throws Exception {
- Path root = fs.getRootDirectories().iterator().next();
-
- Path folder = root.resolve("folder");
- Files.createDirectory(folder);
-
- Path file = root.resolve("file");
- Files.createFile(file);
-
- FileTime someTimeAgo = FileTime.from(365 * 12, TimeUnit.DAYS);
- Files.setLastModifiedTime(folder, someTimeAgo);
- Files.setLastModifiedTime(file, someTimeAgo);
- try {
- Files.setLastModifiedTime(root, someTimeAgo);
- } catch (NoSuchFileException ex) {
- System.err
- .println("Unexpected failure of setLastModifiedTime on root");
- ex.printStackTrace();
- }
- }
-
- @Before
- public void tempZipFS() throws Exception {
- zip = Files.createTempFile("test", ".zip");
- Files.delete(zip);
- System.out.println(zip);
- URI jar = new URI("jar", zip.toUri().toString(), null);
- Map<String, Object> env = new HashMap<>();
- env.put("create", "true");
- fs = FileSystems.newFileSystem(jar, env);
- }
-
- @After
- public void deleteTempFS() throws IOException {
- fs.close();
- Files.deleteIfExists(zip);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/316e4a8a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/TestManifest.java
----------------------------------------------------------------------
diff --git a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/TestManifest.java b/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/TestManifest.java
deleted file mode 100644
index 3ca4030..0000000
--- a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/TestManifest.java
+++ /dev/null
@@ -1,280 +0,0 @@
-package org.apache.taverna.robundle.manifest;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-
-import org.apache.taverna.robundle.Bundle;
-import org.apache.taverna.robundle.Bundles;
-import org.apache.taverna.robundle.manifest.Manifest;
-import org.apache.taverna.robundle.manifest.PathMetadata;
-import org.apache.taverna.robundle.manifest.RDFToManifest;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.hp.hpl.jena.query.Query;
-import com.hp.hpl.jena.query.QueryExecution;
-import com.hp.hpl.jena.query.QueryExecutionFactory;
-import com.hp.hpl.jena.query.QueryFactory;
-import com.hp.hpl.jena.query.QuerySolution;
-import com.hp.hpl.jena.query.ResultSet;
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.rdf.model.Resource;
-
-@SuppressWarnings({ "deprecation", "unused" })
-public class TestManifest {
- private Bundle bundle;
-
- @Test
- public void populateFromBundle() throws Exception {
- Path r = bundle.getRoot();
- URI base = r.toUri();
-
- Manifest manifest = new Manifest(bundle);
- manifest.populateFromBundle();
-
- List<String> uris = new ArrayList<>();
- for (PathMetadata s : manifest.getAggregates()) {
- uris.add(s.getFile().toString());
- Path path = s.getFile();
- assertNotNull(path.getParent());
- assertEquals(Manifest.withSlash(path.getParent()), s.getFolder());
- if (s.getFile().equals(URI.create("/f/nested/empty/"))) {
- continue;
- // Folder's don't need proxy and createdOn
- }
- assertEquals("urn", s.getProxy().getScheme());
- UUID.fromString(s.getProxy().getSchemeSpecificPart()
- .replace("uuid:", ""));
- assertEquals(s.getCreatedOn(), Files.getLastModifiedTime(path));
- }
- //System.out.println(uris);
- assertFalse(uris.contains("/mimetype"));
- assertFalse(uris.contains("/META-INF"));
- assertTrue(uris.remove("/hello.txt"));
- assertTrue(uris.remove("/f/file1.txt"));
- assertTrue(uris.remove("/f/file2.txt"));
- assertTrue(uris.remove("/f/file3.txt"));
- assertTrue(uris.remove("/f/nested/file1.txt"));
- assertTrue(uris.remove("/f/nested/empty/"));
- assertTrue(uris.isEmpty());
- }
-
- @Test
- public void repopulateFromBundle() throws Exception {
- Path r = bundle.getRoot();
- URI base = r.toUri();
-
- Manifest manifest = new Manifest(bundle);
- manifest.populateFromBundle();
- // Second populate should not add additional entries
- manifest.populateFromBundle();
-
- List<String> uris = new ArrayList<>();
- for (PathMetadata s : manifest.getAggregates()) {
- uris.add(s.getFile().toString());
- Path path = s.getFile();
- assertNotNull(path.getParent());
- assertEquals(Manifest.withSlash(path.getParent()), s.getFolder());
- if (s.getFile().equals(URI.create("/f/nested/empty/"))) {
- continue;
- // Folder's don't need proxy and createdOn
- }
- assertEquals("urn", s.getProxy().getScheme());
- UUID.fromString(s.getProxy().getSchemeSpecificPart()
- .replace("uuid:", ""));
- assertEquals(s.getCreatedOn(), Files.getLastModifiedTime(path));
- }
- //System.out.println(uris);
- assertFalse(uris.contains("/mimetype"));
- assertFalse(uris.contains("/META-INF"));
- assertTrue(uris.remove("/hello.txt"));
- assertTrue(uris.remove("/f/file1.txt"));
- assertTrue(uris.remove("/f/file2.txt"));
- assertTrue(uris.remove("/f/file3.txt"));
- assertTrue(uris.remove("/f/nested/file1.txt"));
- assertTrue(uris.remove("/f/nested/empty/"));
- assertTrue("Unexpected uri: " + uris, uris.isEmpty());
- }
-
- private Path uri2path(URI base, URI uri) {
- URI fileUri = base.resolve(uri);
- return Paths.get(fileUri);
- }
-
- @Test
- public void writeAsJsonLD() throws Exception {
- Manifest manifest = new Manifest(bundle);
- manifest.populateFromBundle();
- PathMetadata helloMeta = null;
- for (PathMetadata meta : manifest.getAggregates()) {
- if (meta.getFile().endsWith("hello.txt")) {
- helloMeta = meta;
- }
- }
- assertNotNull("No metadata for </hello.txt>", helloMeta);
-
- Path jsonld = manifest.writeAsJsonLD();
- assertEquals(bundle.getFileSystem().getPath("/.ro", "manifest.json"),
- jsonld);
- assertTrue(Files.exists(jsonld));
- String manifestStr = new String(Files.readAllBytes(jsonld), "UTF8");
- //System.out.println(manifestStr);
-
- // Rough and ready that somethings are there
- // TODO: Read back and check as JSON structure
- // TODO: Check as JSON-LD graph
- assertTrue(manifestStr.contains("@context"));
- assertTrue(manifestStr.contains("https://w3id.org/bundle/context"));
- assertTrue(manifestStr.contains("/f/file2.txt"));
- assertTrue(manifestStr.contains("/hello.txt"));
- assertTrue(manifestStr.contains(helloMeta.getProxy().toASCIIString()));
-
- // Parse back as JSON-LD
- try (InputStream jsonIn = Files.newInputStream(jsonld)) {
- URI baseURI = jsonld.toUri();
- Model model = RDFToManifest.jsonLdAsJenaModel(jsonIn, baseURI);
- model.write(new ByteArrayOutputStream(), "TURTLE", baseURI.toString());
- model.write(new ByteArrayOutputStream(), "RDF/XML", baseURI.toString());
-
- String queryStr = "PREFIX ore: <http://www.openarchives.org/ore/terms/>"
- + "PREFIX bundle: <http://purl.org/wf4ever/bundle#>"
- + "SELECT ?file ?proxy "
- + "WHERE {"
- + " ?ro ore:aggregates ?file ."
- + " OPTIONAL { ?file bundle:bundledAs ?proxy . } " + "}";
- Query query = QueryFactory.create(queryStr);
- QueryExecution qexec = QueryExecutionFactory.create(query, model);
-
- try {
- ResultSet results = qexec.execSelect();
- int aggregationCount = 0;
- for (; results.hasNext(); aggregationCount++) {
- QuerySolution soln = results.nextSolution();
- Resource fileRes = soln.getResource("file");
- Resource proxy = soln.getResource("proxy");
- //System.out.println("File: " + fileRes);
- //System.out.println(asURI(fileRes));
-
- Path file = Paths.get(asURI(fileRes));
- assertTrue(Files.exists(file));
- PathMetadata meta = manifest.getAggregation(file);
- assertEquals(meta.getProxy(), asURI(proxy));
- }
- assertEquals("Could not find all aggregations from manifest: "
- + manifest.getAggregates(), manifest.getAggregates()
- .size(), aggregationCount);
- } finally {
- // WHY is not QueryExecution an instance of Closable?
- qexec.close();
- }
- }
- }
-
- @Test
- public void readManifest() throws Exception {
- Manifest manifest = new Manifest(bundle);
-
- new RDFToManifest().readTo(
- getClass().getResourceAsStream("/manifest.json"), manifest,
- manifest.getBaseURI().resolve("does/not/exist"));
-
- Path r = bundle.getRoot();
- assertNotNull(manifest.getAggregation(r.resolve("/README.txt")));
- PathMetadata readme = manifest.getAggregation(r.resolve("/README.txt"));
- assertEquals("http://example.com/foaf#bob", readme.getCreatedBy()
- .getUri().toString());
- assertEquals("Bob Builder",
- manifest.getAggregation(r.resolve("/README.txt"))
- .getCreatedBy().getName());
- assertEquals("text/plain",
- manifest.getAggregation(r.resolve("/README.txt"))
- .getMediatype());
-
- assertNull(manifest.getAggregation(r.resolve("/README.txt"))
- .getBundledAs());
-
- // Disabled: RO Bundle in flux on how to put external URIs in folders
- // assertNotNull(manifest.getAggregation(
- // URI.create("http://example.com/comments.txt")).getProxy());
-
- //System.out.println(manifest.getAnnotations());
-
- assertEquals(3, manifest.getAnnotations().size());
-
- }
-
- private URI asURI(Resource proxy) {
- if (proxy == null) {
- return null;
- }
- String uri = proxy.getURI();
- if (uri == null) {
- return null;
- }
- return bundle.getRoot().toUri().resolve(uri);
- }
-
- @Before
- public void exampleBundle() throws IOException {
- Path source;
- try (Bundle bundle = Bundles.createBundle()) {
- source = bundle.getSource();
- Path r = bundle.getRoot();
- Files.createFile(r.resolve("hello.txt"));
- Path f = r.resolve("f");
- Files.createDirectory(f);
- Files.createFile(f.resolve("file3.txt"));
- Files.createFile(f.resolve("file2.txt"));
- Files.createFile(f.resolve("file1.txt"));
-
- Path nested = f.resolve("nested");
- Files.createDirectory(nested);
- Files.createFile(nested.resolve("file1.txt"));
-
- Files.createDirectory(nested.resolve("empty"));
- bundle.setDeleteOnClose(false);
- }
- bundle = Bundles.openBundle(source);
- }
-
- @After
- public void closeBundle() throws IOException {
- bundle.close();
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/316e4a8a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/TestManifestJSON.java
----------------------------------------------------------------------
diff --git a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/TestManifestJSON.java b/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/TestManifestJSON.java
deleted file mode 100644
index efab8a9..0000000
--- a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/TestManifestJSON.java
+++ /dev/null
@@ -1,275 +0,0 @@
-package org.apache.taverna.robundle.manifest;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.net.URI;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.attribute.FileTime;
-import java.util.Calendar;
-import java.util.Locale;
-import java.util.TimeZone;
-
-import org.apache.taverna.robundle.Bundle;
-import org.apache.taverna.robundle.Bundles;
-import org.apache.taverna.robundle.manifest.Agent;
-import org.apache.taverna.robundle.manifest.Manifest;
-import org.apache.taverna.robundle.manifest.PathAnnotation;
-import org.apache.taverna.robundle.manifest.PathMetadata;
-import org.junit.Test;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-public class TestManifestJSON {
- @Test
- public void createBundle() throws Exception {
- // Create bundle as in Example 3 of the specification
- // http://wf4ever.github.io/ro/bundle/2013-05-21/
- try (Bundle bundle = Bundles.createBundle()) {
- Calendar createdOnCal = Calendar.getInstance(
- TimeZone.getTimeZone("Z"), Locale.ENGLISH);
- // "2013-03-05T17:29:03Z"
- // Remember months are 0-based in java.util.Calendar!
- createdOnCal.set(2013, 3 - 1, 5, 17, 29, 03);
- createdOnCal.set(Calendar.MILLISECOND, 0);
- FileTime createdOn = FileTime.fromMillis(createdOnCal
- .getTimeInMillis());
- Manifest manifest = bundle.getManifest();
- manifest.setCreatedOn(createdOn);
- Agent createdBy = new Agent("Alice W. Land");
- createdBy.setUri(URI.create("http://example.com/foaf#alice"));
- createdBy.setOrcid(URI
- .create("http://orcid.org/0000-0002-1825-0097"));
-
- manifest.setCreatedBy(createdBy);
-
- Path evolutionPath = bundle.getPath(".ro/evolution.ttl");
- Files.createDirectories(evolutionPath.getParent());
- Bundles.setStringValue(
- evolutionPath,
- "<manifest.json> < http://purl.org/pav/retrievedFrom> "
- + "<http://wf4ever.github.io/ro/bundle/2013-05-21/example/.ro/manifest.json> .");
- manifest.getHistory().add(evolutionPath);
-
- Path jpeg = bundle.getPath("folder/soup.jpeg");
- Files.createDirectory(jpeg.getParent());
- Files.createFile(jpeg);
- // register in manifest first
- bundle.getManifest().getAggregation(jpeg);
-
- URI blog = URI.create("http://example.com/blog/");
- bundle.getManifest().getAggregation(blog);
-
- Path readme = bundle.getPath("README.txt");
- Files.createFile(readme);
- PathMetadata readmeMeta = bundle.getManifest().getAggregation(
- readme);
- readmeMeta.setMediatype("text/plain");
- Agent readmeCreatedby = new Agent("Bob Builder");
- readmeCreatedby.setUri(URI.create("http://example.com/foaf#bob"));
- readmeMeta.setCreatedBy(readmeCreatedby);
-
- // 2013-02-12T19:37:32.939Z
- createdOnCal.set(2013, 2 - 1, 12, 19, 37, 32);
- createdOnCal.set(Calendar.MILLISECOND, 939);
- createdOn = FileTime.fromMillis(createdOnCal.getTimeInMillis());
- Files.setLastModifiedTime(readme, createdOn);
- readmeMeta.setCreatedOn(createdOn);
-
- PathMetadata comments = bundle.getManifest().getAggregation(
- URI.create("http://example.com/comments.txt"));
- comments.getOrCreateBundledAs()
- .setURI(URI
- .create("urn:uuid:a0cf8616-bee4-4a71-b21e-c60e6499a644"));
- comments.getOrCreateBundledAs().setFolder(
- bundle.getPath("/folder/"));
- comments.getOrCreateBundledAs().setFilename("external.txt");
-
- PathAnnotation jpegAnn = new PathAnnotation();
- jpegAnn.setAbout(jpeg);
- Path soupProps = Bundles.getAnnotations(bundle).resolve(
- "soup-properties.ttl");
- Bundles.setStringValue(soupProps,
- "</folder/soup.jpeg> <http://xmlns.com/foaf/0.1/depicts> "
- + "<http://example.com/menu/tomato-soup> .");
- jpegAnn.setContent(soupProps);
- // jpegAnn.setContent(URI.create("annotations/soup-properties.ttl"));
- jpegAnn.setUri(URI
- .create("urn:uuid:d67466b4-3aeb-4855-8203-90febe71abdf"));
- manifest.getAnnotations().add(jpegAnn);
-
- PathAnnotation proxyAnn = new PathAnnotation();
- proxyAnn.setAbout(comments.getBundledAs().getURI());
- proxyAnn.setContent(URI
- .create("http://example.com/blog/they-aggregated-our-file"));
- manifest.getAnnotations().add(proxyAnn);
-
- Path metaAnn = Bundles.getAnnotations(bundle).resolve(
- "a-meta-annotation-in-this-ro.txt");
- Bundles.setStringValue(metaAnn,
- "This bundle contains an annotation about /folder/soup.jpeg");
-
- PathAnnotation metaAnnotation = new PathAnnotation();
- metaAnnotation.setAbout(bundle.getRoot());
- metaAnnotation
- .getAboutList()
- .add(URI.create("urn:uuid:d67466b4-3aeb-4855-8203-90febe71abdf"));
-
- metaAnnotation.setContent(metaAnn);
- manifest.getAnnotations().add(metaAnnotation);
-
- Path jsonPath = bundle.getManifest().writeAsJsonLD();
- ObjectMapper objectMapper = new ObjectMapper();
- String jsonStr = Bundles.getStringValue(jsonPath);
- //System.out.println(jsonStr);
- JsonNode json = objectMapper.readTree(jsonStr);
- checkManifestJson(json);
- }
- }
-
- public void checkManifestJson(JsonNode json) {
- JsonNode context = json.get("@context");
- assertNotNull("Could not find @context", context);
- assertTrue("@context SHOULD be an array", context.isArray());
- assertTrue("@context SHOULD include a context", context.size() > 0);
- JsonNode lastContext = context.get(context.size() - 1);
- assertEquals(
- "@context SHOULD include https://w3id.org/bundle/context as last item",
- "https://w3id.org/bundle/context", lastContext.asText());
-
- assertEquals("/", json.get("id").asText());
-
- JsonNode manifest = json.get("manifest");
- if (manifest.isValueNode()) {
- assertEquals(
- "manifest SHOULD be literal value \"manifest.json\" or list",
- "manifest.json", manifest.asText());
- } else {
- assertTrue("manifest is neither literal or list",
- manifest.isArray());
- boolean found = false;
- for (JsonNode n : manifest) {
- found = n.asText().equals("manifest.json");
- if (found) {
- break;
- }
- }
- ;
- assertTrue("Could not find 'manifest.json' in 'manifest' list: "
- + manifest, found);
- }
-
- assertEquals("2013-03-05T17:29:03Z", json.get("createdOn").asText());
- JsonNode createdBy = json.get("createdBy");
- assertNotNull("Could not find createdBy", createdBy);
- assertEquals("http://example.com/foaf#alice", createdBy.get("uri")
- .asText());
- assertEquals("http://orcid.org/0000-0002-1825-0097",
- createdBy.get("orcid").asText());
- assertEquals("Alice W. Land", createdBy.get("name").asText());
-
- JsonNode history = json.get("history");
- if (history.isValueNode()) {
- assertEquals("evolution.ttl", history.asText());
- } else {
- assertEquals("evolution.ttl", history.get(0).asText());
- }
-
- JsonNode aggregates = json.get("aggregates");
- assertTrue("aggregates not a list", aggregates.isArray());
- JsonNode soup = aggregates.get(0);
- if (soup.isValueNode()) {
- assertEquals("/folder/soup.jpeg", soup.asText());
- } else {
- assertEquals("/folder/soup.jpeg", soup.get("uri").asText());
- }
-
- JsonNode blog = aggregates.get(1);
- if (blog.isValueNode()) {
- assertEquals("http://example.com/blog/", blog.asText());
- } else {
- assertEquals("http://example.com/blog/", blog.get("uri").asText());
- }
-
- JsonNode readme = aggregates.get(2);
- assertEquals("/README.txt", readme.get("uri").asText());
- assertEquals("text/plain", readme.get("mediatype").asText());
- assertEquals("2013-02-12T19:37:32.939Z", readme.get("createdOn")
- .asText());
- JsonNode readmeCreatedBy = readme.get("createdBy");
- assertEquals("http://example.com/foaf#bob", readmeCreatedBy.get("uri")
- .asText());
- assertEquals("Bob Builder", readmeCreatedBy.get("name").asText());
-
- JsonNode comments = aggregates.get(3);
- assertEquals("http://example.com/comments.txt", comments.get("uri")
- .asText());
- JsonNode bundledAs = comments.get("bundledAs");
- assertEquals("urn:uuid:a0cf8616-bee4-4a71-b21e-c60e6499a644", bundledAs
- .get("uri").asText());
- assertEquals("/folder/", bundledAs.get("folder").asText());
- assertEquals("external.txt", bundledAs.get("filename").asText());
-
- JsonNode annotations = json.get("annotations");
- assertTrue("annotations MUST be a list", annotations.isArray());
-
- JsonNode ann0 = annotations.get(0);
- assertEquals("urn:uuid:d67466b4-3aeb-4855-8203-90febe71abdf",
- ann0.get("uri").asText());
- assertEquals("/folder/soup.jpeg", ann0.get("about").asText());
- assertEquals("annotations/soup-properties.ttl", ann0.get("content")
- .asText());
-
- JsonNode ann1 = annotations.get(1);
- assertNull(ann1.get("annotation"));
- assertEquals("urn:uuid:a0cf8616-bee4-4a71-b21e-c60e6499a644",
- ann1.get("about").asText());
- assertEquals("http://example.com/blog/they-aggregated-our-file", ann1
- .get("content").asText());
-
- JsonNode ann2 = annotations.get(2);
- assertNull(ann2.get("annotation"));
- JsonNode about = ann2.get("about");
- assertTrue("about was not a list", about.isArray());
- assertEquals("/", about.get(0).asText());
- assertEquals("urn:uuid:d67466b4-3aeb-4855-8203-90febe71abdf", about
- .get(1).asText());
- assertEquals("annotations/a-meta-annotation-in-this-ro.txt",
- ann2.get("content").asText());
-
- }
-
- @Test
- public void checkJsonFromSpec() throws Exception {
- // Verify that our test confirms the existing spec example
- ObjectMapper objectMapper = new ObjectMapper();
- JsonNode json = objectMapper.readTree(getClass().getResource(
- "/manifest.json"));
- checkManifestJson(json);
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/316e4a8a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/TestRDFToManifest.java
----------------------------------------------------------------------
diff --git a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/TestRDFToManifest.java b/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/TestRDFToManifest.java
deleted file mode 100644
index 2557973..0000000
--- a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/TestRDFToManifest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package org.apache.taverna.robundle.manifest;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-import static org.junit.Assert.assertNotNull;
-
-import java.net.URL;
-import java.util.Map;
-
-import org.junit.Test;
-
-import com.github.jsonldjava.core.DocumentLoader;
-
-//import com.github.jsonldjava.core.DocumentLoader;
-
-public class TestRDFToManifest {
- private static final String CONTEXT = "https://w3id.org/bundle/context";
-
- @Test
- public void contextLoadedFromJarCache() throws Exception {
- // RDFToManifest.makeBaseURI(); // trigger static{} block
- @SuppressWarnings("unchecked")
- Map<String, Object> context = (Map<String, Object>) new DocumentLoader()
- .fromURL(new URL(CONTEXT));
- // FIXME: jsonld-java 0.3 and later uses DocumentLoader instead of
- // JSONUtils
- // Map<String, Object> context = (Map<String, Object>)
- // JSONUtils.fromURL(new URL(CONTEXT));
- Object retrievedFrom = context.get("http://purl.org/pav/retrievedFrom");
- assertNotNull("Did not load context from cache: " + CONTEXT,
- retrievedFrom);
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/316e4a8a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/combine/TestCombineManifest.java
----------------------------------------------------------------------
diff --git a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/combine/TestCombineManifest.java b/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/combine/TestCombineManifest.java
deleted file mode 100644
index 5286d67..0000000
--- a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/combine/TestCombineManifest.java
+++ /dev/null
@@ -1,155 +0,0 @@
-package org.apache.taverna.robundle.manifest.combine;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.io.InputStream;
-import java.net.URI;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.StandardCopyOption;
-
-import org.apache.taverna.robundle.Bundle;
-import org.apache.taverna.robundle.Bundles;
-import org.apache.taverna.robundle.manifest.Agent;
-import org.apache.taverna.robundle.manifest.Manifest;
-import org.apache.taverna.robundle.manifest.PathMetadata;
-import org.junit.Test;
-
-public class TestCombineManifest {
- @Test
- public void convertAslanidi() throws Exception {
- Path file = Files.createTempFile("aslanidi", ".zip");
- try (InputStream src = getClass().getResourceAsStream(
- "/combine/aslanidi_purkinje_model_2009.zip")) {
- Files.copy(src, file, StandardCopyOption.REPLACE_EXISTING);
- }
- System.out.println(file);
- try (Bundle bundle = Bundles.openBundle(file)) {
- Manifest manifest = bundle.getManifest();
- Path manifestXml = bundle.getRoot().resolve("manifest.xml");
- assertTrue("manifest.xml not listed in " + manifest.getManifest(),
- manifest.getManifest().contains(manifestXml));
-
- // List<Agent> manifestCreator = manifest.getCreatedBy();
- // Agent createdBy = manifestCreator.get(0);
- // assertEquals("Gary Mirams", createdBy.getName());
- // assertEquals("mbox:gary.mirams@cs.ox.ac.uk", createdBy.getUri());
- // assertEquals("2014-02-06T22:01:58Z",
- // manifest.getCreatedOn().toString());
- //
- Path csvPath = bundle.getRoot().resolve(
- "outputs_degree_of_block.csv");
- PathMetadata csv = manifest.getAggregation(csvPath);
- assertEquals("text/csv", csv.getMediatype());
- Agent csvCreator = csv.getCreatedBy();
- assertEquals("Gary Mirams", csvCreator.getName());
- assertEquals("mbox:gary.mirams@cs.ox.ac.uk", csvCreator.getUri()
- .toString());
- assertEquals("2014-02-06T22:01:58Z", csv.getCreatedOn().toString());
-
- }
- }
-
- @Test
- public void convertBoris() throws Exception {
- Path file = Files.createTempFile("Boris", ".omex");
- try (InputStream src = getClass().getResourceAsStream(
- "/combine/Boris.omex")) {
- Files.copy(src, file, StandardCopyOption.REPLACE_EXISTING);
- }
- //System.out.println(file);
- try (Bundle bundle = Bundles.openBundle(file)) {
- Manifest manifest = bundle.getManifest();
- Path manifestXml = bundle.getRoot().resolve("manifest.xml");
- assertTrue("manifest.xml not listed in " + manifest.getManifest(),
- manifest.getManifest().contains(manifestXml));
-
- assertEquals("2013-05-28T16:50:43.999Z", manifest.getCreatedOn()
- .toString());
-
- // Can't test these - as Boris.omex manifest.xml only
- // list these as unconnected bnodes
- // List<Agent> manifestCreator = manifest.getCreatedBy();
- // Agent createdBy = manifestCreator.get(0);
- // assertEquals("Frank Bergmann", createdBy.getName());
- // assertEquals("mbox:fbergman@caltech.edu", createdBy.getUri());
- //
- }
-
- }
-
- @Test
- public void convertDirectoryMadness() throws Exception {
- Path file = Files.createTempFile("DirectoryMadness", ".omex");
- try (InputStream src = getClass().getResourceAsStream(
- "/combine/DirectoryMadness.omex")) {
- Files.copy(src, file, StandardCopyOption.REPLACE_EXISTING);
- }
- //System.out.println(file);
- try (Bundle bundle = Bundles.openBundle(file)) {
- Manifest manifest = bundle.getManifest();
- Path manifestXml = bundle.getRoot().resolve("manifest.xml");
- assertTrue("manifest.xml not listed in " + manifest.getManifest(),
- manifest.getManifest().contains(manifestXml));
-
- Path boris = bundle.getRoot().resolve("BorisEJB.xml");
- PathMetadata borisMeta = bundle.getManifest().getAggregation(boris);
- assertEquals(
- URI.create("http://identifiers.org/combine.specifications/sbml"),
- borisMeta.getConformsTo());
- // dcterms:modified
- assertEquals("2013-04-05T12:50:56Z", borisMeta.getCreatedOn()
- .toString());
-
- Path paperPdf = bundle.getRoot().resolve("paper")
- .resolve("Kholodenko2000.pdf");
- PathMetadata paperMeta = bundle.getManifest().getAggregation(
- paperPdf);
- assertEquals("application/pdf", paperMeta.getMediatype());
-
- URI biomd = URI
- .create("http://www.ebi.ac.uk/biomodels-main/BIOMD0000000010");
- PathMetadata biomdMeta = bundle.getManifest().getAggregation(biomd);
- assertEquals(
- URI.create("http://identifiers.org/combine.specifications/sbml"),
- biomdMeta.getConformsTo());
-
- }
-
- }
-
- @Test
- public void convertDirectoryMadnessZipped() throws Exception {
- Path file = Files.createTempFile("DirectoryMadnessZipped", ".omex");
- try (InputStream src = getClass().getResourceAsStream(
- "/combine/DirectoryMadnessZipped.omex")) {
- Files.copy(src, file, StandardCopyOption.REPLACE_EXISTING);
- }
- //System.out.println(file);
- try (Bundle bundle = Bundles.openBundle(file)) {
-
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/316e4a8a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/odf/TestODFManifest.java
----------------------------------------------------------------------
diff --git a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/odf/TestODFManifest.java b/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/odf/TestODFManifest.java
deleted file mode 100644
index 539c289..0000000
--- a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/odf/TestODFManifest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package org.apache.taverna.robundle.manifest.odf;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.net.URL;
-import java.nio.file.Files;
-import java.nio.file.Path;
-
-import org.apache.taverna.robundle.Bundle;
-import org.apache.taverna.robundle.Bundles;
-import org.apache.taverna.robundle.manifest.Manifest;
-import org.apache.taverna.robundle.manifest.PathMetadata;
-import org.junit.Test;
-
-public class TestODFManifest {
- @Test
- public void openHelloWorld() throws Exception {
- URL helloworld = getClass().getResource("/helloworld.wfbundle");
- assertNotNull(helloworld);
- try (Bundle bundle = Bundles.openBundle(helloworld)) {
- assertEquals("application/vnd.taverna.scufl2.workflow-bundle",
- Bundles.getMimeType(bundle));
- Path t2flow = bundle
- .getPath("history/8781d5f4-d0ba-48a8-a1d1-14281bd8a917.t2flow");
- assertEquals("application/vnd.taverna.t2flow+xml", bundle
- .getManifest().getAggregation(t2flow).getMediatype());
- Path manifestRdf = bundle.getPath("META-INF/manifest.xml");
- assertTrue(Files.exists(manifestRdf));
- assertTrue(bundle.getManifest().getManifest().contains(manifestRdf));
- }
- }
-
- @Test
- public void openODTDocument() throws Exception {
- URL url = getClass().getResource("/document.odt");
- assertNotNull(url);
- try (Bundle bundle = Bundles.openBundle(url)) {
- assertEquals("application/vnd.oasis.opendocument.text",
- Bundles.getMimeType(bundle));
-
- Path contentXml = bundle.getPath("content.xml");
- Manifest manifest = bundle.getManifest();
- assertEquals("text/xml", manifest.getAggregation(contentXml)
- .getMediatype());
- PathMetadata rootMeta = manifest.getAggregation(bundle.getRoot());
- assertEquals("1.2", rootMeta.getConformsTo() + "");
- assertEquals("application/vnd.oasis.opendocument.text",
- rootMeta.getMediatype());
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/316e4a8a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/utils/TestRecursiveCopyFileVisitor.java
----------------------------------------------------------------------
diff --git a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/utils/TestRecursiveCopyFileVisitor.java b/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/utils/TestRecursiveCopyFileVisitor.java
deleted file mode 100644
index 84012e9..0000000
--- a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/utils/TestRecursiveCopyFileVisitor.java
+++ /dev/null
@@ -1,114 +0,0 @@
-package org.apache.taverna.robundle.manifest.utils;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.nio.file.FileAlreadyExistsException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.StandardCopyOption;
-import java.util.Arrays;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.taverna.robundle.Bundles;
-import org.junit.After;
-import org.junit.Test;
-
-public class TestRecursiveCopyFileVisitor {
-
- // TODO: Test NOFOLLOW and follow of symlinks
-
- private Set<Path> tmps = new LinkedHashSet<>();
-
- @After
- public void deleteTmps() throws IOException {
- IOException lastEx = null;
- for (Path p : tmps) {
- try {
- Bundles.deleteRecursively(p);
- } catch (IOException e) {
- lastEx = e;
- }
- }
- if (lastEx != null)
- throw lastEx;
- }
-
- @Test(expected = FileAlreadyExistsException.class)
- public void copyRecursivelyAlreadyExists() throws Exception {
- Path orig = tempDir("orig");
- Path dest = tempDir("dest");
- Bundles.copyRecursively(orig, dest);
- }
-
- protected Path tempDir(String name) throws IOException {
- Path dir = Files.createTempDirectory(name);
- tmps.add(dir);
- return dir;
- }
-
- @Test
- public void copyRecursivelyReplace() throws Exception {
- Path orig = tempDir("orig");
- Files.createFile(orig.resolve("file"));
- Path dest = tempDir("dest");
- Bundles.copyRecursively(orig, dest, StandardCopyOption.REPLACE_EXISTING);
- assertTrue(Files.isRegularFile(dest.resolve("file")));
- // Second copy should also be OK
- Bundles.copyRecursively(orig, dest, StandardCopyOption.REPLACE_EXISTING);
- }
-
- @Test
- public void copyRecursively() throws Exception {
- Path orig = tempDir("orig");
- Files.createFile(orig.resolve("1"));
- Files.createDirectory(orig.resolve("2"));
- Files.createFile(orig.resolve("2/1"));
- Files.createDirectory(orig.resolve("2/2"));
- List<String> hello = Arrays.asList("Hello");
-
- Charset ascii = Charset.forName("ASCII");
- Files.write(orig.resolve("2/2/1"), hello, ascii);
-
- Files.createDirectory(orig.resolve("2/2/2"));
- Files.createFile(orig.resolve("3"));
-
- Path dest = tempDir("dest");
- Files.delete(dest);
- Bundles.copyRecursively(orig, dest);
-
- assertTrue(Files.isDirectory(dest.resolve("2")));
- assertTrue(Files.isDirectory(dest.resolve("2/2")));
- assertTrue(Files.isDirectory(dest.resolve("2/2")));
- assertTrue(Files.isDirectory(dest.resolve("2/2/2")));
- assertTrue(Files.isRegularFile(dest.resolve("1")));
- assertTrue(Files.isRegularFile(dest.resolve("2/1")));
- assertTrue(Files.isRegularFile(dest.resolve("2/2/1")));
- assertTrue(Files.isRegularFile(dest.resolve("3")));
- assertEquals(hello, Files.readAllLines(dest.resolve("2/2/1"), ascii));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/316e4a8a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/utils/TestRecursiveCopyFileVisitorInBundle.java
----------------------------------------------------------------------
diff --git a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/utils/TestRecursiveCopyFileVisitorInBundle.java b/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/utils/TestRecursiveCopyFileVisitorInBundle.java
deleted file mode 100644
index d66c03a..0000000
--- a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/utils/TestRecursiveCopyFileVisitorInBundle.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package org.apache.taverna.robundle.manifest.utils;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-
-import org.apache.taverna.robundle.Bundle;
-import org.apache.taverna.robundle.Bundles;
-import org.junit.After;
-import org.junit.Before;
-
-public class TestRecursiveCopyFileVisitorInBundle extends
- TestRecursiveCopyFileVisitor {
-
- private Bundle bundle;
-
- @Before
- public void createBundle() throws IOException {
- bundle = Bundles.createBundle();
- }
-
- @After
- public void closeBundle() throws IOException {
- if (bundle != null) {
- bundle.close();
- }
- bundle = null;
- }
-
- @Override
- protected Path tempDir(String name) throws IOException {
- return Files.createTempDirectory(bundle.getRoot(), name);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/316e4a8a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/utils/TestRecursiveCopyFileVisitorMultipleBundles.java
----------------------------------------------------------------------
diff --git a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/utils/TestRecursiveCopyFileVisitorMultipleBundles.java b/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/utils/TestRecursiveCopyFileVisitorMultipleBundles.java
deleted file mode 100644
index c38c502..0000000
--- a/taverna-robundle/src/test/java/org/apache/taverna/robundle/manifest/utils/TestRecursiveCopyFileVisitorMultipleBundles.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package org.apache.taverna.robundle.manifest.utils;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.taverna.robundle.Bundle;
-import org.apache.taverna.robundle.Bundles;
-import org.junit.After;
-
-public class TestRecursiveCopyFileVisitorMultipleBundles extends
- TestRecursiveCopyFileVisitor {
-
- private List<Bundle> bundles = new ArrayList<>();
-
- @After
- public void closeBundle() throws IOException {
- for (Bundle b : bundles) {
- b.close();
- }
- }
-
- @Override
- protected Path tempDir(String name) throws IOException {
- Bundle bundle = Bundles.createBundle();
- bundles.add(bundle);
- return Files.createTempDirectory(bundle.getRoot(), name);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/316e4a8a/taverna-robundle/src/test/resources/combine/Boris.omex
----------------------------------------------------------------------
diff --git a/taverna-robundle/src/test/resources/combine/Boris.omex b/taverna-robundle/src/test/resources/combine/Boris.omex
deleted file mode 100644
index a4d5cf4..0000000
Binary files a/taverna-robundle/src/test/resources/combine/Boris.omex and /dev/null differ