Package org.javalite.activejdbc.test_models

Examples of org.javalite.activejdbc.test_models.Article


    }

    @Test
    public void shouldAddPolymorphicChild() {
        deleteAndPopulateTables("articles", "posts", "comments");
        Article a = Article.findById(1);
        a.add(Comment.create("author", "ipolevoy", "content", "this is just a test comment text"));
        a(Comment.findAll().get(0).get("author")).shouldBeEqual("ipolevoy");
    }
View Full Code Here


    }

    @Test
    public void shouldFindAllPolymorphicChildren() {
        deleteAndPopulateTables("articles", "posts", "comments");
        Article a = Article.findById(1);
        a.add(Comment.create("author", "ipolevoy", "content", "this is just a test comment text"));
        a.add(Comment.create("author", "rkinderman", "content", "this is another test comment text"));
        List<Comment> comments = a.getAll(Comment.class).orderBy("id");

        a(comments.size()).shouldBeEqual(2);
        a(comments.get(0).get("author")).shouldBeEqual("ipolevoy");

        Post p = Post.findById(2);
View Full Code Here

    }

    @Test
    public void shouldFindAllPolymorphicChildrenWithCriteria() {
        deleteAndPopulateTables("articles", "posts", "comments");
        Article a = Article.findById(1);
        a.add(Comment.create("author", "ipolevoy", "content", "this is just a test comment text"));
        a.add(Comment.create("author", "rkinderman", "content", "this is another test comment text"));
        List<Comment> comments = a.get(Comment.class, "author = ?", "ipolevoy");
        a(comments.size()).shouldBeEqual(1);

        a(comments.get(0).getString("content").contains("this is just a test comment text")).shouldBeTrue();
    }
View Full Code Here

    }

    @Test
    public void shouldRemovePolymorphicChildren() {
        deleteAndPopulateTables("articles", "posts", "comments");
        Article a = Article.findById(1);
        a.add(Comment.create("author", "ipolevoy", "content", "this is just a test comment text"));
        a.add(Comment.create("author", "rkinderman", "content", "this is another test comment text"));
        Comment c = (Comment) Comment.findAll().limit(1).orderBy("id").get(0);
        a.remove(c);
        a(Comment.findAll().size()).shouldBeEqual(1);
    }
View Full Code Here


    @Test
    public void shouldInferPolymorphicNames() {
        deleteAndPopulateTables("articles", "posts", "comments");
        Article a = Article.findById(1);
        a.add(Comment.create("author", "ipolevoy", "content", "this is just a test comment text"));
        a.add(Comment.create("author", "rkinderman", "content", "this is another test comment text"));

        a(a.get("comments")).shouldNotBeNull();
        a(Comment.findAll().limit(1).get(0).get("article")).shouldNotBeNull();
    }
View Full Code Here

    }

    @Test
    public void shouldFindPolymorphicParent() {
        deleteAndPopulateTables("articles", "posts", "comments");
        Article article = Article.findById(1);
        article.add(Comment.create("author", "ipolevoy", "content", "this is just a test comment text"));
        article.add(Comment.create("author", "rkinderman", "content", "this is another test comment text"));
        Article article1 = Comment.findAll().get(0).parent(Article.class);
        the(article.getId()).shouldBeEqual(article1.getId());
    }
View Full Code Here


    @Test(expected = IllegalArgumentException.class)
    public void shouldThrowExceptionIfWrongParentTypeRequested() {
        deleteAndPopulateTables("articles", "posts", "comments");
        Article article = Article.findById(1);
        article.add(Comment.create("author", "ipolevoy", "content", "this is just a test comment text"));
        article.add(Comment.create("author", "rkinderman", "content", "this is another test comment text"));

        Comment.findAll().get(0).parent(Post.class);
    }
View Full Code Here

    @Test
    public void shouldFindPolymorphicParentWithInclude(){

        deleteAndPopulateTables("articles", "posts", "comments");
        Article article = Article.findById(1);
        article.add(Comment.create("author", "ipolevoy", "content", "this is just a test comment text"));
        article.add(Comment.create("author", "rkinderman", "content", "this is another test comment text"));


        LazyList<Article> articles = Article.findAll().include(Comment.class).orderBy("id");
        articles.size();
View Full Code Here

        deleteAndPopulateTables("comments", "articles", "posts");

        Post p = Post.findById(1);
        p.add(Comment.create("author", "eleonard", "content", "this is just a test comment text"));

        Article a = Article.findById(2);
        a.add(Comment.create("author", "eleonard", "content", "this is just a test comment text"));

        final LazyList<Comment> comments = Comment.findAll().orderBy("id").include(Article.class, Post.class);

        final List<Map> commentMaps = comments.toMaps();
View Full Code Here

    }

    @Test
    public void shouldGenerateXmlForPolymorphicChildren() throws IOException {
        deleteAndPopulateTables("articles", "comments", "tags");
        Article a = Article.findFirst("title = ?", "ActiveJDBC polymorphic associations");
        a.add(Comment.create("author", "igor", "content", "this is just a test comment text"));
        a.add(Tag.create("content", "orm"));
        LazyList<Article> articles = Article.where("title = ?", "ActiveJDBC polymorphic associations")
                .include(Tag.class, Comment.class);

        String xml = articles.toXml(true, true);
        XPathHelper h = new XPathHelper(xml);
View Full Code Here

TOP

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

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.