Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.virgo.kernel.artifact/src/test')
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/ArtifactSpecificationTests.java47
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/StubHashGenerator.java25
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/bundle/BundleBridgeTests.java192
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/bundle/StubBundleArtefactBridge.java82
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/bundle/StubRepositoryAwareArtifactDescriptor.java79
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/fs/internal/DirectoryArtifactFSTests.java31
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/fs/internal/FileArtifactFSEntryTests.java41
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/fs/internal/FileArtifactFSTests.java41
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/library/LibraryBridgeTests.java57
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/par/ParBridgeTests.java117
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/plan/PlanBridgeTests.java89
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/plan/PlanReaderTests.java106
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/properties/PropertiesBridgeTests.java52
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/artefacts/exploded/META-INF/MANIFEST.MF0
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/artefacts/exploded/META-INF/web/index.jsp12
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/artefacts/exploded/somefile.txt1
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/artifacts/simple.jarbin0 -> 576 bytes
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/bundle.jar/META-INF/MANIFEST.MF4
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/directories/y.different-1.2.3/META-INF/MANIFEST.MF5
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/libraries/invalid.libd3
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/libraries/test.libd4
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/pars/basic.par/META-INF/MANIFEST.MF4
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/pars/illegal-asn.par/META-INF/MANIFEST.MF4
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/pars/illegal-version.par/META-INF/MANIFEST.MF4
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/pars/no-asn.par/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/pars/no-description.par/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/pars/no-manifest.par/META-INF/dummy.txt1
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/pars/no-name.par/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/pars/no-version.par/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/plans/attributes.plan15
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/plans/malformed.plan9
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/plans/multi-artifact.plan13
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/plans/properties.plan13
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/plans/single-artifact.plan11
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/properties/foo.properties1
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/wars/test.warbin0 -> 730 bytes
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/wars/testbad01.warbin0 -> 436 bytes
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/wars/testbad02.war1
38 files changed, 1076 insertions, 0 deletions
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/ArtifactSpecificationTests.java b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/ArtifactSpecificationTests.java
new file mode 100644
index 00000000..1a382c9c
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/ArtifactSpecificationTests.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.artifact;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+
+import org.eclipse.virgo.kernel.artifact.ArtifactSpecification;
+import org.eclipse.virgo.util.osgi.VersionRange;
+
+
+public class ArtifactSpecificationTests {
+
+ @Test
+ public void testCreateWithProperties() {
+ Map<String, String> props = new HashMap<String, String>();
+ props.put("foo", "bar");
+ ArtifactSpecification spec = new ArtifactSpecification("t", "n", new VersionRange("1.2.3"), props);
+ assertEquals("bar", spec.getProperties().get("foo"));
+ }
+
+ @Test
+ public void testCreateWithoutProperties() {
+ ArtifactSpecification spec = new ArtifactSpecification("t", "n", new VersionRange("1.2.3"));
+ assertNotNull(spec.getProperties());
+ }
+
+ @Test(expected=UnsupportedOperationException.class)
+ public void testPropertiesImmutable() {
+ ArtifactSpecification spec = new ArtifactSpecification("t", "n", new VersionRange("1.2.3"));
+ spec.getProperties().put("foo", "bar");
+ }
+}
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/StubHashGenerator.java b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/StubHashGenerator.java
new file mode 100644
index 00000000..6572b80d
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/StubHashGenerator.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.artifact;
+
+import java.io.File;
+
+import org.eclipse.virgo.repository.HashGenerator;
+import org.eclipse.virgo.repository.builder.ArtifactDescriptorBuilder;
+
+public class StubHashGenerator implements HashGenerator {
+
+ public void generateHash(ArtifactDescriptorBuilder artifactDescriptorBuilder, File artifactFile) {
+ // Do nothing
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/bundle/BundleBridgeTests.java b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/bundle/BundleBridgeTests.java
new file mode 100644
index 00000000..8d606dba
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/bundle/BundleBridgeTests.java
@@ -0,0 +1,192 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.artifact.bundle;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+
+import org.eclipse.virgo.kernel.artifact.StubHashGenerator;
+import org.eclipse.virgo.repository.ArtifactDescriptor;
+import org.eclipse.virgo.repository.ArtifactGenerationException;
+import org.eclipse.virgo.repository.Attribute;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+
+/**
+ * <p>
+ * Unit tests for {@link org.eclipse.virgo.kernel.artifact.bundle.BundleBridge BundleBridge}. Uses a combination of real bundle files and
+ * static test data.
+ * </p>
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ *
+ * Threadsafe test case
+ *
+ */
+public class BundleBridgeTests {
+
+ //Test Data
+
+ private final static String ARTEFACT_ATTRIBUTE_NAME = "name";
+
+ private final static String ARTEFACT_ATTRIBUTE_VERSION = "version";
+ //End Test Data
+
+ private static BundleBridge BUNDLE_BRIDGE;
+
+ private static final StubBundleArtefactBridge STUB_ARTEFACT_DEFINITION = new StubBundleArtefactBridge();
+
+ private static final String BUNDLE_MANIFEST_VERSION_HEADER_NAME = "Bundle-ManifestVersion";
+
+ private static final String BUNDLE_NAME_HEADER_NAME = "Bundle-Name";
+
+ @Before
+ public void setUp() throws Exception {
+ BUNDLE_BRIDGE = new BundleBridge(new StubHashGenerator());
+ }
+
+ @Test
+ public void testFictionalURI() {
+ File file = new File("/foo/bar.jar");
+ try {
+ BUNDLE_BRIDGE.generateArtifactDescriptor(file);
+ assertTrue("Should throw exception", false);
+ } catch (ArtifactGenerationException age) {
+ assertEquals("ArtifactType in exception is incorrect", age.getArtifactType(), BundleBridge.BRIDGE_TYPE);
+ }
+ }
+
+ @Test
+ public void testBadManifest01() {
+ File file = new File("./src/test/resources/wars/testbad01.war");
+ try {
+ BUNDLE_BRIDGE.generateArtifactDescriptor(file);
+ assertTrue("Should throw exception", false);
+ } catch (ArtifactGenerationException age) {
+ assertEquals("ArtifactType in exception is incorrect", age.getArtifactType(), BundleBridge.BRIDGE_TYPE);
+ }
+ }
+
+ @Test
+ public void testBadManifest02() {
+ File file = new File("./src/test/resources/wars/testbad02.war");
+ try {
+ BUNDLE_BRIDGE.generateArtifactDescriptor(file);
+ assertTrue("Should throw exception", false);
+ } catch (ArtifactGenerationException age) {
+ assertEquals("ArtifactType in exception is incorrect", age.getArtifactType(), BundleBridge.BRIDGE_TYPE);
+ }
+ }
+
+ @Test
+ public void testGenerateArtefact() throws ArtifactGenerationException {
+ File jarsDirectory = new File("../ivy-cache/repository/org.apache.commons/com.springsource.org.apache.commons.dbcp/1.2.2.osgi/com.springsource.org.apache.commons.dbcp-1.2.2.osgi.jar");
+ File directoriesDirectory = new File("./src/test/resources/directories");
+
+ Set<ArtifactDescriptor> artefacts = new HashSet<ArtifactDescriptor>();
+
+ artefacts.add(BUNDLE_BRIDGE.generateArtifactDescriptor(jarsDirectory));
+
+ assertEquals("Wrong number of artefacts have been parsed", 1, artefacts.size());
+
+ artefacts.addAll(generateArtefacts(directoriesDirectory));
+
+ assertEquals("Wrong number of artefacts have been parsed", 2, artefacts.size());
+
+ ArtifactDescriptor stubArtefact;
+ Set<Attribute> stubAttributes;
+ Set<Attribute> testAttributes;
+
+ for (ArtifactDescriptor testArtefact : artefacts) {
+ stubArtefact = STUB_ARTEFACT_DEFINITION.generateArtifactDescriptor(new File(testArtefact.getUri()));
+
+ stubAttributes = stubArtefact.getAttribute(ARTEFACT_ATTRIBUTE_NAME);
+ testAttributes = testArtefact.getAttribute(Constants.BUNDLE_SYMBOLICNAME);
+
+ assertEquals("Error on: " + testArtefact.toString(), stubAttributes.iterator().next().getValue(),
+ testAttributes.iterator().next().getValue());
+
+ stubAttributes = stubArtefact.getAttribute(ARTEFACT_ATTRIBUTE_VERSION);
+ testAttributes = testArtefact.getAttribute(Constants.BUNDLE_VERSION);
+
+ assertEquals("Error on: " + testArtefact.toString(), stubAttributes.iterator().next().getValue(),
+ testAttributes.iterator().next().getValue());
+ }
+ }
+
+ @Test
+ public void testBuildDictionary() throws ArtifactGenerationException, IOException {
+ File testFile = new File("../ivy-cache/repository/javax.servlet/com.springsource.javax.servlet/2.5.0/com.springsource.javax.servlet-2.5.0.jar");
+
+ ArtifactDescriptor inputArtefact = BUNDLE_BRIDGE.generateArtifactDescriptor(testFile);
+
+ Dictionary<String, String> dictionary = BundleBridge.convertToDictionary(inputArtefact);
+
+ JarFile testJar = new JarFile(testFile);
+ Attributes attributes = testJar.getManifest().getMainAttributes();
+
+ testJar.close();
+
+ assertEquals("Failed to match regenerated " + Constants.BUNDLE_SYMBOLICNAME, dictionary.get(Constants.BUNDLE_SYMBOLICNAME),
+ attributes.getValue(Constants.BUNDLE_SYMBOLICNAME));
+ assertEquals("Failed to match regenerated " + Constants.BUNDLE_VERSION, dictionary.get(Constants.BUNDLE_VERSION),
+ attributes.getValue(Constants.BUNDLE_VERSION));
+ assertEquals("Failed to match regenerated " + BUNDLE_MANIFEST_VERSION_HEADER_NAME, dictionary.get(BUNDLE_MANIFEST_VERSION_HEADER_NAME),
+ attributes.getValue(BUNDLE_MANIFEST_VERSION_HEADER_NAME));
+ assertEquals("Failed to match regenerated " + BUNDLE_NAME_HEADER_NAME, dictionary.get(BUNDLE_NAME_HEADER_NAME),
+ attributes.getValue(BUNDLE_NAME_HEADER_NAME));
+
+ }
+
+ @Test
+ public void webBundleWar() throws ArtifactGenerationException {
+ ArtifactDescriptor descriptor = BUNDLE_BRIDGE.generateArtifactDescriptor(new File("src/test/resources/wars/test.war"));
+ assertNotNull(descriptor);
+ assertEquals("bundle", descriptor.getType());
+ assertEquals("com.springsource.server.admin.web", descriptor.getName());
+ assertEquals(new Version(2, 0, 0), descriptor.getVersion());
+ }
+
+ @Test
+ public void explodedBundle() throws ArtifactGenerationException {
+ ArtifactDescriptor descriptor = BUNDLE_BRIDGE.generateArtifactDescriptor(new File("src/test/resources/bundle.jar"));
+ assertNotNull(descriptor);
+ assertEquals("bundle", descriptor.getType());
+ assertEquals("exploded.bundle", descriptor.getName());
+ assertEquals(new Version(1, 0, 0), descriptor.getVersion());
+ }
+
+ private Set<ArtifactDescriptor> generateArtefacts(File directory) throws ArtifactGenerationException {
+ Set<ArtifactDescriptor> artefacts = new HashSet<ArtifactDescriptor>();
+
+ for (File fileInDir : directory.listFiles()) {
+ if(!fileInDir.getName().endsWith(".jar") && !fileInDir.getName().contains("sources")){
+ ArtifactDescriptor artefact = BUNDLE_BRIDGE.generateArtifactDescriptor(fileInDir);
+ if (artefact != null) {
+ artefacts.add(BUNDLE_BRIDGE.generateArtifactDescriptor(fileInDir));
+ }
+ }
+ }
+ return artefacts;
+ }
+}
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/bundle/StubBundleArtefactBridge.java b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/bundle/StubBundleArtefactBridge.java
new file mode 100644
index 00000000..e2ec7f64
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/bundle/StubBundleArtefactBridge.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.artifact.bundle;
+
+import java.io.File;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.virgo.repository.ArtifactBridge;
+import org.eclipse.virgo.repository.ArtifactDescriptor;
+import org.eclipse.virgo.repository.Attribute;
+import org.eclipse.virgo.repository.RepositoryAwareArtifactDescriptor;
+import org.eclipse.virgo.repository.internal.StandardAttribute;
+import org.osgi.framework.Version;
+
+/**
+ * <p>
+ * A Stub impl of Artefact Bridge, is pre-configured to return values from the test data set.
+ * </p>
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ *
+ * This class is Threadsafe
+ *
+ */
+final public class StubBundleArtefactBridge implements ArtifactBridge {
+
+ private final Map<String, RepositoryAwareArtifactDescriptor> testArtefacts = new HashMap<String, RepositoryAwareArtifactDescriptor>();
+
+ public StubBundleArtefactBridge() {
+
+ testArtefacts.put(translate(TEST_FILE_URI), TEST_ARTEFACT);
+ testArtefacts.put(translate(TEST_DIRECTORY_URI), TEST_DIRECTORY_ARTEFACT);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ArtifactDescriptor generateArtifactDescriptor(File artifact) {
+ return this.testArtefacts.get(artifact.getName());
+ }
+
+ private String translate(URI uri) {
+ return new File(uri).getName();
+ }
+
+ //TEST DATA
+
+ private static final URI TEST_DIRECTORY_URI = URI.create("file:/src/test/resources/directories/y.different-" + new Version("1.2.3"));
+
+ private static final Set<Attribute> TEST_ATTRIBUTE_SET_DIRECTORY = createAttributeSet("y.different", new Version("1.2.3"), TEST_DIRECTORY_URI);
+
+ private final static RepositoryAwareArtifactDescriptor TEST_DIRECTORY_ARTEFACT = new StubRepositoryAwareArtifactDescriptor(TEST_DIRECTORY_URI, "y.different", new Version("1.2.3"), TEST_ATTRIBUTE_SET_DIRECTORY);
+
+ private final static URI TEST_FILE_URI = URI.create("file:/../ivy-cache/repository/org.apache.commons/com.springsource.org.apache.commons.dbcp/1.2.2.osgi/" + "com.springsource.org.apache.commons.dbcp-1.2.2.osgi.jar");
+
+ private static final Set<Attribute> TEST_ATTRIBUTE_SET = createAttributeSet("com.springsource.org.apache.commons.dbcp", new Version("1.2.2.osgi"), TEST_FILE_URI);
+
+ private final static RepositoryAwareArtifactDescriptor TEST_ARTEFACT = new StubRepositoryAwareArtifactDescriptor(TEST_FILE_URI, "com.springsource.org.apache.commons.dbcp", new Version("1.2.2.osgi"), TEST_ATTRIBUTE_SET);
+
+ private static Set<Attribute> createAttributeSet(String name, Version version, URI uri) {
+ Set<Attribute> attributes = new HashSet<Attribute>();
+ attributes.add(new StandardAttribute("type", "test"));
+ attributes.add(new StandardAttribute("name", name));
+ attributes.add(new StandardAttribute("version", version.toString()));
+ attributes.add(new StandardAttribute("uri", uri.toString()));
+ return attributes;
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/bundle/StubRepositoryAwareArtifactDescriptor.java b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/bundle/StubRepositoryAwareArtifactDescriptor.java
new file mode 100644
index 00000000..4428981d
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/bundle/StubRepositoryAwareArtifactDescriptor.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.artifact.bundle;
+
+import java.io.File;
+import java.net.URI;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.osgi.framework.Version;
+
+import org.eclipse.virgo.repository.Attribute;
+import org.eclipse.virgo.repository.RepositoryAwareArtifactDescriptor;
+
+class StubRepositoryAwareArtifactDescriptor implements RepositoryAwareArtifactDescriptor {
+
+ private final URI uri;
+
+ private final String name;
+
+ private final Version version;
+
+ private final Set<Attribute> attributes;
+
+ public StubRepositoryAwareArtifactDescriptor(URI uri, String name, Version version, Set<Attribute> attributes) {
+ this.uri = uri;
+ this.name = name;
+ this.version = version;
+ this.attributes = attributes;
+ }
+
+ public Set<Attribute> getAttribute(String name) {
+ Set<Attribute> matchingAttribs = new HashSet<Attribute>();
+ for(Attribute attrib : this.attributes){
+ if(attrib.getKey().equals(name)){
+ matchingAttribs.add(attrib);
+ }
+ }
+ return matchingAttribs;
+ }
+
+ public Set<Attribute> getAttributes() {
+ return this.attributes;
+ }
+
+ public String getFilename() {
+ return new File(this.uri).getName();
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public String getType() {
+ return "test_type";
+ }
+
+ public URI getUri() {
+ return this.uri;
+ }
+
+ public Version getVersion() {
+ return this.version;
+ }
+
+ public String getRepositoryName() {
+ return "test-repo";
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/fs/internal/DirectoryArtifactFSTests.java b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/fs/internal/DirectoryArtifactFSTests.java
new file mode 100644
index 00000000..fd240e05
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/fs/internal/DirectoryArtifactFSTests.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.artifact.fs.internal;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.eclipse.virgo.kernel.artifact.fs.internal.DirectoryArtifactFS;
+import org.eclipse.virgo.kernel.artifact.fs.internal.FileArtifactFSEntry;
+import org.junit.Test;
+
+
+public class DirectoryArtifactFSTests {
+
+ private final DirectoryArtifactFS artifactFS = new DirectoryArtifactFS(new File("target"));
+
+ @Test
+ public void getEntry() {
+ assertTrue(this.artifactFS.getEntry("test") instanceof FileArtifactFSEntry);
+ }
+}
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/fs/internal/FileArtifactFSEntryTests.java b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/fs/internal/FileArtifactFSEntryTests.java
new file mode 100644
index 00000000..5d616113
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/fs/internal/FileArtifactFSEntryTests.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.artifact.fs.internal;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.util.jar.JarFile;
+
+import org.eclipse.virgo.kernel.artifact.fs.internal.FileArtifactFSEntry;
+import org.junit.Test;
+
+public class FileArtifactFSEntryTests {
+
+ private final File file;
+
+ public FileArtifactFSEntryTests() throws Exception {
+ this.file = new File("src/test/resources/artifacts/exploded");
+ new FileArtifactFSEntry(this.file, new File(this.file, JarFile.MANIFEST_NAME));
+ new FileArtifactFSEntry(this.file, new File(this.file, "META-INF/"));
+ }
+
+ @Test
+ public void getNameRoot() {
+ assertEquals("", new FileArtifactFSEntry(this.file, this.file).getPath());
+ }
+
+ @Test
+ public void getName() {
+ assertEquals("test", new FileArtifactFSEntry(this.file, new File(this.file, "test")).getPath());
+ }
+}
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/fs/internal/FileArtifactFSTests.java b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/fs/internal/FileArtifactFSTests.java
new file mode 100644
index 00000000..ee40067e
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/fs/internal/FileArtifactFSTests.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.artifact.fs.internal;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.eclipse.virgo.kernel.artifact.fs.internal.FileArtifactFS;
+import org.eclipse.virgo.kernel.artifact.fs.internal.FileArtifactFSEntry;
+import org.junit.Test;
+
+
+public class FileArtifactFSTests {
+
+ private final FileArtifactFS artifactFS = new FileArtifactFS(new File(".classpath"));
+
+ @Test(expected = IllegalArgumentException.class)
+ public void constructorDirectory() {
+ new FileArtifactFS(new File("target"));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void getEntryNonNull() {
+ this.artifactFS.getEntry("test");
+ }
+
+ @Test
+ public void getEntry() {
+ assertTrue(this.artifactFS.getEntry(null) instanceof FileArtifactFSEntry);
+ }
+}
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/library/LibraryBridgeTests.java b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/library/LibraryBridgeTests.java
new file mode 100644
index 00000000..fdc2bcc3
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/library/LibraryBridgeTests.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.artifact.library;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.io.File;
+
+import org.junit.Test;
+
+
+import org.eclipse.virgo.kernel.artifact.StubHashGenerator;
+import org.eclipse.virgo.kernel.artifact.library.LibraryBridge;
+import org.eclipse.virgo.repository.ArtifactDescriptor;
+import org.eclipse.virgo.repository.ArtifactGenerationException;
+
+/**
+ */
+public class LibraryBridgeTests {
+
+ @Test
+ public void testValidLibraryFile() throws ArtifactGenerationException {
+ LibraryBridge bridge = new LibraryBridge(new StubHashGenerator());
+
+ ArtifactDescriptor descriptor = bridge.generateArtifactDescriptor(new File("src/test/resources/libraries/test.libd"));
+ assertNotNull(descriptor);
+
+ assertEquals("test.library", descriptor.getName());
+ assertEquals("1.2.0", descriptor.getAttribute("Library-Version").iterator().next().getValue());
+ assertEquals(3, descriptor.getAttribute("Import-Bundle").size());
+ }
+
+ @Test
+ public void testNotALibraryFile() throws ArtifactGenerationException {
+ LibraryBridge bridge = new LibraryBridge(new StubHashGenerator());
+
+ ArtifactDescriptor descriptor = bridge.generateArtifactDescriptor(new File("src/test/resources/libraries/test.foo"));
+ assertNull(descriptor);
+ }
+
+ @Test(expected = ArtifactGenerationException.class)
+ public void testInvalidLibraryFile() throws ArtifactGenerationException {
+ LibraryBridge bridge = new LibraryBridge(new StubHashGenerator());
+ bridge.generateArtifactDescriptor(new File("src/test/resources/libraries/invalid.libd"));
+ }
+}
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/par/ParBridgeTests.java b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/par/ParBridgeTests.java
new file mode 100644
index 00000000..459889f3
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/par/ParBridgeTests.java
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.artifact.par;
+
+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 static org.junit.Assert.fail;
+
+import java.io.File;
+
+import org.junit.Test;
+import org.osgi.framework.Version;
+
+
+import org.eclipse.virgo.kernel.artifact.StubHashGenerator;
+import org.eclipse.virgo.kernel.artifact.par.ParBridge;
+import org.eclipse.virgo.repository.ArtifactDescriptor;
+import org.eclipse.virgo.repository.ArtifactGenerationException;
+
+
+/**
+ *
+ */
+public class ParBridgeTests {
+
+ private final ParBridge parBridge = new ParBridge(new StubHashGenerator());
+
+ @Test
+ public void descriptorGeneration() throws ArtifactGenerationException {
+ ArtifactDescriptor descriptor = this.parBridge.generateArtifactDescriptor(new File("src/test/resources/pars/basic.par"));
+ assertDescriptor(descriptor, "par", "basic", new Version(1,2,3), "Basic Par", "A basic PAR file for the unit tests");
+ }
+
+ @Test
+ public void generationWithNoManifest() throws ArtifactGenerationException {
+ ArtifactDescriptor descriptor = this.parBridge.generateArtifactDescriptor(new File("src/test/resources/pars/no-manifest.par"));
+ assertNull(descriptor);
+ }
+
+ @Test
+ public void generationWithNoApplicationSymbolicName() throws ArtifactGenerationException {
+ ArtifactDescriptor descriptor = this.parBridge.generateArtifactDescriptor(new File("src/test/resources/pars/no-asn.par"));
+ assertNull(descriptor);
+ }
+
+ @Test
+ public void generationWithNoApplicationVersion() throws ArtifactGenerationException {
+ ArtifactDescriptor descriptor = this.parBridge.generateArtifactDescriptor(new File("src/test/resources/pars/no-version.par"));
+ assertDescriptor(descriptor, "par", "basic", Version.emptyVersion, "Basic Par", "A basic PAR file for the unit tests");
+ }
+
+ @Test
+ public void generationWithNoName() throws ArtifactGenerationException {
+ ArtifactDescriptor descriptor = this.parBridge.generateArtifactDescriptor(new File("src/test/resources/pars/no-name.par"));
+ assertDescriptor(descriptor, "par", "basic", new Version(1,2,3), null, "A basic PAR file for the unit tests");
+ }
+
+ @Test
+ public void generationWithNoDescription() throws ArtifactGenerationException {
+ ArtifactDescriptor descriptor = this.parBridge.generateArtifactDescriptor(new File("src/test/resources/pars/no-description.par"));
+ assertDescriptor(descriptor, "par", "basic", new Version(1,2,3), "Basic Par", null);
+ }
+
+ @Test
+ public void generationWithIllegalApplicationSymbolicName() throws Exception {
+ try {
+ this.parBridge.generateArtifactDescriptor(new File("src/test/resources/pars/illegal-asn.par"));
+ fail("Illegal Application-SymbolicName did not throw an ArtifactGenerationException");
+ } catch (ArtifactGenerationException age) {
+ assertEquals("Application-SymbolicName '.@$%' contains illegal characters", age.getMessage());
+ }
+ }
+
+ @Test
+ public void generationWithIllegalApplicationVersion() throws Exception {
+ try {
+ this.parBridge.generateArtifactDescriptor(new File("src/test/resources/pars/illegal-version.par"));
+ fail("Illegal Application-Version did not throw an ArtifactGenerationException");
+ } catch (ArtifactGenerationException age) {
+ assertEquals("Version 'alpha' is ill-formed", age.getMessage());
+ }
+ }
+
+ @Test(expected=ArtifactGenerationException.class)
+ public void generationWithMissingPar() throws ArtifactGenerationException {
+ this.parBridge.generateArtifactDescriptor(new File("src/test/resources/pars/not-there.par"));
+ }
+
+ private void assertDescriptor(ArtifactDescriptor descriptor, String type, String symbolicName, Version version, String name, String description) {
+ assertNotNull(descriptor);
+ assertEquals(type, descriptor.getType());
+ assertEquals(symbolicName, descriptor.getName());
+ assertEquals(version, descriptor.getVersion());
+ if (name != null) {
+ assertEquals(name, descriptor.getAttribute("Application-Name").iterator().next().getValue());
+ } else {
+ assertTrue(descriptor.getAttribute("Application-Name").isEmpty());
+ }
+
+ if (description != null) {
+ assertEquals(description, descriptor.getAttribute("Application-Description").iterator().next().getValue());
+ } else {
+ assertTrue(descriptor.getAttribute("Application-Description").isEmpty());
+ }
+ }
+}
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/plan/PlanBridgeTests.java b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/plan/PlanBridgeTests.java
new file mode 100644
index 00000000..97a5704b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/plan/PlanBridgeTests.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.artifact.plan;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.io.File;
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.Test;
+import org.osgi.framework.Version;
+
+
+import org.eclipse.virgo.kernel.artifact.StubHashGenerator;
+import org.eclipse.virgo.kernel.artifact.plan.PlanBridge;
+import org.eclipse.virgo.repository.ArtifactDescriptor;
+import org.eclipse.virgo.repository.ArtifactGenerationException;
+import org.eclipse.virgo.repository.Attribute;
+
+public class PlanBridgeTests {
+
+ private final PlanBridge bridge = new PlanBridge(new StubHashGenerator());
+
+ @Test(expected = ArtifactGenerationException.class)
+ public void testBadPlanFile() throws ArtifactGenerationException {
+ bridge.generateArtifactDescriptor(new File("src/test/resources/plans/malformed.plan"));
+ }
+
+ @Test()
+ public void testNotAPlanFile() throws ArtifactGenerationException {
+ assertNull(bridge.generateArtifactDescriptor(new File("src/test/resources/plans/not-a-plan.xml")));
+ }
+
+ @Test
+ public void testSingleArtifactPlan() throws ArtifactGenerationException {
+ org.eclipse.virgo.repository.ArtifactDescriptor artefact = bridge.generateArtifactDescriptor(new File(
+ "src/test/resources/plans/single-artifact.plan"));
+ assertEquals("plan", artefact.getType());
+ assertEquals("single-artifact.plan", artefact.getName());
+ assertEquals(new Version(1, 0, 0), artefact.getVersion());
+
+ Set<Attribute> attributes = artefact.getAttribute("artifact");
+ assertEquals(1, attributes.size());
+ Map<String, Set<String>> properties = attributes.iterator().next().getProperties();
+ assertEquals("bundle", getProperty("type", properties));
+ assertEquals("org.springframework.context.support", getProperty("name", properties));
+ assertEquals("[1.0.0, 2.0.0)", getProperty("version", properties));
+ }
+
+ @Test
+ public void testMultiArtifactPlan() throws ArtifactGenerationException {
+ ArtifactDescriptor artefact = bridge.generateArtifactDescriptor(new File("src/test/resources/plans/multi-artifact.plan"));
+ assertEquals("plan", artefact.getType());
+ assertEquals("multi-artifact.plan", artefact.getName());
+ assertEquals(new Version(1, 0, 0), artefact.getVersion());
+
+ Set<Attribute> attributes = artefact.getAttribute("artifact");
+ assertEquals(3, attributes.size());
+ for (Attribute attribute : attributes) {
+ Map<String, Set<String>> properties = attribute.getProperties();
+ String type = getProperty("type", properties);
+ if ("alpha".equals(type)) {
+ assertEquals("org.springframework.core", getProperty("name", properties));
+ assertEquals("0.0.0", getProperty("version", properties));
+ } else if ("bravo".equals(type)) {
+ assertEquals("org.springframework.context", getProperty("name", properties));
+ assertEquals("1.0.0", getProperty("version", properties));
+ } else if ("charlie".equals(type)) {
+ assertEquals("org.springframework.context.support", getProperty("name", properties));
+ assertEquals("[1.0.0, 2.0.0)", getProperty("version", properties));
+ }
+ }
+ }
+
+ private String getProperty(String key, Map<String, Set<String>> properties) {
+ return properties.get(key).iterator().next();
+ }
+}
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/plan/PlanReaderTests.java b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/plan/PlanReaderTests.java
new file mode 100644
index 00000000..a2a9e4fd
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/plan/PlanReaderTests.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.artifact.plan;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.util.List;
+
+import org.junit.Test;
+import org.osgi.framework.Version;
+
+import org.eclipse.virgo.kernel.artifact.ArtifactSpecification;
+import org.eclipse.virgo.kernel.artifact.plan.PlanDescriptor;
+import org.eclipse.virgo.kernel.artifact.plan.PlanReader;
+import org.eclipse.virgo.util.osgi.VersionRange;
+
+public class PlanReaderTests {
+
+ private final PlanReader reader = new PlanReader();
+
+ @Test(expected = RuntimeException.class)
+ public void testBadPlanFile() throws FileNotFoundException {
+ reader.read(new FileInputStream("src/test/resources/plans/malformed.plan"));
+ }
+
+ @Test
+ public void testSingleArtifactPlan() throws FileNotFoundException {
+ PlanDescriptor plan = reader.read(new FileInputStream("src/test/resources/plans/single-artifact.plan"));
+ assertEquals("single-artifact.plan", plan.getName());
+ assertEquals(new Version(1, 0, 0), plan.getVersion());
+
+ List<ArtifactSpecification> artifactSpecifications = plan.getArtifactSpecifications();
+ assertEquals(1, artifactSpecifications.size());
+ ArtifactSpecification artifactSpecification = artifactSpecifications.iterator().next();
+ assertEquals("bundle", artifactSpecification.getType());
+ assertEquals("org.springframework.context.support", artifactSpecification.getName());
+ assertEquals(new VersionRange("[1.0.0, 2.0.0)"), artifactSpecification.getVersionRange());
+ assertNotNull(artifactSpecification.getProperties());
+ assertTrue(artifactSpecification.getProperties().isEmpty());
+ }
+
+ @Test
+ public void testSingleArtifactPlanWithAttributes() throws FileNotFoundException {
+ PlanDescriptor plan = reader.read(new FileInputStream("src/test/resources/plans/attributes.plan"));
+ assertEquals("single-artifact.plan", plan.getName());
+ assertEquals(new Version(1, 0, 0), plan.getVersion());
+
+ List<ArtifactSpecification> artifactSpecifications = plan.getArtifactSpecifications();
+ assertEquals(1, artifactSpecifications.size());
+ ArtifactSpecification artifactSpecification = artifactSpecifications.iterator().next();
+ assertEquals("bundle", artifactSpecification.getType());
+ assertEquals("org.springframework.context.support", artifactSpecification.getName());
+ assertEquals(new VersionRange("[1.0.0, 2.0.0)"), artifactSpecification.getVersionRange());
+ }
+
+ @Test
+ public void testSingleArtifactPlanWithProperties() throws FileNotFoundException {
+ PlanDescriptor plan = reader.read(new FileInputStream("src/test/resources/plans/properties.plan"));
+ assertEquals("properties.plan", plan.getName());
+ assertEquals(new Version(1, 0, 0), plan.getVersion());
+
+ List<ArtifactSpecification> artifactSpecifications = plan.getArtifactSpecifications();
+ assertEquals(1, artifactSpecifications.size());
+ ArtifactSpecification artifactSpecification = artifactSpecifications.iterator().next();
+ assertEquals("bundle", artifactSpecification.getType());
+ assertEquals("my.webapp", artifactSpecification.getName());
+ assertEquals(new VersionRange("[1.0.0, 2.0.0)"), artifactSpecification.getVersionRange());
+ assertEquals("/foo", artifactSpecification.getProperties().get("Web-ContextPath"));
+ }
+
+ @Test
+ public void testMultiArtifactPlan() throws FileNotFoundException {
+ PlanDescriptor plan = reader.read(new FileInputStream("src/test/resources/plans/multi-artifact.plan"));
+ assertEquals("multi-artifact.plan", plan.getName());
+ assertEquals(new Version(1, 0, 0), plan.getVersion());
+
+ List<ArtifactSpecification> artifactSpecifications = plan.getArtifactSpecifications();
+ assertEquals(3, artifactSpecifications.size());
+ for (ArtifactSpecification artifactSpecification : artifactSpecifications) {
+ String type = artifactSpecification.getType();
+ if ("alpha".equals(type)) {
+ assertEquals("org.springframework.core", artifactSpecification.getName());
+ assertEquals(new VersionRange("0"), artifactSpecification.getVersionRange());
+ } else if ("bravo".equals(type)) {
+ assertEquals("org.springframework.context", artifactSpecification.getName());
+ assertEquals(new VersionRange("1.0.0"), artifactSpecification.getVersionRange());
+ } else if ("charlie".equals(type)) {
+ assertEquals("org.springframework.context.support", artifactSpecification.getName());
+ assertEquals(new VersionRange("[1.0.0, 2.0.0)"), artifactSpecification.getVersionRange());
+ }
+ }
+ }
+}
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/properties/PropertiesBridgeTests.java b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/properties/PropertiesBridgeTests.java
new file mode 100644
index 00000000..4f046b2b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/properties/PropertiesBridgeTests.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.artifact.properties;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.io.File;
+
+import org.junit.Test;
+
+
+import org.eclipse.virgo.kernel.artifact.StubHashGenerator;
+import org.eclipse.virgo.kernel.artifact.properties.PropertiesBridge;
+import org.eclipse.virgo.repository.ArtifactDescriptor;
+import org.eclipse.virgo.repository.ArtifactGenerationException;
+
+/**
+ */
+public class PropertiesBridgeTests {
+
+ @Test
+ public void testGeneratePropertiesFile() throws ArtifactGenerationException {
+ PropertiesBridge bridge = new PropertiesBridge(new StubHashGenerator());
+ ArtifactDescriptor result = bridge.generateArtifactDescriptor(new File("src/test/resources/properties/foo.properties"));
+ assertNotNull(result);
+ }
+
+ @Test(expected = ArtifactGenerationException.class)
+ public void testFileDoesNotExist() throws ArtifactGenerationException {
+ PropertiesBridge bridge = new PropertiesBridge(new StubHashGenerator());
+
+ File file = new File("src/test/resources/properties/not.exist.properties");
+ bridge.generateArtifactDescriptor(file);
+ }
+
+ @Test
+ public void testGenerateNotPropertiesFile() throws ArtifactGenerationException {
+ PropertiesBridge bridge = new PropertiesBridge(new StubHashGenerator());
+ ArtifactDescriptor descriptor = bridge.generateArtifactDescriptor(new File("src/test/resources/bar.noterties"));
+ assertNull(descriptor);
+ }
+}
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/artefacts/exploded/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.artifact/src/test/resources/artefacts/exploded/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/artefacts/exploded/META-INF/MANIFEST.MF
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/artefacts/exploded/META-INF/web/index.jsp b/org.eclipse.virgo.kernel.artifact/src/test/resources/artefacts/exploded/META-INF/web/index.jsp
new file mode 100644
index 00000000..8102008f
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/artefacts/exploded/META-INF/web/index.jsp
@@ -0,0 +1,12 @@
+<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
+ pageEncoding="ISO-8859-1"%>
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Hello Web!</title>
+</head>
+<body>
+<p>Hello Web!</p>
+</body>
+</html> \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/artefacts/exploded/somefile.txt b/org.eclipse.virgo.kernel.artifact/src/test/resources/artefacts/exploded/somefile.txt
new file mode 100644
index 00000000..c57eff55
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/artefacts/exploded/somefile.txt
@@ -0,0 +1 @@
+Hello World! \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/artifacts/simple.jar b/org.eclipse.virgo.kernel.artifact/src/test/resources/artifacts/simple.jar
new file mode 100644
index 00000000..7efafc13
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/artifacts/simple.jar
Binary files differ
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/bundle.jar/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.artifact/src/test/resources/bundle.jar/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..4a7652cc
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/bundle.jar/META-INF/MANIFEST.MF
@@ -0,0 +1,4 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: exploded.bundle
+Bundle-Version: 1.0
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/directories/y.different-1.2.3/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.artifact/src/test/resources/directories/y.different-1.2.3/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..582885d7
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/directories/y.different-1.2.3/META-INF/MANIFEST.MF
@@ -0,0 +1,5 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: y.different
+Export-Package: x
+Bundle-Version: 1.2.3
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/libraries/invalid.libd b/org.eclipse.virgo.kernel.artifact/src/test/resources/libraries/invalid.libd
new file mode 100644
index 00000000..ff55009f
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/libraries/invalid.libd
@@ -0,0 +1,3 @@
+Manifest-Version: 1
+Library-Version: 1.2
+Import-Bundle: a,b,c \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/libraries/test.libd b/org.eclipse.virgo.kernel.artifact/src/test/resources/libraries/test.libd
new file mode 100644
index 00000000..3e4e6f06
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/libraries/test.libd
@@ -0,0 +1,4 @@
+Manifest-Version: 1
+Library-SymbolicName: test.library
+Library-Version: 1.2
+Import-Bundle: a,b,c \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/basic.par/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/basic.par/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..8099c758
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/basic.par/META-INF/MANIFEST.MF
@@ -0,0 +1,4 @@
+Application-SymbolicName: basic
+Application-Version: 1.2.3
+Application-Name: Basic Par
+Application-Description: A basic PAR file for the unit tests
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/illegal-asn.par/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/illegal-asn.par/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..e5fa4593
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/illegal-asn.par/META-INF/MANIFEST.MF
@@ -0,0 +1,4 @@
+Application-SymbolicName: .@$%
+Application-Version: 1.2.3
+Application-Name: Basic Par
+Application-Description: A basic PAR file for the unit tests
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/illegal-version.par/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/illegal-version.par/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..6488d37c
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/illegal-version.par/META-INF/MANIFEST.MF
@@ -0,0 +1,4 @@
+Application-SymbolicName: basic
+Application-Version: alpha
+Application-Name: Basic Par
+Application-Description: A basic PAR file for the unit tests
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/no-asn.par/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/no-asn.par/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..f9f79e57
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/no-asn.par/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Application-Version: 1.2.3
+Application-Name: Basic Par
+Application-Description: A basic PAR file for the unit tests
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/no-description.par/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/no-description.par/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..fd589a8f
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/no-description.par/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Application-SymbolicName: basic
+Application-Version: 1.2.3
+Application-Name: Basic Par
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/no-manifest.par/META-INF/dummy.txt b/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/no-manifest.par/META-INF/dummy.txt
new file mode 100644
index 00000000..0fa94231
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/no-manifest.par/META-INF/dummy.txt
@@ -0,0 +1 @@
+Just a file to keep the directory around \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/no-name.par/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/no-name.par/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..ad855b69
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/no-name.par/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Application-SymbolicName: basic
+Application-Version: 1.2.3
+Application-Description: A basic PAR file for the unit tests
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/no-version.par/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/no-version.par/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..a5a84ba6
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/pars/no-version.par/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Application-SymbolicName: basic
+Application-Name: Basic Par
+Application-Description: A basic PAR file for the unit tests
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/plans/attributes.plan b/org.eclipse.virgo.kernel.artifact/src/test/resources/plans/attributes.plan
new file mode 100644
index 00000000..5ae8d8c7
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/plans/attributes.plan
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plan name="single-artifact.plan" version="1.0.0" scoped="true" atomic="true"
+ xmlns="http://www.springsource.org/schema/dm-server/plan"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springsource.org/schema/dm-server/plan
+ http://www.springsource.org/schema/dm-server/plan/springsource-dm-server-plan.xsd">
+
+ <attributes>
+ <attribute name="version" value="[1.0.0, 2.0.0)"/>
+
+ </attributes>
+ <artifact type="bundle" name="org.springframework.context.support" version="${version}"/>
+
+</plan> \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/plans/malformed.plan b/org.eclipse.virgo.kernel.artifact/src/test/resources/plans/malformed.plan
new file mode 100644
index 00000000..71cc5c15
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/plans/malformed.plan
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plan name="malformed.plan" version="1.0.0"
+ xmlns="http://www.springsource.org/schema/dm-server/plan"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springsource.org/schema/dm-server/plan
+ http://www.springsource.org/schema/dm-server/plan/springsource-dm-server-plan.xsd">
+ <artifact type="bundle"/>
+</plan> \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/plans/multi-artifact.plan b/org.eclipse.virgo.kernel.artifact/src/test/resources/plans/multi-artifact.plan
new file mode 100644
index 00000000..ea5363d0
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/plans/multi-artifact.plan
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plan name="multi-artifact.plan" version="1.0.0" scoped="true" atomic="true"
+ xmlns="http://www.springsource.org/schema/dm-server/plan"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springsource.org/schema/dm-server/plan
+ http://www.springsource.org/schema/dm-server/plan/springsource-dm-server-plan.xsd">
+
+ <artifact type="alpha" name="org.springframework.core"/>
+ <artifact type="bravo" name="org.springframework.context" version="1.0.0"/>
+ <artifact type="charlie" name="org.springframework.context.support" version="[1.0.0, 2.0.0)"/>
+
+</plan> \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/plans/properties.plan b/org.eclipse.virgo.kernel.artifact/src/test/resources/plans/properties.plan
new file mode 100644
index 00000000..8e76e718
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/plans/properties.plan
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plan name="properties.plan" version="1.0.0" scoped="true" atomic="true"
+ xmlns="http://www.springsource.org/schema/dm-server/plan"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springsource.org/schema/dm-server/plan
+ http://www.springsource.org/schema/dm-server/plan/springsource-dm-server-plan.xsd">
+
+ <artifact type="bundle" name="my.webapp" version="[1.0.0, 2.0.0)">
+ <property name="Web-ContextPath" value="/foo"/>
+ </artifact>
+
+</plan> \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/plans/single-artifact.plan b/org.eclipse.virgo.kernel.artifact/src/test/resources/plans/single-artifact.plan
new file mode 100644
index 00000000..e5377970
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/plans/single-artifact.plan
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plan name="single-artifact.plan" version="1.0.0" scoped="true" atomic="true"
+ xmlns="http://www.springsource.org/schema/dm-server/plan"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springsource.org/schema/dm-server/plan
+ http://www.springsource.org/schema/dm-server/plan/springsource-dm-server-plan.xsd">
+
+ <artifact type="bundle" name="org.springframework.context.support" version="[1.0.0, 2.0.0)"/>
+
+</plan> \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/properties/foo.properties b/org.eclipse.virgo.kernel.artifact/src/test/resources/properties/foo.properties
new file mode 100644
index 00000000..74d0a43f
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/properties/foo.properties
@@ -0,0 +1 @@
+foo=bar
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/wars/test.war b/org.eclipse.virgo.kernel.artifact/src/test/resources/wars/test.war
new file mode 100644
index 00000000..c08c7316
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/wars/test.war
Binary files differ
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/wars/testbad01.war b/org.eclipse.virgo.kernel.artifact/src/test/resources/wars/testbad01.war
new file mode 100644
index 00000000..677a6ba6
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/wars/testbad01.war
Binary files differ
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/wars/testbad02.war b/org.eclipse.virgo.kernel.artifact/src/test/resources/wars/testbad02.war
new file mode 100644
index 00000000..4b90d403
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/wars/testbad02.war
@@ -0,0 +1 @@
+This is not a war file really \ No newline at end of file

Back to the top