Commits

Sam Adams  committed 035a3da

Developing deposit ATs

  • Participants
  • Parent commits f4b001c

Comments (0)

Files changed (7)

File acceptance-test-driver/src/main/java/net/chempound/acceptance/dsl/AbstractAcceptanceTest.java

     private static File workspace;
     private static int port;
 
+    protected final TestContext testContext = new TestContext();
     protected final DriverFactory driverFactory;
 
     protected AbstractAcceptanceTest() {
-        this(new SeleniumDriverFactory());
-    }
-
-    public AbstractAcceptanceTest(final DriverFactory driverFactory) {
-        this.driverFactory = driverFactory;
+        this.driverFactory = new SeleniumDriverFactory(testContext);
     }
 
     @After

File acceptance-test-driver/src/main/java/net/chempound/acceptance/dsl/SeleniumDriverFactory.java

  */
 public class SeleniumDriverFactory implements DriverFactory {
 
-    private final TestContext context = new TestContext();
+    private final TestContext context;
     private final WebDriver webDriver;
 
-    public SeleniumDriverFactory() {
+    public SeleniumDriverFactory(final TestContext testContext) {
+        this.context = testContext;
         this.webDriver = createWebDriver();
     }
 

File acceptance-test-driver/src/main/java/net/chempound/acceptance/dsl/driver/DepositItem.java

     URI parent;
     String title;
     String slug;
+    boolean multipart;
+    Resource file;
 
     DepositItem(final APIDriver driver) {
         this.driver = driver;
         return this;
     }
 
+    public DepositItem multipart(final boolean multipart) {
+        this.multipart = multipart;
+        return this;
+    }
+
+    public DepositItem withFile(final Resource file) {
+        this.file = file;
+        return this;
+    }
+
     public Item execute() {
         return driver.depositItem(this);
     }
-
 }

File acceptance-test-driver/src/main/java/net/chempound/acceptance/dsl/driver/ItemMatchers.java

         };
     }
 
+    public static Matcher<ItemPage> hasFileLink(final String file) {
+        return new TypeSafeMatcher<ItemPage>() {
+
+            @Override
+            protected boolean matchesSafely(final ItemPage item) {
+                return item.matchesFileLink(file);
+            }
+
+            @Override
+            public void describeTo(final Description description) {
+                description.appendText("contains file '" + file + "'");
+            }
+        };
+    }
+
 }

File acceptance-test-driver/src/main/java/net/chempound/acceptance/dsl/driver/ItemPage.java

 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebElement;
 
+import java.net.URI;
+
 /**
  * @author Sam Adams
  */
         return context.actual(title).equals(element.getText());
     }
 
+    public boolean matchesFileLink(final String file) {
+        final URI uri = URI.create(webDriver.getCurrentUrl()).resolve(file);
+        final WebElement element = webDriver.findElement(By.xpath("//a[@href='" + uri + "']"));
+        return element != null;
+    }
 }

File acceptance-test-driver/src/main/java/net/chempound/acceptance/dsl/driver/Resource.java

+package net.chempound.acceptance.dsl.driver;
+
+/**
+ * @author Sam Adams
+ */
+public class Resource {
+    
+    private final String path;
+    private final String mimeType;
+    private final byte[] content;
+
+    public Resource(final String path, final String mimeType, final byte[] content) {
+        this.path = path;
+        this.mimeType = mimeType;
+        this.content = content;
+    }
+
+    public String getPath() {
+        return path;
+    }
+
+    public String getMimeType() {
+        return mimeType;
+    }
+
+    public byte[] getContent() {
+        return content;
+    }
+
+}

File acceptance-tests/src/test/java/net/chempound/acceptance/DepositAcceptanceTest.java

 import net.chempound.acceptance.dsl.AbstractAcceptanceTest;
 import net.chempound.acceptance.dsl.driver.APIDriver;
 import net.chempound.acceptance.dsl.driver.Item;
+import net.chempound.acceptance.dsl.driver.Resource;
 import net.chempound.acceptance.dsl.driver.WebUIDriver;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 
+import java.util.Random;
+
+import static net.chempound.acceptance.dsl.driver.ItemMatchers.hasFileLink;
 import static net.chempound.acceptance.dsl.driver.ItemMatchers.hasTitle;
 
 /**
  * @author Sam Adams
  */
+@Ignore
 public class DepositAcceptanceTest extends AbstractAcceptanceTest {
 
     private WebUIDriver webDriver;
     }
 
     @Test
+    @SuppressWarnings("unchecked")
     public void shouldCreateItemOnMetadataDeposit() {
         Item item = apiDriver.newItem()
             .withTitle("title")
         webDriver.check(item, hasTitle("title"));
     }
 
+    @Test
+    @SuppressWarnings("unchecked")
+    public void shouldCreateItemOnBinaryDeposit() {
+        Resource file = newResource();
+        
+        Item item = apiDriver.newItem()
+            .withFile(file)
+            .execute();
+
+        webDriver.check(item, hasFileLink("file"));
+    }
+
+    @Test
+    @SuppressWarnings("unchecked")
+    public void shouldCreateItemOnMultipartDeposit() {
+        Resource file = newResource();
+
+        Item item = apiDriver.newItem()
+                     .withTitle("title")
+                     .withFile(file)
+                     .multipart(true)
+                     .execute();
+
+        webDriver.check(item, hasTitle("title"), hasFileLink(file.getPath()));
+    }
+
+    private static Resource newResource() {
+        return new Resource("path", "mime/Type", generateContent());
+    }
+
+    private static byte[] generateContent() {
+        byte[] bytes = new byte[1024];
+        new Random().nextBytes(bytes);
+        return bytes;
+    }
+
 }