You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ace.apache.org by br...@apache.org on 2013/07/23 20:37:10 UTC

svn commit: r1506202 - /ace/trunk/org.apache.ace.client.rest.itest/src/org/apache/ace/client/rest/itest/RESTClientTest.java

Author: bramk
Date: Tue Jul 23 18:37:10 2013
New Revision: 1506202

URL: http://svn.apache.org/r1506202
Log:
ACE-340 Cleanup/stabilize REST itest

Modified:
    ace/trunk/org.apache.ace.client.rest.itest/src/org/apache/ace/client/rest/itest/RESTClientTest.java

Modified: ace/trunk/org.apache.ace.client.rest.itest/src/org/apache/ace/client/rest/itest/RESTClientTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.rest.itest/src/org/apache/ace/client/rest/itest/RESTClientTest.java?rev=1506202&r1=1506201&r2=1506202&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.rest.itest/src/org/apache/ace/client/rest/itest/RESTClientTest.java (original)
+++ ace/trunk/org.apache.ace.client.rest.itest/src/org/apache/ace/client/rest/itest/RESTClientTest.java Tue Jul 23 18:37:10 2013
@@ -1,3 +1,21 @@
+/*
+ * 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.
+ */
 package org.apache.ace.client.rest.itest;
 
 import java.io.BufferedWriter;
@@ -32,16 +50,17 @@ import com.sun.jersey.api.client.WebReso
 import com.sun.jersey.api.client.config.ClientConfig;
 
 public class RESTClientTest extends IntegrationTestBase {
-	// From: ConfigurationHelper (somehow directly using them here fails)
+
+    // From: ConfigurationHelper (somehow directly using them here fails)
     public static final String KEY_FILENAME = "filename";
     public static final String MIMETYPE = "application/xml:osgi-autoconf";
-    public static final String PROCESSOR = "org.osgi.deployment.rp.autoconf";	
-	
+    public static final String PROCESSOR = "org.osgi.deployment.rp.autoconf";
+
     private static boolean m_hasBeenSetup = false;
     private volatile BundleContext m_context;
     private volatile UserAdmin m_user;
     private volatile LogReaderService m_logReader;
-    
+
     @Override
     protected Component[] getDependencies() {
         return new Component[] {
@@ -51,7 +70,7 @@ public class RESTClientTest extends Inte
                 .add(createServiceDependency().setService(LogReaderService.class).setRequired(true))
         };
     }
-    
+
     @Override
     protected void configureAdditionalServices() throws Exception {
         // there is some setup we only want to do once, before the first test we run, and since we cannot
@@ -62,143 +81,173 @@ public class RESTClientTest extends Inte
             m_hasBeenSetup = true;
         }
     }
-    
+
     /**
-     * Creates a new workspace, ensures it works correctly by asking for a list of entity types, then
-     * deletes the workspace again and ensures it's no longer available.
+     * Creates a new workspace, ensures it works correctly by asking for a list of entity types, then deletes the
+     * workspace again and ensures it's no longer available.
      */
     public void testCreateAndDestroyRESTSession() throws Exception {
-        Client c = Client.create();
-        c.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false);
-        WebResource r = c.resource("http://localhost:8080/client/work");
+        Client client = Client.create();
+        client.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false);
         try {
-            r.post(String.class, "");
-            fail("We should have been redirected to a new workspace.");
-        }
-        catch (UniformInterfaceException e) {
-            ClientResponse response = e.getResponse();
-            URI location = response.getLocation();
-            assertTrue(location.toString().startsWith("http://localhost:8080/client/work/rest-"));
-            WebResource r2 = c.resource(location);
-            r2.get(String.class);            
-            r2.delete();
+            WebResource r = client.resource("http://localhost:8080/client/work");
             try {
+                r.post(String.class, "");
+                fail("We should have been redirected to a new workspace.");
+            }
+            catch (UniformInterfaceException e) {
+                ClientResponse response = e.getResponse();
+                URI location = response.getLocation();
+                assertTrue(location.toString().startsWith("http://localhost:8080/client/work/rest-"));
+                WebResource r2 = client.resource(location);
                 r2.get(String.class);
+                r2.delete();
+                try {
+                    r2.get(String.class);
+                }
+                catch (UniformInterfaceException e2) {
+                    assertEquals(404, e2.getResponse().getStatus());
+                }
             }
-            catch (UniformInterfaceException e2) {
-                assertEquals(404, e2.getResponse().getStatus());
+        }
+        catch (Exception e) {
+            showBundles();
+            showLog();
+            throw e;
+        }
+    }
+
+    /**
+     * Creates and deletes a number of workspaces.
+     */
+    public void testCreateAndDeleteMultipleWorkspaces() throws Exception {
+        Client client = Client.create();
+        client.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false);
+        try {
+            int nr = 10;
+            for (int i = 0; i < nr; i++) {
+                WebResource w1 = createWorkspace(client);
+                w1.delete();
+            }
+            WebResource[] w = new WebResource[nr];
+            for (int i = 0; i < w.length; i++) {
+                w[i] = createWorkspace(client);
+            }
+            for (int i = 0; i < w.length; i++) {
+                w[i].delete();
             }
         }
