Package de.jetwick.util

Examples of de.jetwick.util.MyDate


        assertEquals(2, tw.getTextTerms().size());
        assertEquals(2, tw2.getTextTerms().size());
    }

    JTweet createSolrTweet(long id, String twText, String user) {
        return new JTweet(id, twText, new JUser(user)).setCreatedAt(new MyDate(id).toDate());
    }
View Full Code Here


        this.twitter4j = twitter4j;
    }

    public Collection<String> updateFriendsOf(JUser user) {
        Date cacheTime = user.getLastFriendsUpdate();
        if (cacheTime == null || new MyDate().minus(cacheTime.getTime()).getDays() > 3) {
            final Collection<String> friends = new ArrayList<String>();           
            try {
                updateFromTwitter(friends, user.getScreenName(), 1000);
                if (friends.size() > 0) {
                    user.setLastFriendsUpdate(new Date());
View Full Code Here

    public void setRemoveOlderThanHours(int removeHours) {
        removeOlderThanMinutes = removeHours * 60;
    }

    public MyDate createRemoveOlderThan() {
        return new MyDate().minusMinutes(removeOlderThanMinutes).castToHour();
    }
View Full Code Here

        assertEquals("peter3", iter.next().getScreenName());
    }

    @Test
    public void testSorting() {
        MyDate day = new MyDate();
        MyDate day2 = day.clone().plusDays(1);
        twSearch.store(createSolrTweet(day, "java is a test!", "peter"), false);
        twSearch.store(createSolrTweet(day2, "java is cool and stable!", "peter2"), true);
        JetwickQuery q = new TweetQuery("java").setSort("dt", "desc");
        List<JUser> res = new ArrayList<JUser>();
        twSearch.query(res, q);
        assertEquals(2, res.size());
        assertEquals(day2.getTime(), (long) res.get(0).getOwnTweets().iterator().next().getTwitterId());

        q = new TweetQuery("java").setSort("dt", "asc");
        res.clear();
        twSearch.query(res, q);
        assertEquals(day.getTime(), (long) res.get(0).getOwnTweets().iterator().next().getTwitterId());
View Full Code Here

    public void testFindDuplicates() {
        twSearch.store(new JTweet(1L, "wikileaks is not a wtf", new JUser("userA")), false);
        twSearch.store(new JTweet(2L, "news about wikileaks", new JUser("userB")), false);

        // find dup is restricted to the last hour so use a current date
        MyDate dt = new MyDate();
        JTweet tw3 = new JTweet(3L, "wtf means wikileaks task force", new JUser("userC")).setCreatedAt(dt.toDate());
        JTweet tw4 = new JTweet(4L, "wtf wikileaks task force", new JUser("userD")).setCreatedAt(dt.plusMinutes(1).toDate());
        JTweet tw5 = new JTweet(5L, "RT @userC: wtf means wikileaks task force", new JUser("userE")).setCreatedAt(dt.plusMinutes(1).toDate());       
        twSearch.queueObjects(Arrays.asList(tw3, tw4, tw5));
        twSearch.forceEmptyQueueAndRefresh();
        assertEquals("should be empty. should NOT find tweet 4 because it is younger", 0, tw3.getDuplicates().size());
        assertEquals("should find tweet 3", 1, tw4.getDuplicates().size());

        Map<Long, JTweet> map = new LinkedHashMap<Long, JTweet>();
        JTweet tw = new JTweet(10L, "wtf wikileaks task force", new JUser("peter")).setCreatedAt(dt.plusMinutes(1).toDate());
        map.put(10L, tw);
        twSearch.findDuplicates(map);
        assertEquals("should find tweets 3 and 4", 2, tw.getDuplicates().size());
    }
View Full Code Here

        assertEquals("should find tweets 3 and 4", 2, tw.getDuplicates().size());
    }
   
    @Test
    public void testSpamDuplicates() {
        MyDate dt = new MyDate();
        JTweet tw1 = new JTweet(1L, "2488334. Increase your twitter followers now! Buy Twitter Followers", new JUser("userA")).setCreatedAt(dt.plusMinutes(1).toDate());
        JTweet tw2 = new JTweet(2L, "349366. Increase your twitter followers now! Buy Twitter Followers", new JUser("userB")).setCreatedAt(dt.plusMinutes(1).toDate());
        JTweet tw3 = new JTweet(31L, "2040312. Increase your twitter followers now! Buy Twitter Followers", new JUser("userC")).setCreatedAt(dt.plusMinutes(1).toDate());       
        twSearch.queueObjects(Arrays.asList(tw1, tw2, tw3));
        twSearch.forceEmptyQueueAndRefresh();

        assertEquals(0, tw1.getDuplicates().size());
        assertEquals(1, tw2.getDuplicates().size());
View Full Code Here

    }

    @Test
    public void testUpdateAndRemove() throws Exception {
        JTweet tw1 = createTweet(1L, "@karsten hajo", "peter");
        tw1.setCreatedAt(new MyDate().minusDays(2).toDate());

        twSearch.testUpdate(tw1);
        assertEquals(1, twSearch.countAll());
        assertEquals("@karsten hajo", twSearch.search("hajo").iterator().next().getOwnTweets().iterator().next().getText());
        assertEquals(1, twSearch.findByUserName("peter").getOwnTweets().size());
View Full Code Here

    }

    @Test
    public void testDoNotAddOldTweets() {
        JTweet tw = createTweet(2L, "RT @userA: bla bli blu", "userB");
        tw.setCreatedAt(new MyDate().minusDays(2).toDate());
        twSearch.setRemoveOlderThanDays(1);
        twSearch.queueObject(tw);
        twSearch.forceEmptyQueueAndRefresh();
        assertEquals(0, twSearch.getFeededTweets());
View Full Code Here

    }

    @Test
    public void testAddOldTweetsIfPersistent() {
        JTweet tw = createTweet(2L, "RT @userA: bla bli blu", "userB");
        Date dt = new MyDate().minusDays(2).toDate();
        tw.setUpdatedAt(dt);
        tw.setCreatedAt(dt);
        twSearch.testUpdate(tw);
        assertEquals(1, twSearch.getFeededTweets());


        // testOverwriteTweetsIfPersistent
        tw = createTweet(2L, "totally new", "userB");
        dt = new MyDate().minusDays(2).toDate();
        tw.setUpdatedAt(dt);
        tw.setCreatedAt(dt);
        twSearch.testUpdate(tw);
        assertEquals(1, twSearch.getFeededTweets());
        assertEquals(0, twSearch.search("bla").size());
View Full Code Here

    }

    @Test
    public void testDontRemoveOldIfPersistent() throws Exception {
        JTweet tw1 = createTweet(4L, "newbla next", "userc").setRetweetCount(100);
        tw1.setCreatedAt(new MyDate().minusDays(2).toDate());

        JTweet tw2 = createTweet(2L, "RT @userA: bla bli blu", "userB");
        Date dt = new MyDate().minusDays(2).toDate();
        tw2.setUpdatedAt(dt);
        tw2.setCreatedAt(dt);

        // until date is very old to let tweets going through
        twSearch.queueObjects(Arrays.asList(tw2, tw1));
        twSearch.forceEmptyQueueAndRefresh();
        assertEquals(2, twSearch.getFeededTweets());
        assertEquals(2, twSearch.countAll());
        assertEquals(100, twSearch.findByTwitterId(4L).getRetweetCount());
        assertNotNull(twSearch.findByTwitterId(2L).getUpdatedAt());

        JTweet tw3 = createTweet(3L, "another tweet grabbed from search", "userB");
        tw3.setCreatedAt(new MyDate().minusDays(2).toDate());
       
        twSearch.setRemoveOlderThanDays(1);
        twSearch.queueObject(tw3);
        twSearch.forceEmptyQueueAndRefresh();
        assertEquals(0, twSearch.getFeededTweets());
View Full Code Here

TOP

Related Classes of de.jetwick.util.MyDate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.