You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ace.apache.org by ja...@apache.org on 2013/10/14 16:31:57 UTC

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

Author: jawi
Date: Mon Oct 14 14:31:56 2013
New Revision: 1531910

URL: http://svn.apache.org/r1531910
Log:
Small refactoring:

- moved all REST-specific methods into a separate utility class;
- simplified some of the method calls.


Added:
    ace/trunk/org.apache.ace.client.rest.itest/src/org/apache/ace/client/rest/itest/ClientRestUtils.java   (with props)
Modified:
    ace/trunk/org.apache.ace.client.rest.itest/src/org/apache/ace/client/rest/itest/RESTClientTest.java

Added: ace/trunk/org.apache.ace.client.rest.itest/src/org/apache/ace/client/rest/itest/ClientRestUtils.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.rest.itest/src/org/apache/ace/client/rest/itest/ClientRestUtils.java?rev=1531910&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.client.rest.itest/src/org/apache/ace/client/rest/itest/ClientRestUtils.java (added)
+++ ace/trunk/org.apache.ace.client.rest.itest/src/org/apache/ace/client/rest/itest/ClientRestUtils.java Mon Oct 14 14:31:56 2013
@@ -0,0 +1,242 @@
+/*
+ * 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 static junit.framework.Assert.*;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.apache.ace.test.utils.FileUtils;
+
+import aQute.lib.osgi.Builder;
+import aQute.lib.osgi.Jar;
+
+import com.google.gson.Gson;
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.UniformInterfaceException;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.client.config.ClientConfig;
+
+/**
+ * Helper methods for talking to the ACE client through REST.
+ */
+public class ClientRestUtils {
+
+    /** Asserts that a list of entities exist by trying to GET them. */
+    public static 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.
+     */
+    public static void assertResources(Gson gson, WebResource w2, String type, int number) {
+        String[] artifacts = gson.fromJson(w2.path(type).get(String.class), String[].class);
+        assertEquals("Wrong number of " + type + "s", number, artifacts.length);
+        for (String id : artifacts) {
+            w2.path(type + "/" + id).get(String.class);
+        }
+    }
+
+    /** Creates an association between an artifact and a feature. */
+    public static WebResource createAssociationA2F(Client c, WebResource work, String left, String right) throws IOException {
+        return createEntity(c, work, "artifact2feature", "{attributes: {leftEndpoint: \"(artifactName=" + left + ")\", rightEndpoint=\"(name=" + right + ")\", leftCardinality: \"1\", rightCardinality=\"1\"}, tags: {}}");
+    }
+
+    /** Creates an association between a distribution and a target. */
+    public static WebResource createAssociationD2T(Client c, WebResource work, String left, String right) throws IOException {
+        return createEntity(c, work, "distribution2target", "{attributes: {leftEndpoint: \"(name=" + left + ")\", rightEndpoint=\"(id=" + right + ")\", leftCardinality: \"1\", rightCardinality=\"1\"}, tags: {}}");
+    }
+
+    /** Creates an association between a feature and a distribution. */
+    public static WebResource createAssociationF2D(Client c, WebResource work, String left, String right) throws IOException {
+        return createEntity(c, work, "feature2distribution", "{attributes: {leftEndpoint: \"(name=" + left + ")\", rightEndpoint=\"(name=" + right + ")\", leftCardinality: \"1\", rightCardinality=\"1\"}, tags: {}}");
+    }
+
+    /** Creates a bundle artifact. */
+    public static WebResource createBundleArtifact(Client c, WebResource work, String name, String bsn, String v, File file) throws IOException {
+        return createBundleArtifact(c, work, name, bsn, v, file.toURI().toURL().toExternalForm());
+    }
+
+    /** Creates a bundle artifact. */
+    public static WebResource createBundleArtifact(Client c, WebResource work, String name, String bsn, String v, String url) throws IOException {
+        return createArtifact(c, work, name, bsn, v, url, "application/vnd.osgi.bundle");
+    }
+
+    /** Creates a bundle artifact. */
+    public static WebResource createArtifact(Client c, WebResource work, String name, String bsn, String v, String url, String mimetype) throws IOException {
+        return createEntity(c, work, "artifact", "{attributes: {" +
+            "artifactName: \"" + name + "\", " +
+            "Bundle-SymbolicName: \"" + bsn + "\", " +
+            "Bundle-Version: \"" + v + "\", " +
+            "mimetype: \"" + mimetype + "\", " +
+            "url: \"" + url + "\"" +
+            "}, tags: {}}");
+    }
+
+    /** Creates a configuration artifact. */
+    public static WebResource createConfiguration(Client c, WebResource work, String name, String url, String mimetype, String filename, String processorID) throws IOException {
+        return createEntity(c, work, "artifact", "{attributes: {" +
+            "artifactName: \"" + name + "\", " +
+            "filename: \"" + filename + "\", " +
+            "mimetype: \"" + mimetype + "\", " +
+            "url: \"" + url + "\", " +
+            "processorPid: \"" + processorID + "\"" +
+            "}, tags: {}}");
+    }
+
+    /** creates a new REST-client. */
+    public static Client createClient() {
+        Client client = Client.create();
+        client.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false);
+        return client;
+    }
+
+    /** Creates a distribution. */
+    public static WebResource createDistribution(Client c, WebResource work, String name) throws IOException {
+        return createEntity(c, work, "distribution", "{attributes: {name: \"" + name + "\"}, tags: {}}");
+    }
+
+    /** Creates an entity. */
+    public static WebResource createEntity(Client c, WebResource work, String type, String data) throws IOException {
+        WebResource entity = work.path(type);
+        try {
+            entity.post(String.class, data);
+            throw new IOException("Could not create " + type + " with data " + data);
+        }
+        catch (UniformInterfaceException e2) {
+            return c.resource(e2.getResponse().getLocation());
+        }
+    }
+
+    /** Creates a feature. */
+    public static WebResource createFeature(Client c, WebResource work, String name) throws IOException {
+        return createEntity(c, work, "feature", "{attributes: {name: \"" + name + "\"}, tags: {}}");
+    }
+
+    /** Creates a resource processor bundle artifact. */
+    public static WebResource createResourceProcessor(Client c, WebResource work, String name, String bsn, String v, String url, String mimetype, String processorID) throws IOException {
+        return createEntity(c, work, "artifact", "{attributes: {" +
+            "artifactName: \"" + name + "\", " +
+            "description: \"\", " +
+            "Bundle-SymbolicName: \"" + bsn + "\", " +
+            "Bundle-Version: \"" + v + "\", " +
+            "mimetype: \"" + mimetype + "\", " +
+            "Deployment-ProvidesResourceProcessor: \"" + processorID + "\", " +
+            "DeploymentPackage-Customizer: \"true\", " +
+            "url: \"" + url + "\"" +
+            "}, tags: {}}");
+    }
+
+    /** Creates a target. */
+    public static WebResource createTarget(Client c, WebResource work, String name, String... tags) throws IOException {
+        StringBuffer result = new StringBuffer();
+        for (int i = 0; i < tags.length; i += 2) {
+            if (result.length() > 0) {
+                result.append(", ");
+            }
+            result.append(tags[i] + ": \"" + tags[i + 1] + "\"");
+        }
+        return createEntity(c, work, "target", "{attributes: {id: \"" + name + "\", autoapprove: \"true\"}, tags: {" + result.toString() + "}}");
+    }
+
+    public static 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(file);
+            return file;
+        }
+        finally {
+            b.close();
+        }
+    }
+
+    public static File createTmpConfigOnDisk(String config) throws Exception {
+        File file = File.createTempFile("template", ".xml");
+        file.deleteOnExit();
+        BufferedWriter bw = new BufferedWriter(new FileWriter(file));
+        try {
+            bw.write(config);
+            return file;
+        }
+        finally {
+            bw.close();
+        }
+    }
+
+    /** Creates a new workspace. */
+    public static WebResource createWorkspace(String host, Client c) {
+        WebResource r = c.resource(host.concat("/client/work"));
+        try {
+            r.post(String.class, "");
+            fail("We should have been redirected to a new workspace.");
+            return null; // to keep the compiler happy, it does not understand what fail() does
+        }
+        catch (UniformInterfaceException e) {
+            return c.resource(e.getResponse().getLocation());
+        }
+    }
+
+    public static 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");
+    }
+
+    public static 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();
+        }
+    }
+
+    public static void ensureCleanStore(String path) throws IOException {
+        File store = new File(path);
+        System.out.println("store: " + store.getAbsolutePath());
+        if (store.exists()) {
+            if (!store.isDirectory()) {
+                throw new IllegalStateException("Configured store is not a directory: " + store.getAbsolutePath());
+            }
+            FileUtils.removeDirectoryWithContent(store);
+        }
+        if (!store.mkdirs()) {
+            throw new IllegalStateException("Failed to create store directory: " + store.getAbsolutePath());
+        }
+    }
+}

