Package org.javalite.activejdbc.test_models

Examples of org.javalite.activejdbc.test_models.Watermelon


public class OptimisticLockingTest extends ActiveJDBCTest {

    @Test
    public void shouldSetVersionToOneWhenCreatingNewRecord(){
        deleteAndPopulateTable("watermelons");
        Watermelon m = new Watermelon();
        m.set("melon_type", "dark_green");
        m.saveIt();
        Watermelon m1 = Watermelon.findById(1);
        a(m1.get("record_version")).shouldBeEqual(1);
    }
View Full Code Here


    @Test
    public void shouldAdvanceVersionWhenRecordIsUpdated(){

        deleteAndPopulateTable("watermelons");
        Watermelon m = new Watermelon();
        m.set("melon_type", "dark_green");
        m.saveIt();

        m = Watermelon.findById(1);
        m.set("melon_type", "red").saveIt();
        a(m.get("record_version")).shouldBeEqual(2);// this will ensure that the value is updated in the model itself
        m = Watermelon.findById(1);
        a(m.get("record_version")).shouldBeEqual(2);

        m = Watermelon.findById(1);
        m.set("melon_type", "green").saveIt();
        m = Watermelon.findById(1);
        a(m.get("record_version")).shouldBeEqual(3);

        m = Watermelon.findById(1);
        m.set("melon_type", "yellow").saveIt();
        m = Watermelon.findById(1);
        a(m.get("record_version")).shouldBeEqual(4);
    }
View Full Code Here

    }

    @Test(expected = StaleModelException.class)
    public void shouldThrowExceptionWhenVersionCollisionHappens(){
        deleteAndPopulateTable("watermelons");
        Watermelon m = new Watermelon();
        m.set("melon_type", "dark_green");
        m.saveIt();

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

        m1.set("melon_type", "red");
        m1.saveIt();

        m2.set("melon_type", "yellow");
        m2.saveIt()//<<<<================ this will cause the StaleModelException
    }
View Full Code Here

    @Test
    public void should(){
        deleteAndPopulateTable("watermelons");

        Watermelon m = new Watermelon();
        m.set("melon_type", "dark_green");
        m.saveIt();

        m.set("melon_type", "light_green");
        m.saveIt();

        m.set("melon_type", "super_green");
        m.saveIt();

        m.set("melon_type", "dark_red");
        m.saveIt();
    }
View Full Code Here

TOP

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

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.