test/net/java/sip/communicator/slick/metahistory/TestMetaHistoryService.java
/**
     * tests all read methods (finders)
     */
tests all read methods (finders)
tests all read methods ( finders )
public void messageTests()
    {
        /**
         * This matches all written messages, they are minimum 5
         */
        Collection<Object> rs = metaHistoryService.findByKeyword(
            new String[]{MessageHistoryService.class.getName()},
            testMetaContact, "test");
        assertTrue("Nothing found findByKeyword ", !rs.isEmpty());
        List<String> msgs = getMessages(rs);
        assertTrue("Messages too few - findByKeyword", msgs.size() >= 5);
        /**
         * Will test case sernsitive and insensitive search
         */
        rs = metaHistoryService.findByKeyword(
            new String[]{MessageHistoryService.class.getName()},
            testMetaContact, "Test", false);
        assertTrue("Nothing found findByKeyword caseINsensitive search", !rs.isEmpty());
        msgs = getMessages(rs);
        assertTrue("Messages too few - findByKeyword", msgs.size() >= 5);
        rs = metaHistoryService.findByKeyword(
            new String[]{MessageHistoryService.class.getName()},
            testMetaContact, "Test", true);
        assertFalse("Something found by findByKeyword casesensitive search", !rs.isEmpty());
        /**
         * This must match also many messages, as tests are run many times
         * but the minimum is 3
         */
        rs = metaHistoryService.findByEndDate(
            new String[]{MessageHistoryService.class.getName()},
            testMetaContact, controlDate2);
        assertTrue("Nothing found findByEndDate", !rs.isEmpty());
        msgs = getMessages(rs);
        assertTrue("Messages too few - findByEndDate", msgs.size() >= 3);
        /**
         * This must find also many messages but atleast one
         */
        rs = metaHistoryService.findByKeywords(
            new String[]{MessageHistoryService.class.getName()},
            testMetaContact,
            new String[]{"test", "word2"});
        assertTrue("Nothing found findByKeywords", !rs.isEmpty());
        msgs = getMessages(rs);
        assertTrue("Messages too few - findByKeywords", msgs.size() >= 1);
        /**
         * Nothing to be found
         */
        rs = metaHistoryService.findByKeywords(
            new String[]{MessageHistoryService.class.getName()},
            testMetaContact,
            new String[]{"test1", "word2"});
        assertFalse("Something found findByKeywords", !rs.isEmpty());
        /**
         * must find 2 messages
         */
        rs = metaHistoryService.findByPeriod(
            new String[]{MessageHistoryService.class.getName()},
            testMetaContact, controlDate1, controlDate2);
        assertFalse("Nothing found findByPeriod", rs.isEmpty());
        msgs = getMessages(rs);
        assertEquals("Messages must be 2", 2, msgs.size());
        assertTrue("Message no found",
                   msgs.contains(messagesToSend[2].getContent()));
        assertTrue("Message no found",
                   msgs.contains(messagesToSend[3].getContent()));
        /**
         * must find 1 record
         */
        rs = metaHistoryService.findByPeriod(
            new String[]{MessageHistoryService.class.getName()},
            testMetaContact, controlDate1, controlDate2, new String[]{"word3"});
        assertTrue("Nothing found findByPeriod", !rs.isEmpty());
        msgs = getMessages(rs);
        assertEquals("Messages must be 1", msgs.size(), 1);
        assertTrue("Message no found",
                   msgs.contains(messagesToSend[2].getContent()));
        /**
         * must find 2 records
         */
        rs = metaHistoryService.findByStartDate(
            new String[]{MessageHistoryService.class.getName()},
            testMetaContact, controlDate2);
        assertTrue("Nothing found findByStartDate", !rs.isEmpty());
        msgs = getMessages(rs);
        assertEquals("Messages must be 2", msgs.size(), 2);
        assertTrue("Message no found",
                   msgs.contains(messagesToSend[4].getContent()));
        assertTrue("Message no found",
                   msgs.contains(messagesToSend[5].getContent()));
        /**
         * Must return exactly the last 3 messages
         */
        rs = metaHistoryService.findLast(
            new String[]{MessageHistoryService.class.getName()},
            testMetaContact, 3);
        assertTrue("Nothing found 8", !rs.isEmpty());
        msgs = getMessages(rs);
        assertEquals("Messages must be 3", msgs.size(), 3);
        assertTrue("Message no found",
                   msgs.contains(messagesToSend[3].getContent()));
        assertTrue("Message no found",
                   msgs.contains(messagesToSend[4].getContent()));
        assertTrue("Message no found",
                   msgs.contains(messagesToSend[5].getContent()));
        /**
         * Must return exactly the 3 messages after controlDate1
         */
        rs = metaHistoryService.findFirstMessagesAfter(
            new String[]{MessageHistoryService.class.getName()},
            testMetaContact, controlDate1, 3);
        assertTrue("Nothing found 9", !rs.isEmpty());
        msgs = getMessages(rs);
        assertEquals("Messages must be 3", msgs.size(), 3);
        assertTrue("Message no found",
                   msgs.contains(messagesToSend[2].getContent()));
        assertTrue("Message no found",
                   msgs.contains(messagesToSend[3].getContent()));
        assertTrue("Message no found",
                   msgs.contains(messagesToSend[4].getContent()));
        /**
         * Must return exactly the 3 messages before controlDate2
         */
        rs = metaHistoryService.findLastMessagesBefore(
            new String[]{MessageHistoryService.class.getName()},
            testMetaContact, controlDate2, 3);
        assertTrue("Nothing found 10", !rs.isEmpty());
        msgs = getMessages(rs);
        assertEquals("Messages must be 3", msgs.size(), 3);
        assertTrue("Message no found",
                   msgs.contains(messagesToSend[1].getContent()));
        assertTrue("Message no found",
                   msgs.contains(messagesToSend[2].getContent()));
        assertTrue("Message no found",
                   msgs.contains(messagesToSend[3].getContent()));
    }