+        catch (Exception e) {
+            showBundles();
+            showLog();
+            throw e;
+        }
     }
 
     /**
-     * Creates a workspace, three bundle artifacts that are associated to three features. The features are all grouped into
-     * a single distribution, and the distribution is associated with a target. This workspace is then committed and a new
-     * workspace is opened. From this new workspace, we read back the entities we committed before. Then, we check if this
-     * has indeed led to a new version of the software for this target.
+     * Creates a workspace, three bundle artifacts that are associated to three features. The features are all grouped
+     * into a single distribution, and the distribution is associated with a target. This workspace is then committed
+     * and a new workspace is opened. From this new workspace, we read back the entities we committed before. Then, we
+     * check if this has indeed led to a new version of the software for this target.
      */
     public void testDeployBundlesToTarget() throws Exception {
+        Client client = Client.create();
+        client.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false);
         Gson gson = new Gson();
-        Client c = Client.create();
-        c.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false);
-        
-        File b1 = new File("b1.jar");
-        File b2 = new File("b2.jar");
-        File b3 = new File("b3.jar");
-        createBundleOnDisk(b1, "b1", "1.0.0");
-        createBundleOnDisk(b2, "b2", "1.0.0");
-        createBundleOnDisk(b3, "b3", "1.0.0");
-        b1.deleteOnExit();
-        b2.deleteOnExit();
-        b3.deleteOnExit();
-        
-        WebResource w1 = createWorkspace(c);
-        WebResource a1 = createBundle(c, w1, "a1", "b1", "1.0.0", b1.toURI().toURL().toString(), BundleHelper.MIMETYPE);
-        WebResource a2 = createBundle(c, w1, "a2", "b2", "1.0.0", b2.toURI().toURL().toString(), BundleHelper.MIMETYPE);
-        WebResource a3 = createBundle(c, w1, "a3", "b3", "1.0.0", b3.toURI().toURL().toString(), BundleHelper.MIMETYPE);
-        assertEntitiesExist(a1, a2, a3);
-        WebResource a1f1 = createAssociationA2F(c, w1, "artifact2feature", "a1", "f1");
-        WebResource a2f2 = createAssociationA2F(c, w1, "artifact2feature", "a2", "f2");
-        WebResource a3f3 = createAssociationA2F(c, w1, "artifact2feature", "a3", "f3");
-        assertEntitiesExist(a1f1, a2f2, a3f3);
-        WebResource f1 = createFeature(c, w1, "f1");
-        WebResource f2 = createFeature(c, w1, "f2");
-        WebResource f3 = createFeature(c, w1, "f3");
-        assertEntitiesExist(f1, f2, f3);
-        WebResource f1d1 = createAssociationF2D(c, w1, "feature2distribution", "f1", "d1");
-        WebResource f2d1 = createAssociationF2D(c, w1, "feature2distribution", "f2", "d1");
-        WebResource f3d1 = createAssociationF2D(c, w1, "feature2distribution", "f3", "d1");
-        assertEntitiesExist(f1d1, f2d1, f3d1);
-        WebResource d1 = createDistribution(c, w1, "d1");
-        assertEntitiesExist(d1);
-        WebResource d1t1 = createAssociationD2T(c, w1, "distribution2target", "d1", "t1");
-        assertEntitiesExist(d1t1);
-        WebResource t1 = createTarget(c, w1, "t1");
-        assertEntitiesExist(t1);
-        w1.post();
-        w1.delete();
-        
-        WebResource w2 = createWorkspace(c);
-        assertResources(gson, w2, "artifact", 3);
-        assertResources(gson, w2, "artifact2feature", 3);
-        assertResources(gson, w2, "feature", 3);
-        assertResources(gson, w2, "feature2distribution", 3);
-        assertResources(gson, w2, "distribution", 1);
-        assertResources(gson, w2, "distribution2target", 1);
-        assertResources(gson, w2, "target", 1);
-        w2.delete();
-        
-        WebResource t1versions = c.resource("http://localhost:8080/deployment/t1/versions");
-        assertEquals("1.0.0\n", t1versions.get(String.class));
+        try {
+            File b1 = createTmpBundleOnDisk("foo.b1", "1.0.0");
+            File b2 = createTmpBundleOnDisk("foo.b2", "1.0.0");
+            File b3 = createTmpBundleOnDisk("foo.b3", "1.0.0");
+
+            WebResource w1 = createWorkspace(client);
+            deleteResources(gson, w1);
+            
+            WebResource a1 = createBundle(client, w1, "foo.a1", "foo.b1", "1.0.0", b1.toURI().toURL().toString(), BundleHelper.MIMETYPE);
+            WebResource a2 = createBundle(client, w1, "foo.a2", "foo.b2", "1.0.0", b2.toURI().toURL().toString(), BundleHelper.MIMETYPE);
+            WebResource a3 = createBundle(client, w1, "foo.a3", "foo.b3", "1.0.0", b3.toURI().toURL().toString(), BundleHelper.MIMETYPE);
+            assertEntitiesExist(a1, a2, a3);
+            WebResource a1f1 = createAssociationA2F(client, w1, "artifact2feature", "foo.a1", "foo.f1");
+            WebResource a2f2 = createAssociationA2F(client, w1, "artifact2feature", "foo.a2", "foo.f2");
+            WebResource a3f3 = createAssociationA2F(client, w1, "artifact2feature", "foo.a3", "foo.f3");
+            assertEntitiesExist(a1f1, a2f2, a3f3);
+            WebResource f1 = createFeature(client, w1, "foo.f1");
+            WebResource f2 = createFeature(client, w1, "foo.f2");
+            WebResource f3 = createFeature(client, w1, "foo.f3");
+            assertEntitiesExist(f1, f2, f3);
+            WebResource f1d1 = createAssociationF2D(client, w1, "feature2distribution", "foo.f1", "foo.d1");
+            WebResource f2d1 = createAssociationF2D(client, w1, "feature2distribution", "foo.f2", "foo.d1");
+            WebResource f3d1 = createAssociationF2D(client, w1, "feature2distribution", "foo.f3", "foo.d1");
+            assertEntitiesExist(f1d1, f2d1, f3d1);
+            WebResource d1 = createDistribution(client, w1, "foo.d1");
+            assertEntitiesExist(d1);
+            WebResource d1t1 = createAssociationD2T(client, w1, "distribution2target", "foo.d1", "foo.t1");
+            assertEntitiesExist(d1t1);
+            WebResource t1 = createTarget(client, w1, "foo.t1");
+            assertEntitiesExist(t1);
+            w1.post();
+            w1.delete();
+
+            WebResource w2 = createWorkspace(client);
+            assertResources(gson, w2, "artifact", 3);
+            assertResources(gson, w2, "artifact2feature", 3);
+            assertResources(gson, w2, "feature", 3);
+            assertResources(gson, w2, "feature2distribution", 3);
+            assertResources(gson, w2, "distribution", 1);
+            assertResources(gson, w2, "distribution2target", 1);
+            assertResources(gson, w2, "target", 1);
+            w2.post();
+            w2.delete();
+
+            WebResource t1versions = client.resource("http://localhost:8080/deployment/foo.t1/versions");
+            assertEquals("1.0.0\n", t1versions.get(String.class));
+        }
+        catch (Exception e) {
+            showBundles();
+            showLog();
+            throw e;
+        }
     }
 
     public void testDeployConfigurationTemplateToTargets() throws Exception {
+        Client client = Client.create();
+        client.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false);
+        Gson gson = new Gson();
         try {
-            Client c = Client.create();
-            c.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false);
+            File bundle = createTmpBundleOnDisk("rp", "1.0.0", BundleHelper.KEY_RESOURCE_PROCESSOR_PID, PROCESSOR, "DeploymentPackage-Customizer", "true");
+            File config = createTmpConfigOnDisk(
+                "<MetaData xmlns='http://www.osgi.org/xmlns/metatype/v1.0.0'>\n" +
+                    "  <OCD name='ocd' id='ocd'>\n" +
+                    "    <AD id='name' type='STRING' cardinality='0' />\n" +
+                    "  </OCD>\n" +
+                    "  <Designate pid='simple' bundle='osgi-dp:location'>\n" +
+                    "    <Object ocdref='ocd'>\n" +
+                    "      <Attribute adref='name'>\n" +
+                    "        <Value><![CDATA[${context.test}]]></Value>\n" +
+                    "      </Attribute>\n" +
+                    "    </Object>\n" +
+                    "  </Designate>\n" +
+                    "</MetaData>\n"
+                );
+
+            WebResource w1 = createWorkspace(client);
+            deleteResources(gson, w1);
             