Propchange: ace/trunk/org.apache.ace.client.rest.itest/src/org/apache/ace/client/rest/itest/ClientRestUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=1531910&r1=1531909&r2=1531910&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 Mon Oct 14 14:31:56 2013
@@ -18,20 +18,32 @@
  */
 package org.apache.ace.client.rest.itest;
 
-import java.io.BufferedWriter;
+import static org.apache.ace.client.rest.itest.ClientRestUtils.createAssociationA2F;
+import static org.apache.ace.client.rest.itest.ClientRestUtils.createAssociationD2T;
+import static org.apache.ace.client.rest.itest.ClientRestUtils.createAssociationF2D;
+import static org.apache.ace.client.rest.itest.ClientRestUtils.createBundleArtifact;
+import static org.apache.ace.client.rest.itest.ClientRestUtils.createClient;
+import static org.apache.ace.client.rest.itest.ClientRestUtils.createConfiguration;
+import static org.apache.ace.client.rest.itest.ClientRestUtils.createDistribution;
+import static org.apache.ace.client.rest.itest.ClientRestUtils.createFeature;
+import static org.apache.ace.client.rest.itest.ClientRestUtils.createResourceProcessor;
+import static org.apache.ace.client.rest.itest.ClientRestUtils.createTarget;
+import static org.apache.ace.client.rest.itest.ClientRestUtils.createTmpBundleOnDisk;
+import static org.apache.ace.client.rest.itest.ClientRestUtils.createTmpConfigOnDisk;
+import static org.apache.ace.client.rest.itest.ClientRestUtils.createWorkspace;
+import static org.apache.ace.client.rest.itest.ClientRestUtils.deleteResources;
+import static org.apache.ace.client.rest.itest.ClientRestUtils.ensureCleanStore;
+
 import java.io.File;
