Пример #1
0
 // -------------------------------------+
 @Test
 public void findRepostByTweets_Entity_単数_00() {
   Tweet twt1 = Tweet.findBySerialCode("twt-goro2").first();
   List<RepostBase> lst = RepostBase.findRepostByTweets(twt1).fetch();
   assertThat(lst.size(), is(4));
   // DBからの取得リストの並び保証なし
 }
Пример #2
0
 // -------------------------------------+
 @Test
 public void findRepostByUsers_Entity_単数_00() {
   User usr1 = User.findBySerialCode("usr-goro").first();
   List<RepostBase> lst = RepostBase.findRepostByUsers(usr1).fetch();
   assertThat(lst.size(), is(4));
   // DBからの取得リストの並び保証なし
 }
Пример #3
0
  @Test
  public void postComments() {
    // Create a new user and save it
    User bob = new User("*****@*****.**", "secret", "Bob").save();

    // Create a new post
    Post bobPost = new Post(bob, "My first post", "Hello world").save();

    // Post a first comment
    new Comment(bobPost, "Jeff", "Nice Post").save();
    new Comment(bobPost, "Tom", "I knew that !").save();

    // Retrieve all comments
    List<Comment> bobPostComments = Comment.find("byPost", bobPost).fetch();

    // Tests
    assertEquals(2, bobPostComments.size());

    Comment firstComment = bobPostComments.get(0);
    assertNotNull(firstComment);
    assertEquals("Jeff", firstComment.author);
    assertEquals("Nice Post", firstComment.content);
    assertNotNull(firstComment.postedAt);

    Comment secondComment = bobPostComments.get(1);
    assertNotNull(secondComment);
    assertEquals("Tom", secondComment.author);
    assertEquals("I knew that !", secondComment.content);
    assertNotNull(secondComment.postedAt);
  }
Пример #4
0
 // -------------------------------------+
 @Test
 public void findRepostByTags_Entity_単数_00() {
   Tag tag1 = Tag.findBySerialCode("tag-goro-red").first();
   List<RepostBase> lst = RepostBase.findRepostByTags(tag1).fetch();
   assertThat(lst.size(), is(3));
   // DBからの取得リストの並び保証なし
 }
Пример #5
0
 @Test
 public void findRepostByTags_String_単数_投稿者_00() {
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst = RepostBase.findRepostByTags("tag-goro-red").contributor(acnt).fetch();
   assertThat(lst.size(), is(3));
   // DBからの取得リストの並び保証なし
 }
Пример #6
0
 // -------------------------------------+
 @Test
 public void findRepostByAccounts_Entity_単数_00() {
   Account acnt1 = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst = RepostBase.findRepostByAccounts(acnt1).fetch();
   assertThat(lst.size(), is(17));
   // DBからの取得リストの並び保証なし
 }
Пример #7
0
 // -------------------------------------+
 @Test
 public void findRepostByCategories_Entity_単数_00() {
   Category cat1 = Category.findBySerialCode("cat-biz").first();
   List<RepostBase> lst = RepostBase.findRepostByCategories(cat1).fetch();
   assertThat(lst.size(), is(2));
   // DBからの取得リストの並び保証なし
 }
Пример #8
0
 // -------------------------------------+
 @Test
 public void findRepostByTweets_Entity_単数_投稿者_00() {
   Tweet twt1 = Tweet.findBySerialCode("twt-goro2").first();
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst = RepostBase.findRepostByTweets(twt1).contributor(acnt).fetch();
   assertThat(lst.size(), is(2));
   // DBからの取得リストの並び保証なし
 }
Пример #9
0
 // -------------------------------------+
 @Test
 public void findRepostByUsers_Entity_単数_投稿者_00() {
   User usr1 = User.findBySerialCode("usr-goro").first();
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst = RepostBase.findRepostByUsers(usr1).contributor(acnt).fetch();
   assertThat(lst.size(), is(2));
   // DBからの取得リストの並び保証なし
 }
