Exemplo n.º 1
0
  @Test
  public void testSources2() {

    // Create
    User user = serviceFacade.getUserManager().getUserByEMail("*****@*****.**");
    User user2 = new User();
    serviceFacade.getUserManager().create(user2);

    // Connect facebook to user
    SocialSource src;
    src = new SocialSource();
    serviceFacade.getSourceManager().connectSourceToUser(user, "123", "facebook", src);
    // Connect vkontakte ti user2
    src = new SocialSource();
    serviceFacade.getSourceManager().connectSourceToUser(user2, "321", "vkontakte", src);

    Assert.assertEquals(serviceFacade.getSourceManager().getAliveSources(user.getId()).size(), 1);
    Assert.assertEquals(serviceFacade.getSourceManager().getAliveSources(user2.getId()).size(), 1);

    // Connect vkontakte to user
    src = new SocialSource();
    serviceFacade.getSourceManager().connectSourceToUser(user, "321", "vkontakte", src);

    Assert.assertEquals(serviceFacade.getSourceManager().getAliveSources(user.getId()).size(), 2);
    Assert.assertEquals(serviceFacade.getUserManager().get(user2.getId()), null);
  }
Exemplo n.º 2
0
  @Test
  public void testSocial() {

    // Create
    User user = serviceFacade.getUserManager().getUserByEMail("*****@*****.**");

    // Connect social sources
    User user2;
    user2 = serviceFacade.getUserManager().getUserBySocialSource("1234", "facebook");
    Assert.assertNull(user2);
    SocialSource token = serviceFacade.getSourceManager().get(user.getId(), "facebook");
    Assert.assertNull(token);
    token = new SocialSource();
    token.setSourceCode("facebook");
    token.setExtId("1234");
    token.setUserId(user.getId());
    serviceFacade.getSourceManager().create(token);
    token = new SocialSource();
    token.setSourceCode("vkontakte");
    token.setExtId("4321");
    token.setUserId(user.getId());
    serviceFacade.getSourceManager().create(token);

    // Get named source for user
    token = serviceFacade.getSourceManager().get(user.getId(), "facebook");
    Assert.assertNotNull(token);
    Assert.assertEquals(token.getExtId(), "1234");

    token = serviceFacade.getSourceManager().get(user.getId(), "vkontakte");
    Assert.assertNotNull(token);
    Assert.assertEquals(token.getExtId(), "4321");

    // Get user by social creds
    user2 = serviceFacade.getUserManager().getUserBySocialSource("1234", "facebook");
    Assert.assertNotNull(user2);
    Assert.assertEquals(user2.getId(), user.getId());
    user2 = serviceFacade.getUserManager().getUserBySocialSource("4321", "vkontakte");
    Assert.assertNotNull(user2);
    Assert.assertEquals(user2.getId(), user.getId());

    // Get all sources for user
    List<SocialSource> sources = serviceFacade.getSourceManager().getAll(user.getId());
    Assert.assertNotNull(sources);
    Assert.assertEquals(sources.size(), 2);

    // Create another user
    User user3 = new User();
    user3.setEmail("*****@*****.**");
    user3.setName("Eugene Zhulkov");
    serviceFacade.getUserManager().create(user3);

    // Connect 3 nets
    SocialSource token1 = new SocialSource();
    token1.setSourceCode("facebook");
    token1.setExtId("12342");
    token1.setUserId(user3.getId());
    serviceFacade.getSourceManager().create(token1);

    SocialSource token2 = new SocialSource();
    token2.setSourceCode("vkontakte");
    token2.setExtId("43212");
    token2.setUserId(user3.getId());
    serviceFacade.getSourceManager().create(token2);

    SocialSource token3 = new SocialSource();
    token3.setSourceCode("twitter");
    token3.setExtId("11112");
    token3.setUserId(user3.getId());
    serviceFacade.getSourceManager().create(token3);

    Assert.assertEquals(serviceFacade.getSourceManager().getAll(user.getId()).size(), 2);
    Assert.assertEquals(serviceFacade.getSourceManager().getAll(user3.getId()).size(), 3);
    Assert.assertEquals(
        serviceFacade.getUserManager().getUserBySocialSource("12342", "facebook").getId(),
        user3.getId());
    Assert.assertEquals(
        serviceFacade.getUserManager().getUserBySocialSource("1234", "facebook").getId(),
        user.getId());

    // Disconnect sources
    serviceFacade
        .getSourceManager()
        .disconnectSourceFromUser(user, SocialSource.SourceType.OAUTH, token1.getSourceCode());
    serviceFacade
        .getSourceManager()
        .disconnectSourceFromUser(user3, SocialSource.SourceType.OAUTH, token1.getSourceCode());

    Assert.assertEquals(serviceFacade.getSourceManager().getAll(user.getId()).size(), 1);
    Assert.assertEquals(serviceFacade.getSourceManager().getAll(user3.getId()).size(), 2);

    serviceFacade
        .getSourceManager()
        .disconnectSourceFromUser(user, SocialSource.SourceType.OAUTH, token2.getSourceCode());
    serviceFacade
        .getSourceManager()
        .disconnectSourceFromUser(user3, SocialSource.SourceType.OAUTH, token2.getSourceCode());

    Assert.assertEquals(serviceFacade.getSourceManager().getAll(user.getId()).size(), 0);
    Assert.assertEquals(serviceFacade.getSourceManager().getAll(user3.getId()).size(), 1);

    serviceFacade
        .getSourceManager()
        .disconnectSourceFromUser(user, SocialSource.SourceType.OAUTH, token3.getSourceCode());
    serviceFacade
        .getSourceManager()
        .disconnectSourceFromUser(user3, SocialSource.SourceType.OAUTH, token3.getSourceCode());

    Assert.assertEquals(serviceFacade.getSourceManager().getAll(user.getId()).size(), 0);
    Assert.assertEquals(serviceFacade.getSourceManager().getAll(user3.getId()).size(), 0);
  }
