Exemplo n.º 1
0
 private Post makePost(String pid, String code, User user, long time) {
   Post post = new Post();
   post.setPid(pid);
   post.setCreatedTime(new Date(time));
   post.setSourceCode(code);
   post.setUserId(user.getId());
   return post;
 }
Exemplo n.º 2
0
 private void checkTimestamps(List<Post> posts) {
   long time = 0;
   List<String> pids = new LinkedList<String>();
   for (Post post : posts) {
     Assert.assertTrue(!pids.contains(post.getPid()));
     pids.add(post.getPid());
     if (time == 0) {
       time = post.getCreatedTime().getTime();
     } else {
       Assert.assertTrue(time >= post.getCreatedTime().getTime());
       time = post.getCreatedTime().getTime();
     }
   }
 }
Exemplo n.º 3
0
  @Test
  public void testRels() {

    User user = serviceFacade.getUserManager().getUserByEMail("*****@*****.**");
    Post p1 = new Post();
    Post p2 = new Post();
    Post p3 = new Post();
    Post p4 = new Post();
    p1.setSourceCode("t1");
    p2.setSourceCode("t2");
    p3.setSourceCode("t3");
    p4.setSourceCode("t3");
    p1.setPid("p1");
    p2.setPid("p2");
    p3.setPid("p3");
    p4.setPid("p3");
    serviceFacade.getPostManager().create(p1);
    serviceFacade.getPostManager().create(p3);
    Assert.assertEquals(serviceFacade.getPostManager().getAll().size(), 2);
    Assert.assertEquals(serviceFacade.getPostManager().add(Arrays.asList(p2, p3)).size(), 2);
    Assert.assertEquals(serviceFacade.getPostManager().getAll().size(), 3);
    Assert.assertEquals(serviceFacade.getPostManager().add(Arrays.asList(p1, p4)).size(), 2);
    Assert.assertEquals(serviceFacade.getPostManager().getAll().size(), 3);
    List<Entity> l = new LinkedList<Entity>();
    l.add(p1);
    l.add(p2);
    serviceFacade
        .getRelationManager()
        .createRels(user.getEntityCode(), user.getId(), l, RelationType.WALL, "123");
    Assert.assertEquals(
        serviceFacade
            .getRelationManager()
            .getRels(
                user.getEntityCode(),
                user.getId(),
                RelationManagerImpl.POST_CODE,
                null,
                RelationType.WALL,
                Collections.<String>emptyList(),
                Arrays.asList("123"),
                -1,
                -1)
            .size(),
        2);
    l.clear();
    l.add(p2);
    l.add(p3);
    serviceFacade
        .getRelationManager()
        .createRels(user.getEntityCode(), user.getId(), l, RelationType.WALL, "123");
    Assert.assertEquals(
        serviceFacade
            .getRelationManager()
            .getRels(
                user.getEntityCode(),
                user.getId(),
                RelationManagerImpl.POST_CODE,
                null,
                RelationType.WALL,
                Collections.<String>emptyList(),
                Arrays.asList("123"),
                -1,
                -1)
            .size(),
        3);
    l.clear();
    l.add(p1);
    l.add(p2);
    l.add(p3);
    serviceFacade
        .getRelationManager()
        .createRels(user.getEntityCode(), user.getId(), l, RelationType.WALL, "123");
    List<Relation> rels =
        serviceFacade
            .getRelationManager()
            .getRels(
                user.getEntityCode(),
                user.getId(),
                RelationManagerImpl.POST_CODE,
                null,
                RelationType.WALL,
                Collections.<String>emptyList(),
                Arrays.asList("123"),
                -1,
                -1);
    Assert.assertEquals(rels.size(), 3);
    Assert.assertEquals(serviceFacade.getRelationManager().getAllByRels(rels).size(), 3);

    List<ObjectId> ids = Arrays.asList(p1.getId(), p2.getId(), p3.getId());
    Assert.assertEquals(serviceFacade.getPostManager().getAll(ids).size(), 3);
  }
Exemplo n.º 4
0
 @Override
 protected List<MoimirPost> getPosts(MoimirTemplate template, Post from, int count) {
   return template.feedOperations().getPosts(from == null ? null : from.getPid(), count);
 }