Пример #10
0
 @Test
 public void findRepostByTweets_String_複数_投稿者_00() {
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByTweets("twt-goro2", "twt-jiro1").contributor(acnt).fetch();
   assertThat(lst.size(), is(5));
   // DBからの取得リストの並び保証なし
 }
Пример #11
0
 // -------------------------------------+
 @Test
 public void findRepostByCategories_Entity_単数_投稿者_00() {
   Category cat1 = Category.findBySerialCode("cat-biz").first();
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst = RepostBase.findRepostByCategories(cat1).contributor(acnt).fetch();
   assertThat(lst.size(), is(2));
   // DBからの取得リストの並び保証なし
 }
Пример #12
0
 @Test
 public void findRepostByCategories_String_複数_投稿者_00() {
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByCategories("cat-biz", "cat-enta").contributor(acnt).fetch();
   assertThat(lst.size(), is(3));
   // DBからの取得リストの並び保証なし
 }
Пример #13
0
 @Test
 public void findRepostByTags_Entity_複数_投稿者_00() {
   Tag tag1 = Tag.findBySerialCode("tag-goro-red").first();
   Tag tag2 = Tag.findBySerialCode("tag-jiro-hello").first();
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst = RepostBase.findRepostByTags(tag1, tag2).contributor(acnt).fetch();
   assertThat(lst.size(), is(3));
   // DBからの取得リストの並び保証なし
 }
Пример #14
0
 @Test
 public void findRepostByAccounts_String_複数_降順_00() {
   List<RepostBase> lst =
       RepostBase.findRepostByAccounts("usr-goro", "usr-jiro")
           .orderBy(RepostBase.OrderBy.DATE_OF_REPOST_DESC)
           .fetch();
   assertThat(lst.size(), is(24));
   assertThat(lst.get(0).contributor.loginUser.screenName, is("goro_san"));
 }
Пример #15
0
 // -------------------------------------+
 @Test
 public void findRepostByAccounts_Entity_単数_降順_00() {
   Account acnt1 = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByAccounts(acnt1)
           .orderBy(RepostBase.OrderBy.DATE_OF_REPOST_DESC)
           .fetch();
   assertThat(lst.size(), is(17));
   assertThat(lst.get(0).contributor.loginUser.screenName, is("goro_san"));
 }
Пример #16
0
 @Test
 public void findRepostByTags_String_複数_投稿者_降順_00() {
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByTags("tag-goro-red", "tag-jiro-hello")
           .contributor(acnt)
           .orderBy(RepostBase.OrderBy.DATE_OF_REPOST_DESC)
           .fetch();
   assertThat(lst.size(), is(3));
   assertThat(lst.get(0).getLabel().serialCode, is("tag-goro-red"));
 }
Пример #17
0
 @Test
 public void findRepostByCategories_String_複数_投稿者_降順_00() {
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByCategories("cat-biz", "cat-enta")
           .contributor(acnt)
           .orderBy(RepostBase.OrderBy.DATE_OF_REPOST_DESC)
           .fetch();
   assertThat(lst.size(), is(3));
   assertThat(lst.get(0).getLabel().serialCode, is("cat-biz"));
 }
Пример #18
0
 @Test
 public void findRepostByTweets_String_複数_投稿者_降順_00() {
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByTweets("twt-goro2", "twt-jiro1")
           .contributor(acnt)
           .orderBy(RepostBase.OrderBy.DATE_OF_REPOST_DESC)
           .fetch();
   assertThat(lst.size(), is(5));
   assertThat(lst.get(0).getItem().serialCode, is("twt-jiro1"));
 }