-            File config = new File("template.xml");
-            BufferedWriter bw = new BufferedWriter(new FileWriter(config));
-            bw.write(
-                "<MetaData xmlns='http://www.osgi.org/xmlns/metatype/v1.0.0'>\n" + 
-                "  <OCD name='ocd' id='ocd'>\n" + 
-                "    <AD id='name' type='STRING' cardinality='0' />\n" + 
-                "  </OCD>\n" + 
-                "  <Designate pid='simple' bundle='osgi-dp:location'>\n" + 
-                "    <Object ocdref='ocd'>\n" + 
-                "      <Attribute adref='name'>\n" + 
-                "        <Value><![CDATA[${context.test}]]></Value>\n" + 
-                "      </Attribute>\n" + 
-                "    </Object>\n" + 
-                "  </Designate>\n" + 
-                "</MetaData>\n"
-            );
-            bw.close();
-            config.deleteOnExit();
-            File rp = new File("rp.jar");
-            createBundleOnDisk(rp, "rp", "1.0.0", BundleHelper.KEY_RESOURCE_PROCESSOR_PID, PROCESSOR, "DeploymentPackage-Customizer", "true");
-            rp.deleteOnExit();
-
-            WebResource w1 = createWorkspace(c);
-            createResourceProcessor(c, w1, "rp", "resourceprocessor", "1.0.0", rp.toURI().toURL().toString(), BundleHelper.MIMETYPE, PROCESSOR);
-            createConfiguration(c, w1, "c1", config.toURI().toURL().toString(), MIMETYPE, "template.xml", PROCESSOR);
-            createAssociationA2F(c, w1, "artifact2feature", "c1", "f4");
-            createFeature(c, w1, "f4");
-            createAssociationF2D(c, w1, "feature2distribution", "f4", "d2");
-            createDistribution(c, w1, "d2");
-            createAssociationD2T(c, w1, "distribution2target", "d2", "t4");
-            createAssociationD2T(c, w1, "distribution2target", "d2", "t5");
-            createAssociationD2T(c, w1, "distribution2target", "d2", "t6");
-            createTarget(c, w1, "t4", "test", "one");
-            createTarget(c, w1, "t5", "test", "two");
-            createTarget(c, w1, "t6", "test", "three");
+            createResourceProcessor(client, w1, "rp", "resourceprocessor", "1.0.0", bundle.toURI().toURL().toString(), BundleHelper.MIMETYPE, PROCESSOR);
+            createConfiguration(client, w1, "c1", config.toURI().toURL().toString(), MIMETYPE, "template.xml", PROCESSOR);
+            createAssociationA2F(client, w1, "artifact2feature", "c1", "f4");
+            createFeature(client, w1, "f4");
+            createAssociationF2D(client, w1, "feature2distribution", "f4", "d2");
+            createDistribution(client, w1, "d2");
+            createAssociationD2T(client, w1, "distribution2target", "d2", "t4");
+            createAssociationD2T(client, w1, "distribution2target", "d2", "t5");
+            createAssociationD2T(client, w1, "distribution2target", "d2", "t6");
+            createTarget(client, w1, "t4", "test", "one");
+            createTarget(client, w1, "t5", "test", "two");
+            createTarget(client, w1, "t6", "test", "three");
             w1.post();
             w1.delete();
