Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlyn Normington2012-01-20 08:33:21 -0500
committerGlyn Normington2012-01-20 08:33:21 -0500
commit76d43e682995bfb20e7aae3f0b9ea71ecab7a0bb (patch)
tree6481685181fb89e06ad1892a94e9b90d9a4c2516 /org.eclipse.virgo.kernel.deployer.test/src/test/java
parent6faec84aa985b2c5394ae3ac9162bd96f34ecd0a (diff)
downloadorg.eclipse.virgo.kernel-76d43e682995bfb20e7aae3f0b9ea71ecab7a0bb.tar.gz
org.eclipse.virgo.kernel-76d43e682995bfb20e7aae3f0b9ea71ecab7a0bb.tar.xz
org.eclipse.virgo.kernel-76d43e682995bfb20e7aae3f0b9ea71ecab7a0bb.zip
Bug 327538 - plan bridge tweaks, test case and code to make it pass, better diagnostics
Diffstat (limited to 'org.eclipse.virgo.kernel.deployer.test/src/test/java')
-rw-r--r--org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/PlanUriIntegrationTests.java166
1 files changed, 166 insertions, 0 deletions
diff --git a/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/PlanUriIntegrationTests.java b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/PlanUriIntegrationTests.java
new file mode 100644
index 00000000..51553577
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/PlanUriIntegrationTests.java
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * 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.deployer.test;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+
+import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
+import org.eclipse.virgo.kernel.deployer.core.DeploymentIdentity;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.osgi.framework.Version;
+
+/**
+ * These tests cover the use of URIs in plans.
+ */
+public class PlanUriIntegrationTests extends AbstractDeployerIntegrationTest {
+
+ private static final String PLAN_TYPE = "plan";
+
+ private static final String TEST_RESOURCES_DIRECTORY = "src/test/resources/plan-deployment/";
+
+ private static final String GENERATED_PLAN_DIRECTORY = "target/PlanUriIntegrationTests/";
+
+ private static final String PLAN_EXTENSION = ".plan";
+
+ private static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+
+ private static final String NAMESPACES = " xmlns=\"http://www.eclipse.org/virgo/schema/plan\" \n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n xsi:schemaLocation=\" http://www.eclipse.org/virgo/schema/plan http://www.eclipse.org/virgo/schema/plan/eclipse-virgo-plan.xsd\"";
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ File generatedPlanDirectory = new File(GENERATED_PLAN_DIRECTORY);
+ generatedPlanDirectory.mkdirs();
+ }
+
+ @Test
+ public void testUriInPlan() throws IOException, DeploymentException, InterruptedException {
+ TestArtifactInfo planInfo = createPlanFile("uriplan", Version.emptyVersion, false, false,
+ new File(TEST_RESOURCES_DIRECTORY + "global.jar").toURI().toString());
+ testPlan(planInfo);
+ }
+
+ @Test
+ public void testBundleAndConfigUrisInPlan() throws IOException, DeploymentException, InterruptedException {
+ TestArtifactInfo planInfo = createPlanFile("uriplan", Version.emptyVersion, false, false, new File(TEST_RESOURCES_DIRECTORY
+ + "com.foo.bar.properties").toURI().toString(), new File(TEST_RESOURCES_DIRECTORY + "global.jar").toURI().toString());
+ testPlan(planInfo);
+ }
+
+ @Test(expected = DeploymentException.class)
+ public void testNonFileUriInPlan() throws IOException, DeploymentException, InterruptedException {
+ TestArtifactInfo planInfo = createPlanFile("uriplan", Version.emptyVersion, false, false, "http://www.eclipse.org");
+ testPlan(planInfo);
+ }
+
+ @Test(expected = DeploymentException.class)
+ public void testRelativeUriInPlan() throws IOException, DeploymentException, InterruptedException {
+ TestArtifactInfo planInfo = createPlanFile("uriplan", Version.emptyVersion, false, false, "file:" + TEST_RESOURCES_DIRECTORY + "global.jar");
+ testPlan(planInfo);
+ }
+
+ private void testPlan(TestArtifactInfo plan) throws DeploymentException {
+ DeploymentIdentity parentId = deploy(plan);
+ this.deployer.undeploy(parentId);
+ }
+
+ private DeploymentIdentity deploy(TestArtifactInfo i) throws DeploymentException {
+ DeploymentIdentity identity = this.deployer.deploy(i.getFile().toURI());
+ Assert.assertEquals(i.getType(), identity.getType());
+ Assert.assertEquals(i.getName(), identity.getSymbolicName());
+ Assert.assertEquals(i.getVersion(), new Version(identity.getVersion()));
+ return identity;
+ }
+
+ public static TestArtifactInfo createPlanFile(String planName, Version planVersion, boolean scoped, boolean atomic, String... uris)
+ throws IOException {
+ StringBuffer planContent = new StringBuffer(1024);
+ planContent.append(XML_HEADER);
+ planContent.append("<plan name=\"" + planName + "\" version=\"" + planVersion + "\" scoped=\"" + new Boolean(scoped) + "\" atomic=\""
+ + new Boolean(atomic) + "\" \n" + NAMESPACES + ">\n");
+
+ for (String uri : uris) {
+ planContent.append(" <artifact uri=\"" + uri + "\"/>\n");
+ }
+
+ planContent.append("</plan>");
+
+ TestArtifactInfo info = new TestArtifactInfo(PLAN_TYPE, planName, planVersion);
+
+ String fileName = planName + "-" + planVersion + PLAN_EXTENSION;
+ File planFile = new File(GENERATED_PLAN_DIRECTORY + fileName);
+ Writer writer = new FileWriter(planFile);
+ try {
+ writer.write(planContent.toString());
+ } finally {
+ writer.close();
+ }
+
+ info.setFile(planFile);
+
+ return info;
+ }
+
+ private static class TestArtifactInfo {
+
+ private final String type;
+
+ private final String name;
+
+ private final Version version;
+
+ private File file;
+
+ public TestArtifactInfo(String type, String name, Version version) {
+ this.type = type;
+ this.name = name;
+ this.version = version;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Version getVersion() {
+ return version;
+ }
+
+ public void setFile(File file) {
+ this.file = file;
+ }
+
+ public File getFile() {
+ if (this.file == null) {
+ throw new IllegalStateException("TestArtifactInfo file not set");
+ }
+ return file;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return name;
+ }
+
+ }
+
+}

Back to the top