Пример #19
0
 // -------------------------------------+
 @Test
 public void findRepostByUsers_Entity_単数_投稿者_降順_00() {
   User usr1 = User.findBySerialCode("usr-goro").first();
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByUsers(usr1)
           .contributor(acnt)
           .orderBy(RepostBase.OrderBy.DATE_OF_REPOST_DESC)
           .fetch();
   assertThat(lst.size(), is(2));
   assertThat(lst.get(0).getItem().serialCode, is("usr-goro"));
 }
Пример #20
0
  @Test
  public void createPost() {
    // Create a new user and save it
    User bob = new User("*****@*****.**", "secret", "Bob").save();

    // Create a new post
    new Post(bob, "My first post", "Hello world").save();

    // Test that the post has been created
    assertEquals(1, Post.count());

    // Retrieve all posts created by Bob
    List<Post> bobPosts = Post.find("byAuthor", bob).fetch();

    // Test
    assertEquals(1, bobPosts.size());
    Post firstPost = bobPosts.get(0);
    assertNotNull(firstPost);
    assertEquals(bob, firstPost.author);
    assertEquals("My first post", firstPost.title);
    assertEquals("Hello world", firstPost.content);
    assertNotNull(firstPost.postedAt);
  }
Пример #21
0
 @Test
 public void findRepostByAccounts_String_複数_00() {
   List<RepostBase> lst = RepostBase.findRepostByAccounts("usr-goro", "usr-jiro").fetch();
   assertThat(lst.size(), is(24));
   // DBからの取得リストの並び保証なし
 }