-import java.io.FileWriter;
 import java.io.IOException;
 import java.net.URI;
 import java.util.Date;
 import java.util.Enumeration;
 
 import org.apache.ace.client.repository.helper.bundle.BundleHelper;
-import org.apache.ace.client.repository.object.ArtifactObject;
 import org.apache.ace.http.listener.constants.HttpConstants;
 import org.apache.ace.it.IntegrationTestBase;
 import org.apache.ace.test.constants.TestConstants;
-import org.apache.ace.test.utils.FileUtils;
 import org.apache.felix.dm.Component;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -41,15 +53,11 @@ import org.osgi.service.useradmin.Role;
 import org.osgi.service.useradmin.User;
 import org.osgi.service.useradmin.UserAdmin;
 
-import aQute.lib.osgi.Builder;
-import aQute.lib.osgi.Jar;
-
 import com.google.gson.Gson;
 import com.sun.jersey.api.client.Client;
 import com.sun.jersey.api.client.ClientResponse;
 import com.sun.jersey.api.client.UniformInterfaceException;
 import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.config.ClientConfig;
 
 public class RESTClientTest extends IntegrationTestBase {
 
@@ -73,17 +81,16 @@ public class RESTClientTest extends Inte
      * Creates and deletes a number of workspaces.
      */
     public void testCreateAndDeleteMultipleWorkspaces() throws Exception {
-        Client client = Client.create();
-        client.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false);
+        Client client = createClient();
         try {
             int nr = 10;
             for (int i = 0; i < nr; i++) {
-                WebResource w1 = createWorkspace(client);
+                WebResource w1 = createWorkspace(HOST, client);
                 w1.delete();
             }
             WebResource[] w = new WebResource[nr];
             for (int i = 0; i < w.length; i++) {
-                w[i] = createWorkspace(client);
+                w[i] = createWorkspace(HOST, client);
             }
             for (int i = 0; i < w.length; i++) {
                 w[i].delete();
@@ -101,8 +108,7 @@ public class RESTClientTest extends Inte
      * workspace again and ensures it's no longer available.
      */
     public void testCreateAndDestroyRESTSession() throws Exception {
-        Client client = Client.create();
-        client.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false);
+        Client client = createClient();
         try {
             WebResource r = client.resource(HOST.concat("/client/work"));
             try {
@@ -138,32 +144,31 @@ public class RESTClientTest extends Inte
      * deployment version.
      */
     public void testCreateLotsOfEntities() throws Exception {
-        Client client = Client.create();
-        client.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false);
+        Client client = createClient();
         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);
+            WebResource w1 = createWorkspace(HOST, 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);
+            createBundleArtifact(client, w1, "bar.a1", "bar.b1", "1.0.0", b1);
+            createBundleArtifact(client, w1, "bar.a2", "bar.b2", "1.0.0", b2);
             createTarget(client, w1, "bar.t1");
             w1.post();
             w1.delete();
 
             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);
+                WebResource w2 = createWorkspace(HOST, client);
+                createAssociationA2F(client, w2, "bar.a1", "feat-1-" + i);
+                createAssociationA2F(client, w2, "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);
+                createAssociationF2D(client, w2, "feat-1-" + i, "dist-" + i);
+                createAssociationF2D(client, w2, "feat-2-" + i, "dist-" + i);
                 createDistribution(client, w2, "dist-" + i);
-                createAssociationD2T(client, w2, "distribution2target", "dist-" + i, "bar.t1");
+                createAssociationD2T(client, w2, "dist-" + i, "bar.t1");
                 w2.post();
                 w2.delete();
             }
@@ -184,43 +189,42 @@ public class RESTClientTest extends Inte
      * 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);
+        Client client = createClient();
         Gson gson = new Gson();
         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);
+            WebResource w1 = createWorkspace(HOST, 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);
+            WebResource a1 = createBundleArtifact(client, w1, "foo.a1", "foo.b1", "1.0.0", b1);
+            WebResource a2 = createBundleArtifact(client, w1, "foo.a2", "foo.b2", "1.0.0", b2);
+            WebResource a3 = createBundleArtifact(client, w1, "foo.a3", "foo.b3", "1.0.0", b3);
             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");
+            WebResource a1f1 = createAssociationA2F(client, w1, "foo.a1", "foo.f1");
+            WebResource a2f2 = createAssociationA2F(client, w1, "foo.a2", "foo.f2");
+            WebResource a3f3 = createAssociationA2F(client, w1, "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");
+            WebResource f1d1 = createAssociationF2D(client, w1, "foo.f1", "foo.d1");
+            WebResource f2d1 = createAssociationF2D(client, w1, "foo.f2", "foo.d1");
+            WebResource f3d1 = createAssociationF2D(client, w1, "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");
+            WebResource d1t1 = createAssociationD2T(client, w1, "foo.d1", "foo.t1");
             assertEntitiesExist(d1t1);
             WebResource t1 = createTarget(client, w1, "foo.t1");
             assertEntitiesExist(t1);
             w1.post();
             w1.delete();
 
-            WebResource w2 = createWorkspace(client);
+            WebResource w2 = createWorkspace(HOST, client);
             assertResources(gson, w2, "artifact", 3);
             assertResources(gson, w2, "artifact2feature", 3);
             assertResources(gson, w2, "feature", 3);
@@ -242,8 +246,7 @@ public class RESTClientTest extends Inte
     }
 
     public void testDeployConfigurationTemplateToTargets() throws Exception {
-        Client client = Client.create();
-        client.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false);
+        Client client = createClient();
         Gson gson = new Gson();
         try {
             File bundle = createTmpBundleOnDisk("rp", "1.0.0", BundleHelper.KEY_RESOURCE_PROCESSOR_PID, PROCESSOR, "DeploymentPackage-Customizer", "true");
@@ -262,25 +265,25 @@ public class RESTClientTest extends Inte
                     "</MetaData>\n"
                 );
 
