Commits

Anonymous committed 4bcc73b

Add more methods to sword client driver

Comments (0)

Files changed (1)

acceptance-test-driver/src/main/java/net/chempound/acceptance/dsl/driver/sword/SwordClientDriver.java

 import net.chempound.acceptance.dsl.TestContext;
 import net.chempound.acceptance.dsl.driver.DepositInstruction;
 import net.chempound.acceptance.dsl.driver.DepositSpecification;
-import net.chempound.acceptance.dsl.driver.api.*;
 import org.swordapp.client.*;
-import org.swordapp.client.DepositReceipt;
 
 import java.net.URI;
 
     }
 
     public SwordDepositReceipt depositItem(final DepositSpecification... specifications) throws Exception {
-        final DepositInstruction instruction = new DepositInstruction();
-        for (final DepositSpecification specification : specifications) {
-            specification.apply(instruction);
-        }
+        final DepositInstruction instruction = createDepositInstruction(specifications);
         final URI collection = instruction.parent != null ? instruction.parent : context.getContentRoot();
         final DepositReceipt depositReceipt = swordClient.deposit(collection.toString(), createDeposit(instruction));
         return new SwordDepositReceipt(depositReceipt);
     }
 
-    private Deposit createDeposit(final DepositInstruction instruction) {
-        final Deposit deposit = new Deposit();
-        deposit.setSlug(instruction.slug);
-
-        final EntryPart entryPart = new EntryPart();
-        entryPart.getEntry().setTitle(context.actual(instruction.title));
-        deposit.setEntryPart(entryPart);
-
-        return deposit;
-    }
-
     public void completeDeposit(final String editUrl) throws Exception {
         swordClient.complete(editUrl, null);
     }
         swordClient.delete(deleteUrl, null);
     }
 
+    public SwordResponse replaceItem(final String editUri, final DepositSpecification... specifications) throws Exception {
+        final DepositInstruction instruction = createDepositInstruction(specifications);
+        return swordClient.replace(editUri, createDeposit(instruction), null);
+    }
+
+    public SwordResponse replaceMedia(final String editMediaUri, final DepositSpecification... specifications) throws Exception {
+        final DepositInstruction instruction = createDepositInstruction(specifications);
+        return swordClient.replace(editMediaUri, createDeposit(instruction), null);
+    }
+
+    public SwordDepositReceipt addToItem(final String editUri, final DepositSpecification... specifications) throws Exception {
+        final DepositInstruction instruction = createDepositInstruction(specifications);
+        final DepositReceipt depositReceipt = swordClient.addToContainer(editUri, createDeposit(instruction), null);
+        return new SwordDepositReceipt(depositReceipt);
+    }
+
+    public SwordResponse addToMedia(final String editMediaUri, final DepositSpecification... specifications) throws Exception {
+        final DepositInstruction instruction = createDepositInstruction(specifications);
+        return swordClient.addToMediaResource(editMediaUri, createDeposit(instruction), null);
+    }
+
+    public void getContentAsZipFile(final String contentUri) throws Exception {
+        final Content content = swordClient.getContent(contentUri, null);
+    }
+
+    public void getContentAsFeed(final String contentUri) throws Exception {
+        final Content content = swordClient.getContent(contentUri, "application/atom+xml;type=feed");
+    }
+
+    private DepositInstruction createDepositInstruction(final DepositSpecification[] specifications) {
+        final DepositInstruction instruction = new DepositInstruction();
+        for (final DepositSpecification specification : specifications) {
+            specification.apply(instruction);
+        }
+        return instruction;
+    }
+
+    private Deposit createDeposit(final DepositInstruction instruction) {
+        final Deposit deposit = new Deposit();
+        deposit.setSlug(instruction.slug);
+
+        final EntryPart entryPart = new EntryPart();
+        entryPart.getEntry().setTitle(context.actual(instruction.title));
+        deposit.setEntryPart(entryPart);
+
+        return deposit;
+    }
 }