-            
-            /* TODO: temporarily disabled these checks, because between test methods nothing
-             * is cleaned up right now and this part of the test does rely on that
-            Gson gson = new Gson();
-            WebResource w2 = createWorkspace(c);
+
+            WebResource w2 = createWorkspace(client);
             assertResources(gson, w2, "artifact", 1);
             assertResources(gson, w2, "artifact2feature", 1);
             assertResources(gson, w2, "feature", 1);
@@ -207,16 +256,58 @@ public class RESTClientTest extends Inte
             assertResources(gson, w2, "distribution2target", 3);
             assertResources(gson, w2, "target", 3);
             w2.delete();
-             */
 
-            // just for debugging
-            showLog();
+            WebResource t1versions = client.resource("http://localhost:8080/deployment/t4/versions");
+            assertEquals("1.0.0\n", t1versions.get(String.class));
+        }
+        catch (Exception e) {
             showBundles();
+            showLog();
+            throw e;
+        }
+    }
+
+    /**
+     * Creates two bundles, artifacts an a single target and then in a loop creates two features that link to the bundle
+     * artifacts, one distribution and links all of that to the target. Even though we create a lot of entities that
+     * way, all of them will result in the two bundles being deployed to the target so we end up with only a single
+     * deployment version.
+     */
+    public void testCreateLotsOfEntities() throws Exception {
+        Client client = Client.create();
+        client.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false);
+        Gson gson = new Gson();
+        try {
+            int nr = 20;
+            File b1 = createTmpBundleOnDisk("bar.b1", "1.0.0");
+            File b2 = createTmpBundleOnDisk("bar.b2", "1.0.0");
+
+            WebResource w1 = createWorkspace(client);            
+            deleteResources(gson, w1);
+            createBundle(client, w1, "bar.a1", "bar.b1", "1.0.0", b1.toURI().toURL().toString(), BundleHelper.MIMETYPE);
+            createBundle(client, w1, "bar.a2", "bar.b2", "1.0.0", b2.toURI().toURL().toString(), BundleHelper.MIMETYPE);
+            createTarget(client, w1, "bar.t1");
+            w1.post();
+            w1.delete();
             
-            WebResource t1versions = c.resource("http://localhost:8080/deployment/t4/versions");
+            for (int i = 0; i < nr; i++) {
+                WebResource w2 = createWorkspace(client);
+                createAssociationA2F(client, w2, "artifact2feature", "bar.a1", "feat-1-" + i);
+                createAssociationA2F(client, w2, "artifact2feature", "bar.a2", "feat-2-" + i);
+                createFeature(client, w2, "feat-1-" + i);
+                createFeature(client, w2, "feat-2-" + i);
+                createAssociationF2D(client, w2, "feature2distribution", "feat-1-" + i, "dist-" + i);
+                createAssociationF2D(client, w2, "feature2distribution", "feat-2-" + i, "dist-" + i);
+                createDistribution(client, w2, "dist-" + i);
+                createAssociationD2T(client, w2, "distribution2target", "dist-" + i, "bar.t1");
+                w2.post();
+                w2.delete();
+            }
+            WebResource t1versions = client.resource("http://localhost:8080/deployment/bar.t1/versions");
             assertEquals("1.0.0\n", t1versions.get(String.class));
         }
         catch (Exception e) {
+            showBundles();
             showLog();
             throw e;
         }
