Exemplo n.º 1
0
  @Test
  public void testAdd() {
    Article article =
        new Article(
            null,
            "test.home",
            "测试",
            "一个测试",
            "article.state.recommand",
            "推荐",
            "visible.true",
            "可见",
            "0",
            DateUtils.getSystemTime(),
            "admin",
            "管理员");
    assertEquals(1, Article.add(article));

    article = Article.getAll(article, "0", "1", "id", "desc").getList().get(0);
    String id = article.getId();

    assertNotNull(article);
    assertNotNull(id);

    article.setCid("test.home1");
    assertEquals(1, Article.edit(article));
    assertEquals("test.home1", Article.get(id).getCid());

    assertEquals(1, Article.remove(id));
  }
Exemplo n.º 2
0
  @Test
  @SuppressWarnings("unchecked")
  public void shouldGenerateJsonForPolymorphicChildren() {
    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);

    Map[] maps = JsonHelper.toMaps(articles.toJson(true));

    the(maps.length).shouldBeEqual(1);
    Map article = maps[0];
    List<Map> comments = (List<Map>) ((Map) article.get("children")).get("comments");
    List<Map> tags = (List<Map>) ((Map) article.get("children")).get("tags");

    the(comments.size()).shouldBeEqual(1);
    the(comments.get(0).get("content")).shouldBeEqual("this is just a test comment text");
    the(tags.size()).shouldBeEqual(1);
    the(tags.get(0).get("content")).shouldBeEqual("orm");
  }