-            WebResource w1 = createWorkspace(client);
+            WebResource w1 = createWorkspace(HOST, client);
             deleteResources(gson, w1);
 
             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");
+            createAssociationA2F(client, w1, "c1", "f4");
             createFeature(client, w1, "f4");
-            createAssociationF2D(client, w1, "feature2distribution", "f4", "d2");
+            createAssociationF2D(client, w1, "f4", "d2");
             createDistribution(client, w1, "d2");
-            createAssociationD2T(client, w1, "distribution2target", "d2", "t4");
-            createAssociationD2T(client, w1, "distribution2target", "d2", "t5");
-            createAssociationD2T(client, w1, "distribution2target", "d2", "t6");
+            createAssociationD2T(client, w1, "d2", "t4");
+            createAssociationD2T(client, w1, "d2", "t5");
+            createAssociationD2T(client, w1, "d2", "t6");
             createTarget(client, w1, "t4", "test", "one");
             createTarget(client, w1, "t5", "test", "two");
             createTarget(client, w1, "t6", "test", "three");
             w1.post();
             w1.delete();
 
-            WebResource w2 = createWorkspace(client);
+            WebResource w2 = createWorkspace(HOST, client);
             assertResources(gson, w2, "artifact", 1);
             assertResources(gson, w2, "artifact2feature", 1);
             assertResources(gson, w2, "feature", 1);