@@ -224,7 +315,7 @@ public class RESTClientTest extends Inte
 
     /** Shows all log messages in the OSGi log service. */
     private void showLog() {
-        Enumeration e = m_logReader.getLog();
+        Enumeration<?> e = m_logReader.getLog();
         System.out.println("Log:");
         while (e.hasMoreElements()) {
             LogEntry entry = (LogEntry) e.nextElement();
@@ -242,78 +333,17 @@ public class RESTClientTest extends Inte
         }
     }
 
-    /**
-     * Creates and deletes a number of workspaces.
-     */
-    public void testCreateAndDeleteMultipleWorkspaces() throws Exception {
-        int nr = 10;
-        Client c = Client.create();
-        c.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false);
-        for (int i = 0; i < nr; i++) {
-            WebResource w1 = createWorkspace(c);
-            w1.delete();
-        }
-        WebResource[] w = new WebResource[nr];
-        for (int i = 0; i < w.length; i++) {
-            w[i] = createWorkspace(c);
-        }
-        for (int i = 0; i < w.length; i++) {
-            w[i].delete();
-        }
-    }
-    
-    /**
-     * Creates two bundles, artifacts an a single target and then in a loop creates two
-     * features that link to the bundle artifacts, one distribution and links all of that
-     * to the target. Even though we create a lot of entities that way, all of them will
-     * result in the two bundles being deployed to the target so we end up with only a single
-     * deployment version.
-     */
-    public void testCreateLotsOfEntities() throws Exception {
-        int nr = 20;
-        Client c = Client.create();
-        c.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false);
-        
-        File b1 = new File("b1.jar");
-        File b2 = new File("b2.jar");
-        createBundleOnDisk(b1, "b1", "1.0.0");
-        createBundleOnDisk(b2, "b2", "1.0.0");
-        b1.deleteOnExit();
-        b2.deleteOnExit();
-        
-        WebResource w1 = createWorkspace(c);
-        createBundle(c, w1, "a1", "b1", "1.0.0", b1.toURI().toURL().toString(), BundleHelper.MIMETYPE);
-        createBundle(c, w1, "a2", "b2", "1.0.0", b2.toURI().toURL().toString(), BundleHelper.MIMETYPE);
-        createTarget(c, w1, "t1");
-        w1.post();
-        w1.delete();
-        for (int i = 0; i < nr; i++) {
-            WebResource w = createWorkspace(c);
-            createAssociationA2F(c, w, "artifact2feature", "a1", "feat-1-" + i);
-            createAssociationA2F(c, w, "artifact2feature", "a2", "feat-2-" + i);
-            createFeature(c, w, "feat-1-" + i);
-            createFeature(c, w, "feat-2-" + i);
-            createAssociationF2D(c, w, "feature2distribution", "feat-1-" + i, "dist-" + i);
-            createAssociationF2D(c, w, "feature2distribution", "feat-2-" + i, "dist-" + i);
-            createDistribution(c, w, "dist-" + i);
-            createAssociationD2T(c, w, "distribution2target", "dist-" + i, "t1");
-            w.post();
-            w.delete();
-        }
-        WebResource t1versions = c.resource("http://localhost:8080/deployment/t1/versions");
-        assertEquals("1.0.0\n", t1versions.get(String.class));
-    }    
-    
     /** Asserts that a list of entities exist by trying to GET them. */
     private void assertEntitiesExist(WebResource... entities) throws Exception {
         for (WebResource r : entities) {
+            System.out.println(r.getURI().toString());
             r.get(String.class);
         }
     }
