continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ri...@apache.org
Subject svn commit: r602656 - in /maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store: jpa/JpaProjectStoreTest.java matcher/ matcher/JpaEntity.java
Date Sun, 09 Dec 2007 09:37:20 GMT
Author: rinku
Date: Sun Dec  9 01:37:19 2007
New Revision: 602656

URL: http://svn.apache.org/viewvc?rev=602656&view=rev
Log:
o  added an experimental Hamcrest mapper for some common assertions against the Store. 

Added:
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/matcher/
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/matcher/JpaEntity.java
  (with props)
Modified:
    maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/jpa/JpaProjectStoreTest.java

Modified: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/jpa/JpaProjectStoreTest.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/jpa/JpaProjectStoreTest.java?rev=602656&r1=602655&r2=602656&view=diff
==============================================================================
--- maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/jpa/JpaProjectStoreTest.java
(original)
+++ maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/jpa/JpaProjectStoreTest.java
Sun Dec  9 01:37:19 2007
@@ -3,6 +3,8 @@
  */
 package org.apache.maven.continuum.store.jpa;
 
+import static org.apache.maven.continuum.store.matcher.JpaEntity.isDeleted;
+
 import java.io.File;
 import java.util.List;
 import java.util.Properties;
@@ -13,6 +15,7 @@
 import org.apache.maven.continuum.store.api.ProjectQuery;
 import org.apache.maven.continuum.store.api.Store;
 import org.apache.maven.continuum.store.api.StoreException;
+import org.apache.maven.continuum.store.matcher.JpaEntity;
 import org.apache.openjpa.persistence.OpenJPAQuery;
 import org.junit.After;
 import org.junit.Assert;
@@ -98,9 +101,10 @@
         Assert.assertTrue( project.getId() > 0L );
         getProjectStore().delete( project );
         // assertion follows in a separate transaction
+        isDeleted( getProjectStore(), Project.class, project );
     }
 
-    @AfterTransaction
+    // @AfterTransaction
     public void assertProjectDeleted() throws StoreException
     {
         try

Added: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/matcher/JpaEntity.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/matcher/JpaEntity.java?rev=602656&view=auto
==============================================================================
--- maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/matcher/JpaEntity.java
(added)
+++ maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/matcher/JpaEntity.java
Sun Dec  9 01:37:19 2007
@@ -0,0 +1,88 @@
+/**
+ * 
+ */
+package org.apache.maven.continuum.store.matcher;
+
+import org.apache.maven.continuum.model.CommonUpdatableEntity;
+import org.apache.maven.continuum.store.api.EntityNotFoundException;
+import org.apache.maven.continuum.store.api.Query;
+import org.apache.maven.continuum.store.api.Store;
+import org.apache.maven.continuum.store.api.StoreException;
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+import org.hamcrest.Factory;
+import org.hamcrest.Matcher;
+import org.junit.Assert;
+import org.springframework.test.annotation.NotTransactional;
+
+/**
+ * {@link Matcher} extension that provides a semantic convenience to assert if a persistable
JPA entity was removed from
+ * the underlying store.
+ * 
+ * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
+ * @version $Id$
+ * @since 1.2
+ */
+public class JpaEntity<T extends CommonUpdatableEntity, Q extends Query<T>> extends
BaseMatcher<T>
+{
+
+    /**
+     * Entity to check
+     */
+    private T entity;
+
+    private Class<T> klass;
+
+    private Store<T, Q> store;
+
+    public JpaEntity( Store<T, Q> s, Class<T> c, T t )
+    {
+        this.store = s;
+        this.klass = c;
+        this.entity = t;
+    }
+
+    /**
+     * @{inheritDoc}
+     * 
+     * @see org.hamcrest.Matcher#matches(java.lang.Object)
+     */
+    @NotTransactional
+    public boolean matches( Object o )
+    {
+        Assert.assertNotNull( store );
+        try
+        {
+            T obj = store.lookup( klass, entity.getId() );
+            return ( null == obj );
+        }
+        catch ( EntityNotFoundException e )
+        {
+            return true;
+        }
+        catch ( StoreException e )
+        {
+            // TODO: How do we handle this?
+            return false;
+        }
+    }
+
+    /**
+     * @{inheritDoc}
+     * 
+     * @see org.hamcrest.SelfDescribing#describeTo(org.hamcrest.Description)
+     */
+    public void describeTo( Description description )
+    {
+        description.appendText( "Entity is deleted" );
+    }
+
+    @Factory
+    public static <T extends CommonUpdatableEntity, Q extends Query<T>> Matcher<T>
isDeleted( Store<T, Q> s,
+                                                                                        
     Class<T> c, T t )
+    {
+        JpaEntity<T, Q> matcher = new JpaEntity<T, Q>( s, c, t );
+        return matcher;
+    }
+
+}

Propchange: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/matcher/JpaEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/continuum/branches/continuum-jpa/continuum-model-jpa/src/test/java/org/apache/maven/continuum/store/matcher/JpaEntity.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



Mime
View raw message