@ -11,6 +11,7 @@
import junit.framework.* ;
import net.java.sip.communicator.impl.protocol.mock.* ;
import net.java.sip.communicator.service.contactlist.* ;
import net.java.sip.communicator.service.history.* ;
import net.java.sip.communicator.service.msghistory.* ;
import net.java.sip.communicator.service.protocol.* ;
import net.java.sip.communicator.service.protocol.event.* ;
@ -18,6 +19,8 @@
import org.osgi.framework.* ;
import com.google.common.xml.* ;
/ * *
* Tests message history .
* First installs the MoxkProtocolProvider to be able to send some messages
@ -53,6 +56,8 @@ public class TestMsgHistoryService
private static ServiceReference msgHistoryServiceRef = null ;
public static MessageHistoryService msgHistoryService = null ;
public static HistoryService historyService = null ;
private static MockContact testContact = null ;
private static ServiceReference metaCLref = null ;
@ -138,6 +143,14 @@ public void setupContact()
( MessageHistoryService ) MsgHistoryServiceLick . bc .
getService ( msgHistoryServiceRef ) ;
ServiceReference historyServiceRef =
MsgHistoryServiceLick . bc .
getServiceReference ( HistoryService . class . getName ( ) ) ;
historyService =
( HistoryService ) MsgHistoryServiceLick . bc .
getService ( historyServiceRef ) ;
// fill in a contact to comunicate with
MockContactGroup root =
( MockContactGroup ) mockPresOpSet . getServerStoredContactListRoot ( ) ;
@ -180,7 +193,8 @@ public void setupContact()
mockBImOpSet . createMessage ( "test message word2" + Math . random ( ) ) ,
mockBImOpSet . createMessage ( "test message word3" + Math . random ( ) ) ,
mockBImOpSet . createMessage ( "test message word4" + Math . random ( ) ) ,
mockBImOpSet . createMessage ( "test message word5" + Math . random ( ) )
mockBImOpSet . createMessage ( "test message word5" + Math . random ( ) ) ,
mockBImOpSet . createMessage ( "Hello \u0002World\u0002!" )
} ;
}
@ -380,6 +394,38 @@ public void readRecords()
msgs . contains ( messagesToSend [ 2 ] . getContent ( ) ) ) ;
}
/ * *
* Tests some special chars insert and read .
* /
public void specialChars ( )
{
mockBImOpSet . deliverMessage ( TEST_CONTACT_NAME_1 , messagesToSend [ 5 ] ) ;
waitWrite ( 500 ) ;
historyService . purgeLocallyCachedHistories ( ) ;
/ * *
* Must return exactly the last 3 messages
* /
Collection < EventObject > rs
= msgHistoryService . findLast ( testMetaContact , 3 ) ;
assertTrue ( "Nothing found 8" , ! rs . isEmpty ( ) ) ;
List < String > msgs = getMessages ( rs ) ;
assertEquals ( "Messages must be 3" , 3 , msgs . size ( ) ) ;
assertTrue ( "Message no found" ,
msgs . contains ( messagesToSend [ 3 ] . getContent ( ) ) ) ;
assertTrue ( "Message no found" ,
msgs . contains ( messagesToSend [ 4 ] . getContent ( ) ) ) ;
// For now we are stripping in history the special content chars
// in order to avoid breaking the history records in the xml
assertTrue ( "Message no found" ,
msgs . contains ( XmlEscapers . xmlContentEscaper ( ) . escape (
messagesToSend [ 5 ] . getContent ( ) ) ) ) ;
}
private static void waitWrite ( long timeout )
{
synchronized ( lock )