Package org.javalite.activejdbc.test_models

Examples of org.javalite.activejdbc.test_models.Person


        FutureBirthValidator validator = new FutureBirthValidator();

        Person.addValidator(validator);

        Person p = new Person();

        GregorianCalendar future = new GregorianCalendar();
        future.set(Calendar.YEAR, 3000);//will people still be using Java then... or computers? :)

        p.set("dob", new Date(future.getTimeInMillis()));
        p.validate();
        a(p.errors().size()).shouldBeEqual(3);

        a(p.errors().get("invalid.dob")).shouldBeEqual("date of birth cannot be in future");

        //this is so that other tests succeed
        Person.removeValidator(validator);
    }
View Full Code Here


        Runnable r = new Runnable() {
            public void run() {

                Base.open(driver(), url(), user(), password());
                Person p = new Person();
                p.set("name", "Igor");
                Base.close();
                queue.add(1);
            }
        };
View Full Code Here

    }
   
    @Test
    public void shouldCreateModel() {

        Person p = Person.create("name", "Sam", "last_name", "Margulis", "dob", "2001-01-07");
        p.saveIt();
        a(p.get("name")).shouldBeEqual("Sam");
    }
View Full Code Here

    }

    @Test
    public void shouldCreateAndSaveModel(){

        Person p = Person.createIt("name", "Sam", "last_name", "Margulis", "dob", "2001-01-07");
        a(p.getId()).shouldNotBeNull();
    }
View Full Code Here

    @Test
    public void shouldNotFail(){
        deleteAndPopulateTable("people");

        Person p = new Person();
        a(p).shouldBe("new");

        p = Person.findFirst("last_name = ?", "Pesci");
        a(p).shouldNotBe("new");
    }
View Full Code Here

public class Defect141Test extends ActiveJDBCTest {

    @Test
    public void shouldRefreshCreatedAndUpdatedAttributes() throws InterruptedException {

        Person p = new Person();
        p.set("name", "John", "last_name", "Doe");
        p.saveIt();

        Timestamp createdOrig = p.getTimestamp("created_at");
        Timestamp updatedOrig = p.getTimestamp("updated_at");

        Thread.sleep(500);

        Base.exec("update people set updated_at = ? where id = ?", new Timestamp(System.currentTimeMillis()), p.getId());
        Base.exec("update people set created_at = ? where id = ?", new Timestamp(System.currentTimeMillis()), p.getId());

        p.refresh();

        a(createdOrig).shouldNotBeEqual(p.getTimestamp("created_at"));
        a(updatedOrig).shouldNotBeEqual(p.getTimestamp("updated_at"));
    }
View Full Code Here

    }

    @Test
      public void shouldResetUpdatedAtByInstanceMethods(){

        Person p = new Person();
        p.set("name", "Lisa");
        p.set("last_name", "Simpson");
        //DOB setter missing
        p.saveIt();

        p  = Person.findFirst("last_name = ?", "Simpson");
        Timestamp createdAt = p.getTimestamp("created_at");
        a(createdAt).shouldNotBeNull();

        try{Thread.sleep(1000);}catch(Exception e){}//MySQL seems to round off some milliseconds, this sucks.

        p.set("name", "Bart");
        p.saveIt();

        p = Person.findFirst("last_name = ?", "Simpson");
        Timestamp updatedAt = p.getTimestamp("updated_at");

        a(updatedAt).shouldNotBeNull();
        a(createdAt).shouldBeEqual(p.get("created_at"));
        a(createdAt.before(updatedAt)).shouldBeTrue();
    }
View Full Code Here

public class ToFromXmlSpec extends ActiveJDBCTest {

    @Test
    public void shouldGenerateSimpleXml(){
        deleteAndPopulateTable("people");
        Person p  = Person.findById(1);
        String xml = p.toXml(true, true);
        a(XPathHelper.selectText("//name", xml)).shouldEqual("John");
        a(XPathHelper.selectText("//last_name", xml)).shouldEqual("Smith");
    }
View Full Code Here

    @Test
    public void shouldParseAttributesFromXml() throws ParseException {
        deleteAndPopulateTables("people");

        Person p = new Person();
        String xml = readResource("/person.xml");
        p.fromXml(xml);
        p.saveIt();
        p.refresh();

        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");

        a(p.get("name")).shouldBeEqual("John");
        a(p.get("last_name")).shouldBeEqual("Doe");
        a(p.get("graduation_date")).shouldBeEqual(f.parse("1979-06-01"));
        a(p.get("dob")).shouldBeEqual(f.parse("1962-06-13"));
    }
View Full Code Here


    @Test
    public void shouldInjectCustomContentIntoXML(){
        deleteAndPopulateTable("people");
        Person p  = Person.findById(1);
        String xml = p.toXml(true, true);
        a(XPathHelper.selectText("/person/test", xml)).shouldEqual("test content");
    }
View Full Code Here

TOP

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

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.