@@ -309,7 +312,7 @@ public class RESTClientTest extends Inte
             // count the number of tests, so we can determine when to clean up...
             m_totalTestCount = getTestCount();
 
-            ensureCleanStore();
+            ensureCleanStore(STOREPATH);
             configureServer();
             createServerUser();
             m_hasBeenSetup = true;
@@ -429,79 +432,6 @@ public class RESTClientTest extends Inte
             "repositoryName", "user");
     }
 
-    /** Creates an association between an artifact and a feature. */
-    private WebResource createAssociationA2F(Client c, WebResource work, String type, String left, String right) throws IOException {
-        return createEntity(c, work, type, "{attributes: {leftEndpoint: \"(artifactName=" + 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: {}}");
-    }
-
-    /** Creates an association between a feature and a distribution. */
-    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 a bundle artifact. */
-    private WebResource createBundle(Client c, WebResource work, String name, String bsn, String v, String url, String mimetype) throws IOException {
-        return createEntity(c, work, "artifact", "{attributes: {" +
-            "artifactName: \"" + name + "\", " +
-            "Bundle-SymbolicName: \"" + bsn + "\", " +
-            "Bundle-Version: \"" + v + "\", " +
-            "mimetype: \"" + mimetype + "\", " +
-            "url: \"" + url + "\"" +
-            "}, tags: {}}");
-    }
-
-    /** Creates a configuration artifact. */
-    private WebResource createConfiguration(Client c, WebResource work, String name, String url, String mimetype, String filename, String processorID) throws IOException {
-        return createEntity(c, work, "artifact", "{attributes: {" +
-            "artifactName: \"" + name + "\", " +
-            "filename: \"" + filename + "\", " +
-            "mimetype: \"" + mimetype + "\", " +
-            "url: \"" + url + "\", " +
-            ArtifactObject.KEY_PROCESSOR_PID + ": \"" + processorID + "\"" +
-            "}, tags: {}}");
-    }
-
-    /** Creates a distribution. */
-    private WebResource createDistribution(Client c, WebResource work, String name) throws IOException {
-        return createEntity(c, work, "distribution", "{attributes: {name: \"" + name + "\"}, tags: {}}");
-    }
-
-    /** Creates an entity. */
-    private WebResource createEntity(Client c, WebResource work, String type, String data) throws IOException {
-        WebResource entity = work.path(type);
-        try {
-            entity.post(String.class, data);
-            throw new IOException("Could not create " + type + " with data " + data);
-        }
-        catch (UniformInterfaceException e2) {
-            return c.resource(e2.getResponse().getLocation());
-        }
-    }
-
-    /** Creates a feature. */
-    private WebResource createFeature(Client c, WebResource work, String name) throws IOException {
-        return createEntity(c, work, "feature", "{attributes: {name: \"" + name + "\"}, tags: {}}");
-    }
-
-    /** Creates a resource processor bundle artifact. */
-    private WebResource createResourceProcessor(Client c, WebResource work, String name, String bsn, String v, String url, String mimetype, String processorID) throws IOException {
-        return createEntity(c, work, "artifact", "{attributes: {" +
-            "artifactName: \"" + name + "\", " +
-            "description: \"\", " +
-            "Bundle-SymbolicName: \"" + bsn + "\", " +
-            "Bundle-Version: \"" + v + "\", " +
-            "mimetype: \"" + mimetype + "\", " +
-            BundleHelper.KEY_RESOURCE_PROCESSOR_PID + ": \"" + processorID + "\", " +
-            "DeploymentPackage-Customizer: \"true\", " +
-            "url: \"" + url + "\"" +
-            "}, tags: {}}");
-    }
-
     /** Create a user so we can log in to the server. */
     private void createServerUser() {
         User user = (User) m_user.createRole("d", Role.USER);
@@ -509,95 +439,6 @@ public class RESTClientTest extends Inte
         user.getCredentials().put("password", "f");
     }
 
