(no commit message)
[utils] / test / enterprise / src / test / java / org / wamblee / test / persistence / MyEntityExampleTestBase.java
index 737455ce77ae6f0c75fa149172452342a739f254..7f19633386378dae98c107d1bbdc687044c73bbe 100644 (file)
@@ -12,7 +12,7 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- */ 
+ */
 package org.wamblee.test.persistence;
 
 import static junit.framework.Assert.*;
@@ -100,4 +100,54 @@ public class MyEntityExampleTestBase {
 
     }
 
+    @Test
+    public void testEntityPersistenceWithBasicApi() throws Exception {
+
+        // Use the JPA builder to create a transaction scoped entity manager for
+        // as and execute the
+        // unit of work.
+        EntityManager em = builder.begin();
+
+        MyEntity entity = new MyEntity("a", "b");
+        em.persist(entity);
+
+        builder.commit(em);
+
+        // Verify one row is written (using Db unit)
+        ITable table = dbtester.getDataSet().getTable("XYZ_MYENTITY");
+        assertEquals(1, table.getRowCount());
+
+        assertEquals("a", table.getValue(0, "SLEUTELTJE"));
+        assertEquals("b", table.getValue(0, "VALUE"));
+
+        // For this simple test, it can also be done through DatabaseUtils
+        assertEquals(1, dbutils.getTableSize("XYZ_MYENTITY"));
+
+    }
+    
+    @Test
+    public void testEntityPersistenceWithContextualEntityManager() throws Exception {
+
+        // Use the JPA builder to create a transaction scoped entity manager for
+        // as and execute the
+        // unit of work.
+        builder.begin();
+
+        EntityManager em = builder.getContextualEntityManager(); 
+        MyEntity entity = new MyEntity("a", "b");
+        em.persist(entity);
+
+        builder.commit(em);
+
+        // Verify one row is written (using Db unit)
+        ITable table = dbtester.getDataSet().getTable("XYZ_MYENTITY");
+        assertEquals(1, table.getRowCount());
+
+        assertEquals("a", table.getValue(0, "SLEUTELTJE"));
+        assertEquals("b", table.getValue(0, "VALUE"));
+
+        // For this simple test, it can also be done through DatabaseUtils
+        assertEquals(1, dbutils.getTableSize("XYZ_MYENTITY"));
+
+    }
 }