1   // 
2   // Copyright (c) 2003-2005, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J. 
3   // All rights reserved. 
4   //   
5   // Redistribution and use in source and binary forms, with or without modification,  
6   // are permitted provided that the following conditions are met: 
7   //   
8   // * Redistributions of source code must retain the above copyright notice,  
9   // this list of conditions and the following disclaimer. 
10  // * Redistributions in binary form must reproduce the above copyright notice,  
11  // this list of conditions and the following disclaimer in the documentation  
12  // and/or other materials provided with the distribution. 
13  // * Neither the name of the Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.  
14  // nor the names of its contributors may be used to endorse or promote products  
15  // derived from this software without specific prior written permission. 
16  // 
17  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"  
18  // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED  
19  // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
20  // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,  
21  // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,  
22  // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
23  // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,  
24  // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)  
25  // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE  
26  // POSSIBILITY OF SUCH DAMAGE. 
27  //
28  
29  package org.objectledge.im;
30  
31  import org.jcontainer.dna.Configuration;
32  import org.objectledge.filesystem.FileSystem;
33  import org.objectledge.parameters.DefaultParameters;
34  import org.objectledge.parameters.Parameters;
35  import org.objectledge.utils.LedgeTestCase;
36  
37  /***
38   *
39   *
40   * @author <a href="rafal@caltha.pl">RafaƂ Krzewski</a>
41   * @version $Id: InstantMessagingTest.java,v 1.2 2005/07/29 05:32:53 rafal Exp $
42   */
43  public class InstantMessagingTest
44      extends LedgeTestCase
45  {
46      private InstantMessaging im;
47      
48      public void setUp() throws Exception
49      {
50          super.setUp();
51          
52          FileSystem fs = getFileSystem();
53          Configuration config = getConfig(fs, "config/org.objectledge.im.InstantMessaging.xml");
54          im = new InstantMessaging(config);
55      }
56      
57      public void testConfig()
58      {
59          // test setUp()
60      }
61      
62      public void testProtocolRegistry()
63      {
64          assertEquals(4, im.getProtocols().size());
65          assertEquals(4, im.getProtocolsById().size());
66          assertNotNull(im.getProtocol("icq"));
67          assertTrue(im.getProtocolsById().containsKey("icq"));
68      }
69      
70      public void testProtocolMethods()
71      {
72          InstantMessagingProtocol icq = im.getProtocol("icq");
73          assertEquals("ICQ", icq.getName());
74          assertEquals(null, icq.getIconUrl());
75          assertEquals("http://icq.com/", icq.getInfoUrl());
76          assertEquals("http://status.icq.com/online.gif?icq=3657252&img=5", icq.getStatusUrl("3657252"));
77          assertEquals(true, icq.isValidScreenName("3657252"));
78          assertEquals(false, icq.isValidScreenName("filem0n"));        
79      }
80      
81      public void testContacts()
82      {
83          Parameters pd = new DefaultParameters();
84          InstantMessagingProtocol icq = im.getProtocol("icq");
85          InstantMessagingProtocol tlen = im.getProtocol("tlen");
86          im.addContact(pd, new InstantMessagingContact(icq, "3657252"));
87          im.addContact(pd, new InstantMessagingContact(tlen, "filem0n"));        
88          assertEquals(2, im.getContacts(pd).size());
89          for(InstantMessagingContact contact : im.getContacts(pd))
90          {
91              if(contact.getProtocol().getId().equals("icq"))
92              {
93                  assertEquals(contact.getScreenName(), "3657252");
94              }
95              if(contact.getProtocol().getId().equals("tlen"))
96              {
97                  assertEquals(contact.getScreenName(), "filem0n");
98              }
99          }
100         im.removeContact(pd, new InstantMessagingContact(tlen, "filem0n"));
101         assertEquals(1, im.getContacts(pd).size());
102     }
103 }