Exemplo n.º 3
0
  @Test
  public void testSources() {

    // Create
    User user = serviceFacade.getUserManager().getUserByEMail("*****@*****.**");

    // Connect facebook
    SocialSource src = new SocialSource();
    serviceFacade.getSourceManager().connectSourceToUser(user, "123", "facebook", src);

    Assert.assertEquals(serviceFacade.getSourceManager().getRevokedSources(user.getId()).size(), 0);
    Assert.assertEquals(serviceFacade.getSourceManager().getAliveSources(user.getId()).size(), 1);
    Assert.assertNotEquals(
        serviceFacade.getSourceManager().getWaitingSources(user.getId()).get(0).getSourceCode(),
        "facebook");
    Assert.assertEquals(
        serviceFacade.getUserManager().getDummyUserByExtCreds("123", "facebook"), null);
    Assert.assertEquals(
        serviceFacade.getUserManager().getUserBySocialSource("123", "facebook"), user);
    Assert.assertEquals(serviceFacade.getUserManager().getUserByExtCreds("facebook", "123"), user);

    // Connect second source - twitter
    src = new SocialSource();
    serviceFacade.getSourceManager().connectSourceToUser(user, "234", "twitter", src);
    Assert.assertEquals(serviceFacade.getSourceManager().getRevokedSources(user.getId()).size(), 0);
    Assert.assertEquals(serviceFacade.getSourceManager().getAliveSources(user.getId()).size(), 2);
    Assert.assertEquals(serviceFacade.getSourceManager().getAll(user.getId()).size(), 2);
    Assert.assertEquals(
        serviceFacade.getUserManager().getDummyUserByExtCreds("234", "twitter"), null);
    Assert.assertEquals(
        serviceFacade.getUserManager().getUserBySocialSource("234", "twitter"), user);
    Assert.assertEquals(serviceFacade.getUserManager().getUserByExtCreds("twitter", "234"), user);

    // Update facebook token
    src = new SocialSource();
    src.setAccessToken("acctoken");
    serviceFacade.getSourceManager().connectSourceToUser(user, "123", "facebook", src);

    src = serviceFacade.getSourceManager().get(user.getId(), "facebook");
    Assert.assertEquals(src.getUserId(), user.getId());
    Assert.assertEquals(src.getExtId(), "123");
    Assert.assertEquals(src.getAccessToken(), "acctoken");

    // Create dummy user
    User user2 = new User();
    user2.setExtId("123456");
    user2.setSourceCode("vkontakte");
    user2.setName("Eugene Zhulkov");
    serviceFacade.getUserManager().create(user2);

    Assert.assertEquals(
        serviceFacade.getUserManager().getDummyUserByExtCreds("123456", "vkontakte"), user2);
    Assert.assertEquals(
        serviceFacade.getUserManager().getUserBySocialSource("123456", "vkontakte"), null);
    Assert.assertEquals(
        serviceFacade.getUserManager().getUserByExtCreds("vkontakte", "123456"), user2);

    // Connect 3rd source - vkontakte
    src = new SocialSource();
    serviceFacade.getSourceManager().connectSourceToUser(user, "123456", "vkontakte", src);

    Assert.assertEquals(serviceFacade.getSourceManager().getAll(user.getId()).size(), 3);
    Assert.assertEquals(serviceFacade.getUserManager().get(user2.getId()), null);

    Assert.assertEquals(
        serviceFacade.getUserManager().getDummyUserByExtCreds("123456", "vkontakte"), null);
    Assert.assertEquals(
        serviceFacade.getUserManager().getUserBySocialSource("123456", "vkontakte"), user);
    Assert.assertEquals(
        serviceFacade.getUserManager().getUserByExtCreds("vkontakte", "123456"), user);

    // Revoke 1 source
    serviceFacade.getSourceManager().revokeSourceFromUser(user, "vkontakte");
    Assert.assertEquals(serviceFacade.getSourceManager().getAll(user.getId()).size(), 3);
    Assert.assertEquals(serviceFacade.getSourceManager().getRevokedSources(user.getId()).size(), 1);
    Assert.assertEquals(serviceFacade.getSourceManager().getAliveSources(user.getId()).size(), 2);
  }