Пример #22
0
  @Test
  public void loadEmployeeEnhanced() {
    SienaFixtures.loadModels("data2.yml");

    // Bob
    EmployeeEnhanced bob = EmployeeEnhanced.all().filter("firstName", "Bob").get();
    assertNotNull(bob);
    assertEquals("Bob", bob.firstName);
    assertEquals("Smith", bob.lastName);
    assertEquals("password1", bob.pwd);
    assertEquals("{\"alpha1\": \"beta1\"}", bob.contactInfo.toString());
    // profileImage
    assertEquals("filename1.ext", bob.profileImage.filename);
    assertEquals("title1", bob.profileImage.title);
    assertEquals(1, bob.profileImage.views);
    assertEquals(EmployeeEnhanced.MyEnum.VAL1, bob.profileImage.itemEnum);
    // otherImages[0]
    assertEquals("filename1.ext", bob.otherImages.get(0).filename);
    assertEquals("title1", bob.otherImages.get(0).title);
    assertEquals(1, bob.otherImages.get(0).views);
    assertEquals(EmployeeEnhanced.MyEnum.VAL1, bob.otherImages.get(0).itemEnum);
    // otherImages[1]
    assertEquals("filename2.ext", bob.otherImages.get(1).filename);
    assertEquals("title2", bob.otherImages.get(1).title);
    assertEquals(2, bob.otherImages.get(1).views);
    assertEquals(EmployeeEnhanced.MyEnum.VAL2, bob.otherImages.get(1).itemEnum);
    // stillImages[test1]
    assertEquals("filename1.ext", bob.stillImages.get("test1").filename);
    assertEquals("title1", bob.stillImages.get("test1").title);
    assertEquals(1, bob.stillImages.get("test1").views);
    assertEquals(EmployeeEnhanced.MyEnum.VAL1, bob.stillImages.get("test1").itemEnum);
    // stillImages[test2]
    assertEquals("filename2.ext", bob.stillImages.get("test2").filename);
    assertEquals("title2", bob.stillImages.get("test2").title);
    assertEquals(2, bob.stillImages.get("test2").views);
    assertEquals(EmployeeEnhanced.MyEnum.VAL2, bob.stillImages.get("test2").itemEnum);
    // items[1]
    assertEquals("alpha1", bob.items.get(0).item);
    assertEquals("beta1", bob.items.get(0).item2);
    assertEquals(EmployeeEnhanced.MyEnum.VAL1, bob.items.get(0).itemEnum);
    // items[2]
    assertEquals("alpha2", bob.items.get(1).item);
    assertEquals("beta2", bob.items.get(1).item2);
    assertEquals(EmployeeEnhanced.MyEnum.VAL2, bob.items.get(1).itemEnum);
    // enumField
    assertEquals(EmployeeEnhanced.MyEnum.VAL3, bob.enumField);

    // John
    EmployeeEnhanced john = EmployeeEnhanced.all().filter("firstName", "John").get();
    assertNotNull(john);
    assertEquals("John", john.firstName);
    assertEquals("Doe", john.lastName);
    assertEquals("password2", john.pwd);
    assertEquals("{\"alpha2\": \"beta2\"}", john.contactInfo.toString());
    assertEquals("filename2.ext", john.profileImage.filename);
    assertEquals("title2", john.profileImage.title);
    assertEquals(2, john.profileImage.views);
    assertEquals(EmployeeEnhanced.MyEnum.VAL2, john.profileImage.itemEnum);
    assertEquals(bob.id, john.boss.id);

    // emp1
    EmployeeEnhanced emp1 = EmployeeEnhanced.all().filter("firstName", "emp1").get();
    assertNotNull(emp1);
    // emp2
    EmployeeEnhanced emp2 = EmployeeEnhanced.all().filter("firstName", "emp2").get();
    assertNotNull(emp2);
    // boss
    EmployeeEnhanced boss =
        EmployeeEnhanced.all(EmployeeEnhanced.class).filter("firstName", "boss").get();
    assertNotNull(boss);
    List<EmployeeEnhanced> emps = boss.employees.fetch();
    assertEquals(emp1.id, emps.get(0).id);
    assertEquals(emp2.id, emps.get(1).id);
    assertEquals(emp1.boss.id, boss.id);
    assertEquals(emp2.boss.id, boss.id);

    // query wrapper
    Query<EmployeeEnhanced> q = EmployeeEnhanced.all().getWrappedQuery();
    emps = q.filter("firstName", "boss").fetch();
    assertEquals(boss, emps.get(0));

    // enhanced functions tests
    Batch<EmployeeEnhanced> b = EmployeeEnhanced.batch().getWrappedBatch();
    List<EmployeeEnhanced> emps2 = b.getByKeys(bob.id, john.id, boss.id, emp1.id, emp2.id);
    assertEquals(bob, emps2.get(0));
    assertEquals(john, emps2.get(1));
    assertEquals(boss, emps2.get(2));
    assertEquals(emp1, emps2.get(3));
    assertEquals(emp2, emps2.get(4));

    emps2.clear();
    emps2 = EmployeeEnhanced.batch().getByKeys(bob.id, john.id, boss.id, emp1.id, emp2.id);
    assertEquals(bob, emps2.get(0));
    assertEquals(john, emps2.get(1));
    assertEquals(boss, emps2.get(2));
    assertEquals(emp1, emps2.get(3));
    assertEquals(emp2, emps2.get(4));

    emps2.clear();
    emps2 = EmployeeEnhanced.findAll();
    assertEquals(bob, emps2.get(0));
    assertEquals(john, emps2.get(1));
    assertEquals(emp1, emps2.get(2));
    assertEquals(emp2, emps2.get(3));
    assertEquals(boss, emps2.get(4));

    assertEquals(bob, EmployeeEnhanced.findById(bob.id));
    assertEquals(bob, EmployeeEnhanced.getByKey(bob.id));
    assertEquals(5, EmployeeEnhanced.count());
    EmployeeEnhanced.deleteAll();
    assertEquals(0, EmployeeEnhanced.count());
  }
Пример #23
0
 @Test
 public void findRepostByTags_String_複数_00() {
   List<RepostBase> lst = RepostBase.findRepostByTags("tag-goro-red", "tag-jiro-hello").fetch();
   assertThat(lst.size(), is(5));
   // DBからの取得リストの並び保証なし
 }