-    
+
     /**
-     * Asserts that a collection of resources exist by trying to GET the list, validate the
-     * number of items and finally GET each item.
+     * Asserts that a collection of resources exist by trying to GET the list, validate the number of items and finally
+     * GET each item.
      */
     private void assertResources(Gson gson, WebResource w2, String type, int number) {
         String[] artifacts = gson.fromJson(w2.path(type).get(String.class), String[].class);
@@ -371,7 +401,7 @@ public class RESTClientTest extends Inte
             ArtifactObject.KEY_PROCESSOR_PID + ": \"" + processorID + "\"" +
             "}, tags: {}}");
     }
-    
+
     /** Creates a feature. */
     private WebResource createFeature(Client c, WebResource work, String name) throws IOException {
         return createEntity(c, work, "feature", "{attributes: {name: \"" + name + "\"}, tags: {}}");
@@ -403,7 +433,7 @@ public class RESTClientTest extends Inte
     private WebResource createAssociationF2D(Client c, WebResource work, String type, String left, String right) throws IOException {
         return createEntity(c, work, type, "{attributes: {leftEndpoint: \"(name=" + left + ")\", rightEndpoint=\"(name=" + right + ")\", leftCardinality: \"1\", rightCardinality=\"1\"}, tags: {}}");
     }
-    
+
     /** Creates an association between a distribution and a target. */
     private WebResource createAssociationD2T(Client c, WebResource work, String type, String left, String right) throws IOException {
         return createEntity(c, work, type, "{attributes: {leftEndpoint: \"(name=" + left + ")\", rightEndpoint=\"(id=" + right + ")\", leftCardinality: \"1\", rightCardinality=\"1\"}, tags: {}}");
@@ -421,29 +451,75 @@ public class RESTClientTest extends Inte
         }
     }
 
