Commits

Sam Adams  committed 69fbb94

Added item slug check

  • Participants
  • Parent commits 61eaeaa

Comments (0)

Files changed (5)

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

  * @author Sam Adams
  */
 public class CollectionMatchers {
-    
+
+    public static Matcher<CollectionView> hasSlug(final String slug) {
+        return new CollectionSlugMatcher(slug);
+    }
+
     public static Matcher<CollectionView> hasTitle(final String title) {
         return new CollectionTitleMatcher(title);
     }
-    
+
     public static Matcher<CollectionView> containsItem(final Collection child) {
         return new CollectionContainsMatcher(child);
     }
 
-    public static Matcher<CollectionView> hasSlug(final String slug) {
-        return new CollectionSlugMatcher(slug);
-    }
-
 
     private static class CollectionTitleMatcher extends TypeSafeMatcher<CollectionView> {
         private final String title;

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

  */
 public class ItemMatchers {
 
+    public static Matcher<ItemView> hasSlug(final String slug) {
+        return new ItemSlugMatcher(slug);
+    }
+
     public static Matcher<ItemView> hasTitle(final String title) {
         return new ItemTitleMatcher(title);
     }
         return new ItemFileLinkMatcher(file);
     }
 
+    private static class ItemSlugMatcher extends TypeSafeMatcher<ItemView> {
+        private final String slug;
+
+        public ItemSlugMatcher(final String slug) {
+            this.slug = slug;
+        }
+
+        @Override
+        protected boolean matchesSafely(final ItemView item) {
+            return item.hasSlug(slug);
+        }
+
+        @Override
+        public void describeTo(final Description description) {
+            description.appendText("slug matches '" + slug + "'");
+        }
+    }
+
     private static class ItemTitleMatcher extends TypeSafeMatcher<ItemView> {
 
         private final String title;

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

         final WebElement element = webDriver.findElement(By.xpath("//a[@href='" + uri + "']"));
         return element != null;
     }
+
+    @Override
+    public boolean hasSlug(final String slug) {
+        return webDriver.getCurrentUrl().contains('/' + context.actual(slug) + '/');
+    }
 }

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

 
     boolean matchesFileLink(String file);
 
+    boolean hasSlug(String slug);
 }

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

 import net.chempound.acceptance.dsl.driver.Resource;
 import net.chempound.acceptance.dsl.driver.WebUIDriver;
 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;
+import static net.chempound.acceptance.dsl.driver.ItemMatchers.*;
 
 /**
  * @author Sam Adams
     @SuppressWarnings("unchecked")
     public void shouldCreateItemOnMetadataDeposit() {
         Item item = apiDriver.newItem()
+            .withSlug("slug")
             .withTitle("title")
             .execute();
 
-        webDriver.check(item, hasTitle("title"));
+        webDriver.check(item, hasSlug("slug"), hasTitle("title"));
     }
 
     @Test