Exemplo n.º 4
0
  @Test
  public void testTimePaging() throws Exception {

    User user = serviceFacade.getUserManager().getUserByEMail("*****@*****.**");
    serviceFacade.getPostManager().deleteAll(user.getId());
    serviceFacade.getRelationManager().deleteAll();
    serviceFacade.getSourceManager().deleteAll(user.getId());

    TestTimeSource tts1 = new TestTimeSource(user, "t1", 51, 2, 50, 0);
    TestTimeSource tts2 = new TestTimeSource(user, "t2", 11, 1, 100, 200);
    TestTimePagedSource tts3 = new TestTimePagedSource(user, "t3", 100, 1, 5, 75);
    TestTimePagedSource tts4 = new TestTimePagedSource(user, "t4", 217, 3, 7, 13);

    serviceFacade.getSourceManager().registerNewBean("t1", tts1);
    serviceFacade.getSourceManager().registerNewBean("t2", tts2);
    serviceFacade.getSourceManager().registerNewBean("t3", tts3);
    serviceFacade.getSourceManager().registerNewBean("t4", tts4);
    SocialSource st = new SocialSource("", "", "", "");
    st.setSourceCode(tts1.getSourceCode());
    st.setUserId(user.getId());
    serviceFacade.getSourceManager().create(st);
    st = new SocialSource("", "", "", "");
    st.setSourceCode(tts2.getSourceCode());
    st.setUserId(user.getId());
    serviceFacade.getSourceManager().create(st);
    st = new SocialSource("", "", "", "");
    st.setSourceCode(tts3.getSourceCode());
    st.setUserId(user.getId());
    serviceFacade.getSourceManager().create(st);
    st = new SocialSource("", "", "", "");
    st.setSourceCode(tts4.getSourceCode());
    st.setUserId(user.getId());
    serviceFacade.getSourceManager().create(st);

    serviceFacade.getSourceManager().getActualSources(user.getId(), RelationType.WALL);
    Assert.assertEquals(tts1.posts.size(), 51);
    Assert.assertEquals(tts2.posts.size(), 11);
    Assert.assertEquals(tts3.posts.size(), 100);
    Assert.assertEquals(tts4.posts.size(), 217);
    Assert.assertEquals(tts3.getTimelineSource(null, null, null).getObjects(0, 10).size(), 10);
    Assert.assertEquals(tts3.getTimelineSource(null, null, null).getObjects(0, 100).size(), 100);
    Assert.assertEquals(tts3.getTimelineSource(null, null, null).getObjects(0, 300).size(), 100);

    // Simple read from sources
    List<Post> posts;
    serviceFacade.getPostManager().deleteAll(user.getId());
    serviceFacade.getRelationManager().deleteAll();
    posts = readFromSource(user, "t1", 0, 2);
    Assert.assertEquals(posts.size(), tts1.posts.size());
    Assert.assertEquals(posts.get(0).getPid(), "t1_50");
    Assert.assertEquals(posts.get(posts.size() - 1).getPid(), "t1_0");
    checkTimestamps(posts);

    posts = readFromSource(user, "t2", 0, 4);
    Assert.assertEquals(posts.size(), tts2.posts.size());
    Assert.assertEquals(posts.get(0).getPid(), "t2_10");
    Assert.assertEquals(posts.get(posts.size() - 1).getPid(), "t2_0");
    checkTimestamps(posts);

    posts = readFromSource(user, "t3", 0, 11);
    Assert.assertEquals(posts.size(), tts3.posts.size());
    Assert.assertEquals(posts.get(0).getPid(), "t3_99");
    Assert.assertEquals(posts.get(posts.size() - 1).getPid(), "t3_0");
    checkTimestamps(posts);

    posts = readFromSource(user, "t4", 0, 13);
    Assert.assertEquals(posts.size(), tts4.posts.size());
    Assert.assertEquals(posts.get(0).getPid(), "t4_216");
    Assert.assertEquals(posts.get(posts.size() - 1).getPid(), "t4_0");
    checkTimestamps(posts);

    // Simple read from all sources
    posts = readFromSource(user, null, 0, 15);
    Assert.assertEquals(posts.size(), 379);
    checkTimestamps(posts);
    serviceFacade.getPostManager().deleteAll(user.getId());
    serviceFacade.getRelationManager().deleteAll();
    posts = readFromSource(user, null, 0, 15);
    Assert.assertEquals(posts.size(), 379);
    checkTimestamps(posts);

    // Add new posts to t2 and t4
    ((LinkedList) tts2.posts).addFirst(makePost("t2_new1", tts2.getSourceCode(), user, 2000));
    ((LinkedList) tts2.posts).addFirst(makePost("t2_new2", tts2.getSourceCode(), user, 2010));
    ((LinkedList) tts2.posts).addFirst(makePost("t2_new3", tts2.getSourceCode(), user, 2100));
    ((LinkedList) tts4.posts).addFirst(makePost("t4_new1", tts4.getSourceCode(), user, 1999));
    ((LinkedList) tts4.posts).addFirst(makePost("t4_new2", tts4.getSourceCode(), user, 2010));
    ((LinkedList) tts4.posts).addFirst(makePost("t4_new3", tts4.getSourceCode(), user, 2011));

    posts = readFromSource(user, "t2", 0, 10);
    Assert.assertEquals(posts.size(), tts2.posts.size());
    Assert.assertEquals(posts.get(0).getPid(), "t2_new3");
    Assert.assertEquals(posts.get(posts.size() - 1).getPid(), "t2_0");
    checkTimestamps(posts);

    posts = readFromSource(user, "t4", 0, 11);
    Assert.assertEquals(posts.size(), tts4.posts.size());
    Assert.assertEquals(posts.get(0).getPid(), "t4_new3");
    Assert.assertEquals(posts.get(posts.size() - 1).getPid(), "t4_0");
    checkTimestamps(posts);

    posts = readFromSource(user, null, 0, 15);
    Assert.assertEquals(385, posts.size());
    checkTimestamps(posts);

    ((LinkedList) tts4.posts).addFirst(makePost("t4_new4", tts4.getSourceCode(), user, 2015));
    ((LinkedList) tts4.posts).addFirst(makePost("t4_new5", tts4.getSourceCode(), user, 2016));
    ((LinkedList) tts4.posts).addFirst(makePost("t4_new6", tts4.getSourceCode(), user, 2017));

    posts = readFromSource(user, "t4", 0, 11);
    Assert.assertEquals(posts.size(), tts4.posts.size());
    Assert.assertEquals(posts.get(0).getPid(), "t4_new6");
    Assert.assertEquals(posts.get(posts.size() - 1).getPid(), "t4_0");
    checkTimestamps(posts);

    posts = readFromSource(user, null, 0, 7);
    Assert.assertEquals(388, posts.size());
    checkTimestamps(posts);

    // Connect new source
    TestTimePagedSource tts5 = new TestTimePagedSource(user, "t5", 13, 1, 50, 0);
    serviceFacade.getSourceManager().registerNewBean("t5", tts5);
    st = new SocialSource("", "", "", "");
    st.setSourceCode(tts5.getSourceCode());
    st.setUserId(user.getId());
    serviceFacade.getSourceManager().create(st);

    posts = readFromSource(user, "t5", 0, 20);
    Assert.assertEquals(posts.size(), tts5.posts.size());
    Assert.assertEquals(posts.get(0).getPid(), "t5_12");
    Assert.assertEquals(posts.get(posts.size() - 1).getPid(), "t5_0");
    checkTimestamps(posts);

    posts = readFromSource(user, null, 0, 10);
    Assert.assertEquals(401, posts.size());
    checkTimestamps(posts);

    serviceFacade.getSourceManager().unRegisterBean("t1");
    serviceFacade.getSourceManager().unRegisterBean("t2");
    serviceFacade.getSourceManager().unRegisterBean("t3");
    serviceFacade.getSourceManager().unRegisterBean("t4");
    serviceFacade.getSourceManager().unRegisterBean("t5");

    // Read one source then connect and read another
    serviceFacade.getPostManager().deleteAll(user.getId());
    serviceFacade.getRelationManager().deleteAll();
    serviceFacade.getSourceManager().deleteAll(user.getId());
    TestTimePagedSource tts6 = new TestTimePagedSource(user, "t6", 100, 1, 5, 0);
    TestTimePagedSource tts7 = new TestTimePagedSource(user, "t7", 50, 1, 10, 0);
    serviceFacade.getSourceManager().registerNewBean("t6", tts6);
    st = new SocialSource("", "", "", "");
    st.setSourceCode(tts6.getSourceCode());
    st.setUserId(user.getId());
    serviceFacade.getSourceManager().create(st);

    posts = readFromSource(user, "t6", 0, 10);
    Assert.assertEquals(posts.size(), 100);

    serviceFacade.getSourceManager().registerNewBean("t7", tts7);
    st = new SocialSource("", "", "", "");
    st.setSourceCode(tts7.getSourceCode());
    st.setUserId(user.getId());
    serviceFacade.getSourceManager().create(st);

    posts = readFromSource(user, null, 0, 10);
    Assert.assertEquals(posts.size(), 150);

    serviceFacade.getSourceManager().unRegisterBean("t6");
    serviceFacade.getSourceManager().unRegisterBean("t7");

    // Read then delete then read again
    serviceFacade.getPostManager().deleteAll(user.getId());
    serviceFacade.getRelationManager().deleteAll();
    serviceFacade.getSourceManager().deleteAll(user.getId());
    TestTimePagedSource tts8 = new TestTimePagedSource(user, "t8", 100, 1, 10, 0);
    serviceFacade.getSourceManager().registerNewBean("t8", tts8);
    st = new SocialSource("", "", "", "");
    st.setSourceCode(tts8.getSourceCode());
    st.setUserId(user.getId());
    serviceFacade.getSourceManager().create(st);

    // del in the beginning
    posts = readFromSource(user, null, 0, 10);
    Assert.assertEquals(posts.size(), 100);
    posts = tts8.posts;
    for (int i = 0; i < 10; i++) {
      posts.remove(0);
    }
    posts = readFromSource(user, null, 0, 10);
    Assert.assertEquals(posts.size(), 100);

    // in the center
    posts = tts8.posts;
    for (int i = 0; i < 10; i++) {
      posts.remove(50);
    }
    posts = readFromSource(user, null, 0, 10);
    Assert.assertEquals(posts.size(), 100);

    // at the end
    posts = tts8.posts;
    for (int i = 0; i < 10; i++) {
      posts.remove(posts.size() - 1);
    }
    posts = readFromSource(user, null, 0, 10);
    Assert.assertEquals(posts.size(), 100);

    // full
    tts8.posts.clear();
    posts = readFromSource(user, null, 0, 10);
    Assert.assertEquals(posts.size(), 100);

    // Read 50 posts then delete some then read again
    serviceFacade.getPostManager().deleteAll(user.getId());
    serviceFacade.getRelationManager().deleteAll();
    posts.clear();
    tts8 = new TestTimePagedSource(user, "t8", 100, 1, 10, 0);
    serviceFacade.getSourceManager().registerNewBean("t8", tts8);
    TimelineObjectIterator it =
        serviceFacade.getPostManager().getObjectsIterator(RelationType.WALL);
    it.setCount(10);
    it.setOffset(0);
    for (int i = 0; i < 5; i++) {
      it.hasNext(
          user,
          null,
          null,
          null,
          Collections.singleton(tts8.getSourceCode()),
          RelationType.WALL,
          true);
      posts.addAll(it.next());
    }
    Assert.assertEquals(posts.size(), 50);
    posts = tts8.posts;
    for (int i = 0; i < 10; i++) {
      posts.remove(45);
    }
    posts = readFromSource(user, null, 0, 10);
    Assert.assertEquals(posts.size(), 90); // does not work - skips last 10 post (

    serviceFacade.getSourceManager().unRegisterBean("t8");
  }