Package com.avaje.tests.idkeys.db

Examples of com.avaje.tests.idkeys.db.AuditLog


     */
    public void testPropertyChange() throws SQLException
    {
        resetEvent();

        AuditLog al = new AuditLog();

        assertTrue("is EntityBean check", al instanceof EntityBean);

        addListener(al, this);
       
        // test if we get property notification about simple property changes
        al.setDescription("ABC");

        assertNotNull(lastPce);
        assertEquals(1, nuofEvents);
        assertEquals("description", lastPce.getPropertyName());
        assertNull(lastPce.getOldValue());
        assertEquals("ABC", lastPce.getNewValue());

        al.setDescription("DEF");

        assertNotNull(lastPce);
        assertEquals(2, nuofEvents);
        assertEquals("description", lastPce.getPropertyName());
        assertEquals("ABC", lastPce.getOldValue());
        assertEquals("DEF", lastPce.getNewValue());

        resetEvent();

        // test if we get change notification if EBean assigns an id to the bean
        getServer().save(al);

        assertNotNull(lastPce);
        assertEquals("id", lastPce.getPropertyName());
        assertNull(lastPce.getOldValue());
        assertNotNull(lastPce.getNewValue());

        String prevLogDesc = al.getDescription();

        resetEvent();

        // simulate external change and test if we get change notification when we refresh the entity
        Transaction tx = getServer().beginTransaction();
        PreparedStatement pstm = tx.getConnection().prepareStatement("update audit_log set description = ? where id = ?");
        pstm.setString(1, "GHI");
        pstm.setLong(2, al.getId());
        int updated = pstm.executeUpdate();
        pstm.close();

        assertEquals(1, updated);

        tx.commit();

        assertNull(lastPce);
        assertEquals(0, nuofEvents);

        getServer().refresh(al);

        assertEquals("GHI", al.getDescription());

        assertNotNull(lastPce);
        assertEquals(1, nuofEvents);
        assertEquals("description", lastPce.getPropertyName());
        assertEquals(prevLogDesc, lastPce.getOldValue());
        assertNotNull("GHI", lastPce.getNewValue());

        // check if we fire with the real new value which might be a modified version of what we passed to the set method
        resetEvent();
        al.setModifiedDescription("MODIFIED_VALUE");

        assertNotNull(lastPce);
        assertEquals(1, nuofEvents);
        assertEquals("modifiedDescription", lastPce.getPropertyName());
        assertEquals(null, lastPce.getOldValue());
View Full Code Here


     * <li>updating a lazy loaded property fires two events</li>
     * </ul>
     */
    public void testPartialLoad() throws SQLException
    {
        AuditLog log = new AuditLog();
        log.setDescription("log");

        getServer().save(log);

        assertNotNull(log.getId());

        resetEvent();

        List<AuditLog> logs = getServer().find(AuditLog.class)
                .where().eq("id", log.getId())
                .select("id")
                .findList();

        assertNotNull(logs);
        assertEquals(1, logs.size());

        AuditLog logLazy = logs.get(0);

        addListener(logLazy, this);

        // this will lazy load and update the property
        logLazy.setDescription("updated log");

        // which should result in one PCE events
        assertEquals(1, pces.size());

        // test for the acutal update of the value
View Full Code Here

public class TestSqlUpdateInTxn extends BaseTestCase {

  @Test
  public void testBasic() {

    AuditLog otherLog = new AuditLog();
    otherLog.setDescription("foo");
    Ebean.save(otherLog);

    AuditLog log = new AuditLog();
    log.setDescription("foo");
   
    Ebean.save(log);
   
    AuditLog log2 = Ebean.find(AuditLog.class, log.getId());
    Assert.assertEquals("foo", log2.getDescription());
   
    final Long id = log2.getId();
    final String updateDml = "update audit_log set description = :desc where id = :id";
    final String updateModDml = "update audit_log set modified_description = :desc";
   
    SqlUpdate sqlUpdate = Ebean.createSqlUpdate(updateDml);
    sqlUpdate.setParameter("desc", "foo2");
    sqlUpdate.setParameter("id", id);
    sqlUpdate.execute();
   
    SqlUpdate updateMod = Ebean.createSqlUpdateupdateModDml ) ;
    updateMod.setParameter("desc", "mod0");
    updateMod.execute();
   
    AuditLog log3 = Ebean.find(AuditLog.class, log.getId());
    Assert.assertEquals("foo2", log3.getDescription());
    Assert.assertEquals("mod0", log3.getModifiedDescription());

    Ebean.execute(new TxRunnable() { 
      public void run() { 
        SqlUpdate update = Ebean.createSqlUpdateupdateDml ) ;
        update.setParameter("desc", "foo3");
        update.setParameter("id", id);
        update.execute();

        SqlUpdate updateMod = Ebean.createSqlUpdateupdateModDml ) ;
        updateMod.setParameter("desc", "mod1");
        updateMod.execute();
     
    });

    AuditLog log4 = Ebean.find(AuditLog.class, log.getId());
    Assert.assertEquals("foo3", log4.getDescription());
    Assert.assertEquals("mod1", log4.getModifiedDescription());

   
    Ebean.beginTransaction();
   
    SqlUpdate update = Ebean.createSqlUpdate( updateDml) ;
    update.setParameter("desc", "foo4");
    update.setParameter("id", id);
    update.execute();

    updateMod = Ebean.createSqlUpdateupdateModDml ) ;
    updateMod.setParameter("desc", "mod2");
    updateMod.execute();

    Ebean.commitTransaction();

    AuditLog log5 = Ebean.find(AuditLog.class, log.getId());
    Assert.assertEquals("foo4", log5.getDescription());
    Assert.assertEquals("mod2", log5.getModifiedDescription());

  }
View Full Code Here

TOP

Related Classes of com.avaje.tests.idkeys.db.AuditLog

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.