Пример #24
0
  @Test
  public void loadOtherIdModel() {
    SienaFixtures.loadModels("data4.yml");

    // chboing
    OtherIdModel chboing = OtherIdModel.all().filter("alpha", "chboing").get();
    assertNotNull(chboing);
    assertNotSame(0, chboing.myId);
    assertEquals("chboing", chboing.alpha);
    assertEquals(1, chboing.beta);

    OtherIdStringModel plouf = Model.getByKey(OtherIdStringModel.class, "plouf");
    assertNotNull(plouf);
    plouf.link.get();
    assertEquals("plouf", plouf.myId);
    assertEquals("plouf", plouf.alpha);
    assertEquals(2, plouf.beta);
    assertEquals(chboing.myId, plouf.link.myId);
    assertEquals(chboing.alpha, plouf.link.alpha);
    assertEquals(chboing.beta, plouf.link.beta);

    OtherIdStringModel2 plouf2 = Model.getByKey(OtherIdStringModel2.class, "plouf2");
    assertNotNull(plouf2);
    plouf2.link.get();
    assertEquals("plouf2", plouf2.myId);
    assertEquals("plouf2", plouf2.alpha);
    assertEquals(3, plouf2.beta);
    assertEquals(plouf.myId, plouf2.link.myId);
    assertEquals(plouf.alpha, plouf2.link.alpha);
    assertEquals(plouf.beta, plouf2.link.beta);
    assertEquals(chboing.myId, plouf2.link.link.myId);

    OtherIdStringModel2 plouf21 = Model.getByKey(OtherIdStringModel2.class, "plouf21");
    OtherIdStringModel2 plouf22 = Model.getByKey(OtherIdStringModel2.class, "plouf22");

    OtherIdStringModel3 plouf3 = Model.getByKey(OtherIdStringModel3.class, "plouf3");
    List<OtherIdStringModel2> links = plouf3.links.fetch();

    assertEquals(plouf2.myId, links.get(0).myId);
    assertEquals(plouf2.alpha, links.get(0).alpha);
    assertEquals(plouf2.beta, links.get(0).beta);
    assertEquals(plouf2.link.myId, links.get(0).link.myId);

    assertEquals(plouf21.myId, links.get(1).myId);
    assertEquals(plouf21.alpha, links.get(1).alpha);
    assertEquals(plouf21.beta, links.get(1).beta);
    assertEquals(plouf21.link.myId, links.get(1).link.myId);

    assertEquals(plouf22.myId, links.get(2).myId);
    assertEquals(plouf22.alpha, links.get(2).alpha);
    assertEquals(plouf22.beta, links.get(2).beta);
    assertEquals(plouf22.link.myId, links.get(2).link.myId);
  }
Пример #25
0
 @Test
 public void findRepostByTweets_String_複数_00() {
   List<RepostBase> lst = RepostBase.findRepostByTweets("twt-goro2", "twt-jiro1").fetch();
   assertThat(lst.size(), is(7));
   // DBからの取得リストの並び保証なし
 }
Пример #26
0
 // =============================================*
 // 問題なし
 @Test
 public void findRepostByUsers_例外_00() {
   List<RepostBase> lst = RepostBase.findRepostByUsers((Object) null).fetch();
   assertThat(lst.size(), is(10));
 }
Пример #27
0
 @Test
 public void findRepostByCategories_String_複数_00() {
   List<RepostBase> lst = RepostBase.findRepostByCategories("cat-biz", "cat-enta").fetch();
   assertThat(lst.size(), is(5));
   // DBからの取得リストの並び保証なし
 }
Пример #28
0
 @Test
 public void findRepostByUsers_String_単数_00() {
   List<RepostBase> lst = RepostBase.findRepostByUsers("usr-goro").fetch();
   assertThat(lst.size(), is(4));
   // DBからの取得リストの並び保証なし
 }