-    /** Creates a target. */
-    private WebResource createTarget(Client c, WebResource work, String name, String... tags) throws IOException {
-        StringBuffer result = new StringBuffer();
-        for (int i = 0; i < tags.length; i += 2) {
-            if (result.length() > 0) {
-                result.append(", ");
-            }
-            result.append(tags[i] + ": \"" + tags[i + 1] + "\"");
-        }
-        return createEntity(c, work, "target", "{attributes: {id: \"" + name + "\", autoapprove: \"true\"}, tags: {" + result.toString() + "}}");
-    }
-
-    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(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(config);
-            return file;
-        }
-        finally {
-            bw.close();
-        }
-    }
-
-    /** Creates a new workspace. */
-    private WebResource createWorkspace(Client c) {
-        WebResource r = c.resource(HOST.concat("/client/work"));
-        try {
-            r.post(String.class, "");
-            fail("We should have been redirected to a new workspace.");
-            return null; // to keep the compiler happy, it does not understand what fail() does
-        }
-        catch (UniformInterfaceException e) {
-            return c.resource(e.getResponse().getLocation());
-        }
-    }
-
-    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 void ensureCleanStore() throws IOException {
-        File store = new File(STOREPATH);
-        System.out.println("store: " + store.getAbsolutePath());
-        if (store.exists()) {
-            if (!store.isDirectory()) {
-                throw new IllegalStateException("Configured store is not a directory: " + store.getAbsolutePath());
-            }
-            FileUtils.removeDirectoryWithContent(store);
-        }
-        if (!store.mkdirs()) {
-            throw new IllegalStateException("Failed to create store directory: " + store.getAbsolutePath());
-        }
-    }
-
     /** Shows all bundles in the framework. */
     private void showBundles() {
         for (Bundle b : m_context.getBundles()) {