-    /** Creates a bundle on disk, using the specified file, symbolic name and version. */
-    private void createBundleOnDisk(File f, String bsn, String v, String... headers) throws Exception {
+    private void deleteResources(Gson gson, WebResource workspace) {
+        deleteResources(gson, workspace, "artifact");
+        deleteResources(gson, workspace, "artifact2feature");
+        deleteResources(gson, workspace, "feature");
+        deleteResources(gson, workspace, "feature2distribution");
+        deleteResources(gson, workspace, "distribution");
+        deleteResources(gson, workspace, "distribution2target");
+        deleteResources(gson, workspace, "target");
+    }
+
+    private void deleteResources(Gson gson, WebResource workspace, String type) {
+        String[] artifacts = gson.fromJson(workspace.path(type).get(String.class), String[].class);
+        for (String id : artifacts) {
+            workspace.path(type + "/" + id).delete();
+        }
+    }
+
+    private File createTmpBundleOnDisk(String bsn, String v, String... headers) throws Exception {
+        File file = File.createTempFile("bundle", ".jar");
+        file.deleteOnExit();
         Builder b = new Builder();
         try {
-	        b.setProperty("Bundle-SymbolicName", bsn);
-	        b.setProperty("Bundle-Version", v);
-	        for (int i = 0; i < headers.length; i += 2) {
-	            b.setProperty(headers[i], headers[i + 1]);
-	        }
-	        Jar jar = b.build();
-	        jar.getManifest(); // Not sure whether this is needed...
-	        jar.write(f);
-        } finally {
-        	b.close();
+            b.setProperty("Bundle-SymbolicName", bsn);
+            b.setProperty("Bundle-Version", v);
+            for (int i = 0; i < headers.length; i += 2) {
+                b.setProperty(headers[i], headers[i + 1]);
+            }
+            Jar jar = b.build();
+            jar.getManifest(); // Not sure whether this is needed...
+            jar.write(file);
+            return file;
+        }
+        finally {
+            b.close();
+        }
+    }
+
+    private File createTmpConfigOnDisk(String config) throws Exception {
+        File file = File.createTempFile("template", ".xml");
+        file.deleteOnExit();
+        BufferedWriter bw = new BufferedWriter(new FileWriter(file));
+        try {
+            bw.write(
+                "<MetaData xmlns='http://www.osgi.org/xmlns/metatype/v1.0.0'>\n" +
+                    "  <OCD name='ocd' id='ocd'>\n" +
+                    "    <AD id='name' type='STRING' cardinality='0' />\n" +
+                    "  </OCD>\n" +
+                    "  <Designate pid='simple' bundle='osgi-dp:location'>\n" +
+                    "    <Object ocdref='ocd'>\n" +
+                    "      <Attribute adref='name'>\n" +
+                    "        <Value><![CDATA[${context.test}]]></Value>\n" +
+                    "      </Attribute>\n" +
+                    "    </Object>\n" +
+                    "  </Designate>\n" +
+                    "</MetaData>\n"
+                );
+            return file;
+        }
+        finally {
+            bw.close();
         }
     }
-    
+
     /** Configure the server for this test. */
     private void configureServer() throws IOException {
         configure("org.apache.ace.client.rest",
             "org.apache.ace.server.servlet.endpoint", "/client",
             "authentication.enabled", "false");
-        
+
         configure("org.apache.ace.deployment.servlet",
             "org.apache.ace.server.servlet.endpoint", "/deployment",
             "authentication.enabled", "false");
@@ -466,24 +542,23 @@ public class RESTClientTest extends Inte
 
         configure("org.apache.ace.discovery.property",
             "serverURL", "http://localhost:8080");
-        
+
         configure("org.apache.ace.identification.property",
             "targetID", "target-test");
-        
+
         configureFactory("org.apache.ace.log.server.servlet.factory",
             "name", "auditlog",
             HttpConstants.ENDPOINT, "/auditlog",
             "authentication.enabled", "false");
-    
+
         configureFactory("org.apache.ace.log.server.store.factory",
             "name", "auditlog");
-        
+
         configureFactory("org.apache.ace.server.repository.factory",
             "name", "user",
             "customer", "apache",
-            "master", "true"
-            );
-        
+            "master", "true");
+
         configureFactory("org.apache.ace.server.repository.factory",
             "name", "shop",
             "customer", "apache",
@@ -503,13 +578,13 @@ public class RESTClientTest extends Inte
             "name", "users",
             "customer", "apache",
             "master", "true");
-        
+
         configure("org.apache.ace.configurator.useradmin.task.UpdateUserAdminTask",
             "repositoryLocation", "http://localhost:8080/repository",
             "repositoryCustomer", "apache",
             "repositoryName", "user");
     }
-    
+
     /** Create a user so we can log in to the server. */
     @SuppressWarnings("unchecked")
     private void createServerUser() {