Пример #29
0
  @Test
  public void loadEmployee() {
    SienaFixtures.loadModels("data1.yml");

    // Bob
    Employee bob = Employee.all(Employee.class).filter("firstName", "Bob").get();
    assertNotNull(bob);
    assertEquals("Bob", bob.firstName);
    assertEquals("Smith", bob.lastName);
    assertEquals("password1", bob.pwd);
    assertEquals("{\"alpha1\": \"beta1\"}", bob.contactInfo.toString());
    // profileImage
    assertEquals("filename1.ext", bob.profileImage.filename);
    assertEquals("title1", bob.profileImage.title);
    assertEquals(1, bob.profileImage.views);
    assertEquals(Employee.MyEnum.VAL1, bob.profileImage.itemEnum);
    // otherImages[0]
    assertEquals("filename1.ext", bob.otherImages.get(0).filename);
    assertEquals("title1", bob.otherImages.get(0).title);
    assertEquals(1, bob.otherImages.get(0).views);
    assertEquals(Employee.MyEnum.VAL1, bob.otherImages.get(0).itemEnum);
    // otherImages[1]
    assertEquals("filename2.ext", bob.otherImages.get(1).filename);
    assertEquals("title2", bob.otherImages.get(1).title);
    assertEquals(2, bob.otherImages.get(1).views);
    assertEquals(Employee.MyEnum.VAL2, bob.otherImages.get(1).itemEnum);
    // stillImages[test1]
    assertEquals("filename1.ext", bob.stillImages.get("test1").filename);
    assertEquals("title1", bob.stillImages.get("test1").title);
    assertEquals(1, bob.stillImages.get("test1").views);
    assertEquals(Employee.MyEnum.VAL1, bob.stillImages.get("test1").itemEnum);
    // stillImages[test2]
    assertEquals("filename2.ext", bob.stillImages.get("test2").filename);
    assertEquals("title2", bob.stillImages.get("test2").title);
    assertEquals(2, bob.stillImages.get("test2").views);
    assertEquals(Employee.MyEnum.VAL2, bob.stillImages.get("test2").itemEnum);
    // items[1]
    assertEquals("alpha1", bob.items.get(0).item);
    assertEquals("beta1", bob.items.get(0).item2);
    assertEquals(Employee.MyEnum.VAL1, bob.items.get(0).itemEnum);
    // items[2]
    assertEquals("alpha2", bob.items.get(1).item);
    assertEquals("beta2", bob.items.get(1).item2);
    assertEquals(Employee.MyEnum.VAL2, bob.items.get(1).itemEnum);
    // enumField
    assertEquals(Employee.MyEnum.VAL3, bob.enumField);

    // John
    Employee john = Employee.all(Employee.class).filter("firstName", "John").get();
    assertNotNull(john);
    assertEquals("John", john.firstName);
    assertEquals("Doe", john.lastName);
    assertEquals("password2", john.pwd);
    assertEquals("{\"alpha2\": \"beta2\"}", john.contactInfo.toString());
    assertEquals("filename2.ext", john.profileImage.filename);
    assertEquals("title2", john.profileImage.title);
    assertEquals(2, john.profileImage.views);
    assertEquals(Employee.MyEnum.VAL2, john.profileImage.itemEnum);
    assertEquals(bob.id, john.boss.id);

    // emp1
    Employee emp1 = Employee.all(Employee.class).filter("firstName", "emp1").get();
    assertNotNull(emp1);
    // emp2
    Employee emp2 = Employee.all(Employee.class).filter("firstName", "emp2").get();
    assertNotNull(emp2);
    // boss
    Employee boss = Employee.all(Employee.class).filter("firstName", "boss").get();
    assertNotNull(boss);
    List<Employee> emps = boss.employees.fetch();
    assertEquals(emp1.id, emps.get(0).id);
    assertEquals(emp2.id, emps.get(1).id);
    assertEquals(emp1.boss.id, boss.id);
    assertEquals(emp2.boss.id, boss.id);
  }