@Test
  @RunAsClient
  public void testGetAssetsAsAtom(@ArquillianResource URL baseURL) throws Exception {
    AbderaClient client = new AbderaClient(abdera);
    client.addCredentials(
        baseURL.toExternalForm(),
        null,
        null,
        new org.apache.commons.httpclient.UsernamePasswordCredentials("admin", "admin"));

    RequestOptions options = client.getDefaultRequestOptions();
    options.setAccept(MediaType.APPLICATION_ATOM_XML);

    ClientResponse resp =
        client.get(new URL(baseURL, "rest/packages/restPackage1/assets").toExternalForm(), options);

    if (resp.getType() != ResponseType.SUCCESS) {
      fail("Couldn't retrieve assets-> " + resp.getStatus() + ": " + resp.getStatusText());
    }

    // Get the entry element
    Document<Feed> document = resp.getDocument();

    assertEquals(totalAssets, document.getRoot().getEntries().size());
  }
  public String submitSIP(String endpoint, String user, String pass, Package pkg)
      throws RPCException {
    AbderaClient client = null;

    try {

      client = getClient(endpoint, user, pass);

      RequestOptions opts = new RequestOptions();
      opts.setContentType("application/xml");
      opts.setHeader("X-Packaging", "http://dataconservancy.org/schemas/dcp/1.0");
      opts.setHeader("X-Verbose", "true");

      Dcp dcp;

      try {
        dcp = PackageUtil.constructDcp(pkg);
      } catch (IllegalArgumentException e) {
        // e.printStackTrace();
        throw new RPCException("Malformed SIP: " + e.getMessage());
      }

      ByteArray buf = new ByteArray(8 * 1024);
      dcpbuilder.buildSip(dcp, buf.asOutputStream());
      ClientResponse resp = client.post(endpoint, buf.asInputStream(), opts);

      int status = resp.getStatus();

      StringWriter result = new StringWriter();
      resp.getDocument().writeTo(result);

      if (status == 200 || status == 201 || status == 202) {
        return result.toString();
      } else {
        throw new RPCException("Package deposit failed: " + result);
      }
    } catch (IOException e) {
      throw new RPCException(e.getMessage());
    } catch (URISyntaxException e) {
      throw new RPCException(e.getMessage());
    } finally {
      if (client != null) {
        client.teardown();
      }
    }
  }
  @Test
  @RunAsClient
  public void testGetDRLAndDSLAssetsAsAtom(@ArquillianResource URL baseURL) throws Exception {
    AbderaClient client = new AbderaClient(abdera);
    client.addCredentials(
        baseURL.toExternalForm(),
        null,
        null,
        new org.apache.commons.httpclient.UsernamePasswordCredentials("admin", "admin"));

    RequestOptions options = client.getDefaultRequestOptions();
    options.setAccept(MediaType.APPLICATION_ATOM_XML);

    ClientResponse resp =
        client.get(
            new URL(baseURL, "rest/packages/restPackage1/assets?format=drl&format=dsl")
                .toExternalForm(),
            options);

    if (resp.getType() != ResponseType.SUCCESS) {
      fail(
          "Couldn't retrieve DRL and DSL assets-> "
              + resp.getStatus()
              + ": "
              + resp.getStatusText());
    }

    // Get the entry element
    Document<Feed> document = resp.getDocument();

    // Check number of results
    assertEquals(3, document.getRoot().getEntries().size());

    // Check assets names
    List<String> assetNames = new ArrayList<String>();
    for (Entry entry : document.getRoot().getEntries()) {
      assetNames.add(entry.getTitle());
    }

    assertTrue(assetNames.contains("rule1"));
    assertTrue(assetNames.contains("rule4"));
    assertTrue(assetNames.contains("myDSL"));
  }
  @Test
  @RunAsClient
  public void testCreateAssetFromAtom(@ArquillianResource URL baseURL) throws Exception {

    // Check there is no model1-New asset
    AbderaClient client = new AbderaClient(abdera);
    client.addCredentials(
        baseURL.toExternalForm(),
        null,
        null,
        new org.apache.commons.httpclient.UsernamePasswordCredentials("admin", "admin"));
    RequestOptions options = client.getDefaultRequestOptions();
    options.setAccept(MediaType.APPLICATION_ATOM_XML);

    ClientResponse resp =
        client.get(
            new URL(baseURL, "rest/packages/restPackage1/assets/model1-New").toExternalForm());

    // If the asset doesn't exist, an HTTP 500 Error is expected. :S
    if (resp.getType() != ResponseType.SERVER_ERROR) {
      fail(
          "I was expecting an HTTP 500 Error because 'model1-New' shouldn't exist. "
              + "Instead of that I got-> "
              + resp.getStatus()
              + ": "
              + resp.getStatusText());
    }

    // --------------------------------------------------------------

    // Get asset 'model1' from Guvnor
    client = new AbderaClient(abdera);
    client.addCredentials(
        baseURL.toExternalForm(),
        null,
        null,
        new org.apache.commons.httpclient.UsernamePasswordCredentials("admin", "admin"));

    options = client.getDefaultRequestOptions();
    options.setAccept(MediaType.APPLICATION_ATOM_XML);

    resp =
        client.get(new URL(baseURL, "rest/packages/restPackage1/assets/model1").toExternalForm());

    if (resp.getType() != ResponseType.SUCCESS) {
      fail("Couldn't retrieve 'model1' asset-> " + resp.getStatus() + ": " + resp.getStatusText());
    }

    // Get the entry element
    Document<Entry> doc = resp.getDocument();
    Entry entry = doc.getRoot();

    // --------------------------------------------------------------

    // Change the title of the asset
    entry.setTitle(entry.getTitle() + "-New");

    // Save it as a new Asset
    client = new AbderaClient(abdera);
    client.addCredentials(
        baseURL.toExternalForm(),
        null,
        null,
        new org.apache.commons.httpclient.UsernamePasswordCredentials("admin", "admin"));

    options = client.getDefaultRequestOptions();
    options.setContentType(MediaType.APPLICATION_ATOM_XML);

    resp =
        client.post(
            new URL(baseURL, "rest/packages/restPackage1/assets").toExternalForm(), entry, options);

    if (resp.getType() != ResponseType.SUCCESS) {
      fail("Couldn't store 'model1-New' asset-> " + resp.getStatus() + ": " + resp.getStatusText());
    }

    // --------------------------------------------------------------

    // Check that the new asset is in the repository
    client = new AbderaClient(abdera);
    client.addCredentials(
        baseURL.toExternalForm(),
        null,
        null,
        new org.apache.commons.httpclient.UsernamePasswordCredentials("admin", "admin"));
    options = client.getDefaultRequestOptions();
    options.setAccept(MediaType.APPLICATION_ATOM_XML);

    resp =
        client.get(
            new URL(baseURL, "rest/packages/restPackage1/assets/model1-New").toExternalForm());

    if (resp.getType() != ResponseType.SUCCESS) {
      fail(
          "Couldn't retrieve 'model1-New' asset-> "
              + resp.getStatus()
              + ": "
              + resp.getStatusText());
    }

    // Get the entry element
    doc = resp.getDocument();
    entry = doc.getRoot();

    // Compare the title :P
    assertEquals(entry.getTitle(), "model1-New");
  }