public void messageTests ( ) { /**
         * This matches all written messages, they are minimum 5
         */ Collection < Object > rs = metaHistoryService . findByKeyword ( new String [ ] { MessageHistoryService . class . getName ( ) } , testMetaContact , "test" ) ; assertTrue ( "Nothing found findByKeyword " , ! rs . isEmpty ( ) ) ; List < String > msgs = getMessages ( rs ) ; assertTrue ( "Messages too few - findByKeyword" , msgs . size ( ) >= 5 ) ; /**
         * Will test case sernsitive and insensitive search
         */ rs = metaHistoryService . findByKeyword ( new String [ ] { MessageHistoryService . class . getName ( ) } , testMetaContact , "Test" , false ) ; assertTrue ( "Nothing found findByKeyword caseINsensitive search" , ! rs . isEmpty ( ) ) ; msgs = getMessages ( rs ) ; assertTrue ( "Messages too few - findByKeyword" , msgs . size ( ) >= 5 ) ; rs = metaHistoryService . findByKeyword ( new String [ ] { MessageHistoryService . class . getName ( ) } , testMetaContact , "Test" , true ) ; assertFalse ( "Something found by findByKeyword casesensitive search" , ! rs . isEmpty ( ) ) ; /**
         * This must match also many messages, as tests are run many times
         * but the minimum is 3
         */ rs = metaHistoryService . findByEndDate ( new String [ ] { MessageHistoryService . class . getName ( ) } , testMetaContact , controlDate2 ) ; assertTrue ( "Nothing found findByEndDate" , ! rs . isEmpty ( ) ) ; msgs = getMessages ( rs ) ; assertTrue ( "Messages too few - findByEndDate" , msgs . size ( ) >= 3 ) ; /**
         * This must find also many messages but atleast one
         */ rs = metaHistoryService . findByKeywords ( new String [ ] { MessageHistoryService . class . getName ( ) } , testMetaContact , new String [ ] { "test" , "word2" } ) ; assertTrue ( "Nothing found findByKeywords" , ! rs . isEmpty ( ) ) ; msgs = getMessages ( rs ) ; assertTrue ( "Messages too few - findByKeywords" , msgs . size ( ) >= 1 ) ; /**
         * Nothing to be found
         */ rs = metaHistoryService . findByKeywords ( new String [ ] { MessageHistoryService . class . getName ( ) } , testMetaContact , new String [ ] { "test1" , "word2" } ) ; assertFalse ( "Something found findByKeywords" , ! rs . isEmpty ( ) ) ; /**
         * must find 2 messages
         */ rs = metaHistoryService . findByPeriod ( new String [ ] { MessageHistoryService . class . getName ( ) } , testMetaContact , controlDate1 , controlDate2 ) ; assertFalse ( "Nothing found findByPeriod" , rs . isEmpty ( ) ) ; msgs = getMessages ( rs ) ; assertEquals ( "Messages must be 2" , 2 , msgs . size ( ) ) ; assertTrue ( "Message no found" , msgs . contains ( messagesToSend [ 2 ] . getContent ( ) ) ) ; assertTrue ( "Message no found" , msgs . contains ( messagesToSend [ 3 ] . getContent ( ) ) ) ; /**
         * must find 1 record
         */ rs = metaHistoryService . findByPeriod ( new String [ ] { MessageHistoryService . class . getName ( ) } , testMetaContact , controlDate1 , controlDate2 , new String [ ] { "word3" } ) ; assertTrue ( "Nothing found findByPeriod" , ! rs . isEmpty ( ) ) ; msgs = getMessages ( rs ) ; assertEquals ( "Messages must be 1" , msgs . size ( ) , 1 ) ; assertTrue ( "Message no found" , msgs . contains ( messagesToSend [ 2 ] . getContent ( ) ) ) ; /**
         * must find 2 records
         */ rs = metaHistoryService . findByStartDate ( new String [ ] { MessageHistoryService . class . getName ( ) } , testMetaContact , controlDate2 ) ; assertTrue ( "Nothing found findByStartDate" , ! rs . isEmpty ( ) ) ; msgs = getMessages ( rs ) ; assertEquals ( "Messages must be 2" , msgs . size ( ) , 2 ) ; assertTrue ( "Message no found" , msgs . contains ( messagesToSend [ 4 ] . getContent ( ) ) ) ; assertTrue ( "Message no found" , msgs . contains ( messagesToSend [ 5 ] . getContent ( ) ) ) ; /**
         * Must return exactly the last 3 messages
         */ rs = metaHistoryService . findLast ( new String [ ] { MessageHistoryService . class . getName ( ) } , testMetaContact , 3 ) ; assertTrue ( "Nothing found 8" , ! rs . isEmpty ( ) ) ; msgs = getMessages ( rs ) ; assertEquals ( "Messages must be 3" , msgs . size ( ) , 3 ) ; assertTrue ( "Message no found" , msgs . contains ( messagesToSend [ 3 ] . getContent ( ) ) ) ; assertTrue ( "Message no found" , msgs . contains ( messagesToSend [ 4 ] . getContent ( ) ) ) ; assertTrue ( "Message no found" , msgs . contains ( messagesToSend [ 5 ] . getContent ( ) ) ) ; /**
         * Must return exactly the 3 messages after controlDate1
         */ rs = metaHistoryService . findFirstMessagesAfter ( new String [ ] { MessageHistoryService . class . getName ( ) } , testMetaContact , controlDate1 , 3 ) ; assertTrue ( "Nothing found 9" , ! rs . isEmpty ( ) ) ; msgs = getMessages ( rs ) ; assertEquals ( "Messages must be 3" , msgs . size ( ) , 3 ) ; assertTrue ( "Message no found" , msgs . contains ( messagesToSend [ 2 ] . getContent ( ) ) ) ; assertTrue ( "Message no found" , msgs . contains ( messagesToSend [ 3 ] . getContent ( ) ) ) ; assertTrue ( "Message no found" , msgs . contains ( messagesToSend [ 4 ] . getContent ( ) ) ) ; /**
         * Must return exactly the 3 messages before controlDate2
         */ rs = metaHistoryService . findLastMessagesBefore ( new String [ ] { MessageHistoryService . class . getName ( ) } , testMetaContact , controlDate2 , 3 ) ; assertTrue ( "Nothing found 10" , ! rs . isEmpty ( ) ) ; msgs = getMessages ( rs ) ; assertEquals ( "Messages must be 3" , msgs . size ( ) , 3 ) ; assertTrue ( "Message no found" , msgs . contains ( messagesToSend [ 1 ] . getContent ( ) ) ) ; assertTrue ( "Message no found" , msgs . contains ( messagesToSend [ 2 ] . getContent ( ) ) ) ; assertTrue ( "Message no found" , msgs . contains ( messagesToSend [ 3 ] . getContent ( ) ) ) ; }
tests all read methods (finders)
tests all read methods ( finders )