@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); }
@Test public void testUserService() { // Create User user = new User(); user.setEmail("*****@*****.**"); user.setName("Eugene Zhulkov"); user.setPassword("password"); serviceFacade.getUserManager().create(user); Assert.assertNotNull(user.getId()); // Password change Assert.assertEquals(user.getPassword(), "password"); serviceFacade.getUserManager().generateNewPassword(user); Assert.assertNotEquals(user.getPassword(), "password"); }
@Test public void testSphinxSearch() throws Exception { List<User> res = serviceFacade.getSphinxSearchManager().getData("bruce", User.class); for (User re : res) { System.out.println(re); } }
@BeforeMethod public void beforeTest() { mongoTemplate.dropCollection(User.class); mongoTemplate.dropCollection(SocialSource.class); mongoTemplate.dropCollection(Post.class); mongoTemplate.dropCollection(Relation.class); User user = new User(); user.setEmail("*****@*****.**"); user.setName("Eugene Zhulkov"); serviceFacade.getUserManager().create(user); user = new User(); user.setEmail("*****@*****.**"); user.setName("Test1"); serviceFacade.getUserManager().create(user); user = new User(); user.setEmail("*****@*****.**"); user.setName("Test2"); serviceFacade.getUserManager().create(user); user = new User(); user.setEmail("*****@*****.**"); user.setName("Test3"); serviceFacade.getUserManager().create(user); }
// @Test public void testSphinxPoolClient2() { try { for (int i = 0; i < 1000; i++) { List<SphinxClient> list = new ArrayList<SphinxClient>(); for (int j = 0; j < 10; j++) { list.add(serviceFacade.getSphinxClientFactory().getSphinxClient()); } for (SphinxClient sphinxClient : list) { sphinxClient.close(); } } } catch (SphinxException sex) { Assert.fail(); logger.info("abnormal", sex); } }
@Test public void testConcurrentRun() { List<Runnable> runners = new LinkedList<Runnable>(); runners.add(new TestRunnable(500)); runners.add(new TestRunnable(1500)); runners.add(new TestRunnable(100)); serviceFacade.getConcurrentManager().runConcurrently(runners, 1100); try { Thread.sleep(1000); } catch (InterruptedException ex) { return; } Assert.assertEquals(counter.get(), 1); }
private List<Post> readFromSource(User user, String source, int offset, int count) { List<Post> result = new LinkedList<Post>(); TimelineObjectIterator it = serviceFacade.getPostManager().getObjectsIterator(RelationType.WALL); it.setCount(count); it.setOffset(offset); while (it.hasNext( user, null, null, source == null ? new HashSet<String>() : Collections.singleton(source), null, RelationType.WALL, true)) { result.addAll(it.next()); } return result; }
// @Test public void testSphinxPoolClient1() { try { SphinxClient sphinxClient; sphinxClient = serviceFacade.getSphinxClientFactory().getSphinxClient(); sphinxClient = serviceFacade.getSphinxClientFactory().getSphinxClient(); sphinxClient = serviceFacade.getSphinxClientFactory().getSphinxClient(); sphinxClient = serviceFacade.getSphinxClientFactory().getSphinxClient(); sphinxClient = serviceFacade.getSphinxClientFactory().getSphinxClient(); sphinxClient = serviceFacade.getSphinxClientFactory().getSphinxClient(); sphinxClient = serviceFacade.getSphinxClientFactory().getSphinxClient(); sphinxClient = serviceFacade.getSphinxClientFactory().getSphinxClient(); sphinxClient = serviceFacade.getSphinxClientFactory().getSphinxClient(); sphinxClient = serviceFacade.getSphinxClientFactory().getSphinxClient(); sphinxClient = serviceFacade.getSphinxClientFactory().getSphinxClient(); Assert.fail(); } catch (SphinxException sex) { logger.info("normal", sex); } }
@Test public void testChannels() { User user = serviceFacade.getUserManager().getUserByEMail("*****@*****.**"); User user1 = serviceFacade.getUserManager().getUserByEMail("*****@*****.**"); User user2 = serviceFacade.getUserManager().getUserByEMail("*****@*****.**"); User user3 = serviceFacade.getUserManager().getUserByEMail("*****@*****.**"); // Create 2 channels for user - pub/priv Channel ch1 = new Channel(); ch1.setName("pub"); ch1.setType(ChannelType.PUBLIC); ch1.setUserId(user.getId()); serviceFacade.getChannelManager().create(ch1); Channel ch2 = new Channel(); ch2.setName("priv"); ch2.setType(ChannelType.PRIVATE); ch2.setUserId(user.getId()); serviceFacade.getChannelManager().create(ch2); // Add sources to channels Assert.assertTrue(serviceFacade.getChannelManager().addSource(ch1, user1, user)); Assert.assertTrue(serviceFacade.getChannelManager().addSource(ch1, user2, user)); Assert.assertFalse(serviceFacade.getChannelManager().addSource(ch1, user2, user)); Assert.assertTrue(serviceFacade.getChannelManager().addSource(ch2, user1, user)); Assert.assertTrue(serviceFacade.getChannelManager().addSource(ch2, user2, user)); Assert.assertTrue(serviceFacade.getChannelManager().addSource(ch2, user3, user)); Assert.assertFalse(serviceFacade.getChannelManager().addSource(ch2, user3, user1)); // Read user channels Assert.assertEquals( serviceFacade.getChannelManager().getChannels(user, user, ChannelViewType.MY).size(), 2); Assert.assertEquals( serviceFacade.getChannelManager().getChannels(user, user, ChannelViewType.FOLLOWED).size(), 0); Assert.assertEquals( serviceFacade .getChannelManager() .getChannels(user, user, ChannelViewType.RECOMMENDED) .size(), 0); Assert.assertEquals( serviceFacade.getChannelManager().getChannels(user1, user1, ChannelViewType.MY).size(), 0); Assert.assertEquals(serviceFacade.getChannelManager().getChannels(user, user1, null).size(), 1); // Read user channels' sources Assert.assertEquals(serviceFacade.getChannelManager().getSources(ch1).size(), 2); Assert.assertEquals(serviceFacade.getChannelManager().getSources(ch2).size(), 3); // Follow other channel Assert.assertTrue(serviceFacade.getChannelManager().followChannel(ch1, user1)); Assert.assertFalse(serviceFacade.getChannelManager().followChannel(ch1, user1)); Assert.assertFalse(serviceFacade.getChannelManager().followChannel(ch2, user1)); // Remove source Assert.assertTrue(serviceFacade.getChannelManager().removeSource(ch2, user1, user)); Assert.assertFalse(serviceFacade.getChannelManager().removeSource(ch2, user1, user)); Assert.assertFalse(serviceFacade.getChannelManager().removeSource(ch2, user2, user1)); Assert.assertEquals(serviceFacade.getChannelManager().getSources(ch2).size(), 2); }
@Test public void testUtils() { for (int i = 0; i < 101; i++) { System.out.println( i + " " + serviceFacade .getDeclinationManager() .appendNumberEnding("подписчик", i, WordGender.MASCULINE, Declination.SECOND)); } List<String> t = Arrays.asList("1", "2", "3", "4"); Assert.assertEquals(AgUtils.subList(t, 0, 2).size(), 2); Assert.assertEquals(AgUtils.subList(t, 0, 10).size(), 4); Assert.assertEquals(AgUtils.subList(t, 1, 10).size(), 3); Assert.assertEquals(AgUtils.subList(t, 2, 10).size(), 2); Assert.assertEquals(AgUtils.subList(t, 3, 10).size(), 1); Assert.assertEquals(AgUtils.subList(t, 4, 10).size(), 0); Assert.assertEquals(AgUtils.normilezeHTML("<p style=''>123</p>345"), "123 345"); Assert.assertEquals(AgUtils.normilezeHTML("<p style=\"123\">123</p>345"), "123 345"); Assert.assertEquals( AgUtils.normilezeHTML("<A href=''>123</a> <P>1234</p> <a href=''>123</A> 5"), "<A href=''>123</a> 1234 <a href=''>123</A> 5"); Assert.assertEquals(AgUtils.trimHTML("12345", 1), "1..."); Assert.assertEquals(AgUtils.trimHTML("12345", 2), "12..."); Assert.assertEquals(AgUtils.trimHTML("12345", 3), "123..."); Assert.assertEquals(AgUtils.trimHTML("12345", 4), "1234..."); Assert.assertEquals(AgUtils.trimHTML("12345", 5), "12345"); Assert.assertEquals(AgUtils.trimHTML("<a>123</a> 234 <a>456</a> 567", 1), "<a>123</a>..."); Assert.assertEquals(AgUtils.trimHTML("<a>123</a> 234 <a>456</a> 567", 2), "<a>123</a>..."); Assert.assertEquals(AgUtils.trimHTML("<a>123</a> 234 <a>456</a> 567", 3), "<a>123</a>..."); Assert.assertEquals(AgUtils.trimHTML("<a>123</a> 234 <a>456</a> 567", 4), "<a>123</a> ..."); Assert.assertEquals(AgUtils.trimHTML("<a>123</a> 234 <a>456</a> 567", 5), "<a>123</a> 2..."); Assert.assertEquals(AgUtils.trimHTML("<a>123</a> 234 <a>456</a> 567", 6), "<a>123</a> 23..."); Assert.assertEquals( AgUtils.processTextBody("http://www.ya.ru", -1), "<a class='l_blue' target='_blank' href='http://www.ya.ru'>http://www.ya.ru</a>"); Assert.assertEquals(AgUtils.processTextBody("l=http://www.ya.ru", -1), "l=http://www.ya.ru"); Assert.assertEquals(AgUtils.processTextBody("12345", 3), "123..."); Assert.assertEquals(AgUtils.processTextBody("12345", 4), "1234..."); Assert.assertEquals(AgUtils.processTextBody("12345", 5), "12345"); Assert.assertEquals( AgUtils.processTextBody("http://www.ya.ru", 10), "<a class='l_blue' target='_blank' href='http://www.ya.ru'>http://www.ya.ru</a>..."); Assert.assertEquals( AgUtils.processTextBody("http://www.ya.ru?test=123", 10), "<a class='l_blue' target='_blank' href='http://www.ya.ru?test=123'>http://www.ya.ru?test=123</a>..."); Assert.assertEquals( AgUtils.processTextBody( "http://www.yayayayayayayayayayayayayayayayayayayayayayayayayayayayayayayaya.ru", 10), "<a class='l_blue' target='_blank' href='http://www.yayayayayayayayayayayayayayayayayayayayayayayayayayayayayayayaya.ru'>http://www.yayayayayayayayayayayayayayayayayayayay...</a>..."); Assert.assertEquals( AgUtils.processTextBody("http://www.ya.ru http://www.mail.ru", 50), "<a class='l_blue' target='_blank' href='http://www.ya.ru'>http://www.ya.ru</a> <a class='l_blue' target='_blank' href='http://www.mail.ru'>http://www.mail.ru</a>"); Assert.assertEquals( AgUtils.processTextBody("http://www.ya.ru", 3), "<a class='l_blue' target='_blank' href='http://www.ya.ru'>http://www.ya.ru</a>..."); Assert.assertEquals( AgUtils.processTextBody("1234 http://www.ya.ru", 10), "1234 <a class='l_blue' target='_blank' href='http://www.ya.ru'>http://www.ya.ru</a>..."); Assert.assertEquals( AgUtils.processTextBody("1234 http://www.ya.ru 1234", 27), "1234 <a class='l_blue' target='_blank' href='http://www.ya.ru'>http://www.ya.ru</a> 1234"); Assert.assertEquals( AgUtils.processTextBody("1234 http://www.ya.ru 1234", 25), "1234 <a class='l_blue' target='_blank' href='http://www.ya.ru'>http://www.ya.ru</a> 123..."); Assert.assertEquals(AgUtils.processTextBody("1234 http://www.ya.ru 1234", 4), "1234..."); Assert.assertEquals( AgUtils.processTextBody("1234 http://www.ya.ru 1234", 6), "1234 <a class='l_blue' target='_blank' href='http://www.ya.ru'>http://www.ya.ru</a>..."); Assert.assertEquals( AgUtils.processTextBody( "<a class='l_blue' target='_blank' href='http://www.ya.ru'>http://www.ya.ru</a>", 80), "<a class='l_blue' target='_blank' href='http://www.ya.ru'>http://www.ya.ru</a>"); Assert.assertFalse(AgUtils.isMarkupBroken("")); Assert.assertFalse(AgUtils.isMarkupBroken("<a>ttt</a>")); Assert.assertTrue(AgUtils.isMarkupBroken("<a><b><c>ttt</c></b>")); Assert.assertTrue(AgUtils.isMarkupBroken("<a href=\"test\"><b>ttt</a>")); Assert.assertTrue(AgUtils.isMarkupBroken("test <a href=\"test\">")); Assert.assertTrue(AgUtils.isMarkupBroken("test <a href=\"te")); }
@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); }
@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); }
@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); }
@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"); }
@Test public void testUserCRUD() { int ucount = serviceFacade.getUserManager().getAll().size(); // Create User user = new User(); user.setEmail("*****@*****.**"); user.setName("Eugene Zhulkov"); user.setPassword("password"); serviceFacade.getUserManager().create(user); Assert.assertNotNull(user.getId()); user = serviceFacade.getUserManager().get(user.getId()); Assert.assertTrue(user.getName().equals("Eugene Zhulkov")); Assert.assertTrue(user.getPassword().equals("password")); Assert.assertTrue(user.getEmail().equals("*****@*****.**")); // Select user = serviceFacade.getUserManager().getUserByEMail("*****@*****.**"); Assert.assertNotNull(user); User user2 = serviceFacade.getUserManager().get(user.getId()); Assert.assertNotNull(user2); Assert.assertEquals(user2.getId(), user.getId()); // Update user2.setName("Test"); serviceFacade.getUserManager().update(user2); user2 = serviceFacade.getUserManager().get(user2.getId()); Assert.assertEquals(user2.getName(), "Test"); // Get all Assert.assertEquals(serviceFacade.getUserManager().getAll().size(), ucount + 1); // Delete ObjectId uid = user2.getId(); serviceFacade.getUserManager().delete(user2.getId()); Assert.assertNull(serviceFacade.getUserManager().getUserByEMail("*****@*****.**")); Assert.assertNull(serviceFacade.getUserManager().get(uid)); Assert.assertEquals(serviceFacade.getUserManager().getAll().size(), ucount); }