Package org.javalite.activejdbc.test_models

Examples of org.javalite.activejdbc.test_models.Item


public class OptimisticLockingOverrideVersionColumnTest extends ActiveJDBCTest {

    @Test
    public void shouldSetVersionToOneWhenCreatingNewRecord(){
        deleteAndPopulateTable("items");
        Item m = new Item();
        m.set("item_number", 1);
        m.set("item_description", "descr 1");
        m.saveIt();
        Item m1 = Item.findById(1);
        a(m1.get("lock_version")).shouldBeEqual(1);
    }
View Full Code Here



    @Test
    public void shouldAdvanceVersionWhenRecordIsUpdated(){
        deleteAndPopulateTable("items");
        Item m = new Item();
        m.set("item_number", 1);
        m.set("item_description", "descr 1");
        m.saveIt();

        m = Item.findById(1);
        m.set("item_description", "descr 2").saveIt();
        a(m.get("lock_version")).shouldBeEqual(2);// this will ensure that the value is updated in the model itself
        m = Item.findById(1);
        a(m.get("lock_version")).shouldBeEqual(2);

        m = Item.findById(1);
        m.set("item_description", "descr 3").saveIt();
        m = Item.findById(1);
        a(m.get("lock_version")).shouldBeEqual(3);

    }
View Full Code Here

    }

    @Test(expected = StaleModelException.class)
    public void shouldThrowExceptionWhenVersionCollisionHappens(){
        deleteAndPopulateTable("items");
        Item m = new Item();
        m.set("item_number", 1);
        m.set("item_description", "descr 2").saveIt();
        m.saveIt();

        Item m1 = Item.findById(1);
        Item m2 = Item.findById(1);

        m1.set("item_description", "descr 5").saveIt();
        m2.set("item_description", "descr 6").saveIt(); //<<<<================ this will cause the StaleModelException
    }
View Full Code Here

TOP

Related Classes of org.javalite.activejdbc.test_models.Item

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.