From 11966e7e6eff4c2dbe363dd6ccb24783e18f0cff Mon Sep 17 00:00:00 2001 From: Damian Minkov Date: Thu, 27 Jul 2006 14:39:17 +0000 Subject: [PATCH] Fixed message history tests --- lib/testing.properties | 4 +- .../msghistory/MessageHistoryActivator.java | 69 ++++- .../msghistory/MessageHistoryServiceImpl.java | 149 ++++++++-- .../msghistory/MsgHistoryServiceLick.java | 102 +------ .../msghistory/TestMsgHistoryService.java | 255 +++++++++++++----- 5 files changed, 373 insertions(+), 206 deletions(-) diff --git a/lib/testing.properties b/lib/testing.properties index 1ca22c80d..60a0e6288 100644 --- a/lib/testing.properties +++ b/lib/testing.properties @@ -7,10 +7,10 @@ test.list=ConfigurationServiceLick \ NetworkAddressManagerServiceLick \ FileAccessServiceLick \ HistoryServiceLick \ - MsgHistoryServiceLick \ SlicklessTests \ IcqProtocolProviderSlick \ - MetaContactListServiceLick + MetaContactListServiceLick \ + MsgHistoryServiceLick # Set the name of the meta contact list file to use during testing so that # we do not meddle with the file we're using while running the application diff --git a/src/net/java/sip/communicator/impl/msghistory/MessageHistoryActivator.java b/src/net/java/sip/communicator/impl/msghistory/MessageHistoryActivator.java index 4d546acd4..dd4d6ec63 100644 --- a/src/net/java/sip/communicator/impl/msghistory/MessageHistoryActivator.java +++ b/src/net/java/sip/communicator/impl/msghistory/MessageHistoryActivator.java @@ -6,13 +6,72 @@ */ package net.java.sip.communicator.impl.msghistory; -import org.ungoverned.gravity.servicebinder.GenericActivator; +import org.osgi.framework.*; +import net.java.sip.communicator.service.configuration.*; +import net.java.sip.communicator.service.history.*; +import net.java.sip.communicator.service.msghistory.*; +import net.java.sip.communicator.util.*; /** - * Invoke "Service Binder" to parse the service XML and register all services. - * - * @author Alexander Pelov + * Activates the MessageHistoryService + * + * @author Damian Minkov */ -public class MessageHistoryActivator extends GenericActivator { +public class MessageHistoryActivator + implements BundleActivator +{ + private static Logger logger = + Logger.getLogger(MessageHistoryActivator.class); + + private MessageHistoryServiceImpl msgHistoryService = null; + + /** + * Initialize and start message history + * + * @param bundleContext BundleContext + * @throws Exception + */ + public void start(BundleContext bundleContext) throws Exception + { + try{ + + logger.logEntry(); + // get the config service + ServiceReference refConfig = bundleContext.getServiceReference( + ConfigurationService.class.getName()); + + ConfigurationService configurationService = (ConfigurationService) + bundleContext.getService(refConfig); + + ServiceReference refHistory = bundleContext.getServiceReference( + HistoryService.class.getName()); + + HistoryService historyService = (HistoryService) + bundleContext.getService(refHistory); + + //Create and start the message history service. + msgHistoryService = + new MessageHistoryServiceImpl(); + // set the configuration and history service + msgHistoryService.setConfigurationService(configurationService); + msgHistoryService.setHistoryService(historyService); + + msgHistoryService.start(bundleContext); + + bundleContext.registerService( + MessageHistoryService.class.getName(), msgHistoryService, null); + + logger.info("Message History Service ...[REGISTERED]"); + } + finally + { + logger.logExit(); + } + + } + + public void stop(BundleContext bundleContext) throws Exception + { + } } diff --git a/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java b/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java index 4c20c7271..4a3a77d09 100644 --- a/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java +++ b/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java @@ -1,5 +1,3 @@ - - /* * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. * @@ -11,6 +9,7 @@ import java.io.*; import java.util.*; +import org.osgi.framework.*; import net.java.sip.communicator.service.configuration.*; import net.java.sip.communicator.service.contactlist.*; import net.java.sip.communicator.service.history.*; @@ -24,13 +23,15 @@ * @author Alexander Pelov * @author Damian Minkov */ -public class MessageHistoryServiceImpl implements MessageHistoryService, - MessageListener { - +public class MessageHistoryServiceImpl + implements MessageHistoryService, + MessageListener, + ServiceListener +{ /** * The logger for this class. */ - private static Logger log = Logger + private static Logger logger = Logger .getLogger(MessageHistoryServiceImpl.class); private static HistoryRecordStructure recordStructure = @@ -39,6 +40,11 @@ public class MessageHistoryServiceImpl implements MessageHistoryService, private static final String SEARCH_FIELD = "msg"; + /** + * The BundleContext that we got from the OSGI bus. + */ + private BundleContext bundleContext = null; + private ConfigurationService configurationService = null; private HistoryService historyService = null; @@ -76,7 +82,7 @@ public QueryResultSet findByStartDate(MetaContact contact, Date startDate) } } catch (IOException e) { - log.error("Could not read history", e); + logger.error("Could not read history", e); } } @@ -104,7 +110,7 @@ public QueryResultSet findByEndDate(MetaContact contact, Date endDate) } } catch (IOException e) { - log.error("Could not read history", e); + logger.error("Could not read history", e); } } @@ -132,7 +138,7 @@ public QueryResultSet findByPeriod(MetaContact contact, Date startDate, Date end } } catch (IOException e) { - log.error("Could not read history", e); + logger.error("Could not read history", e); } } @@ -163,7 +169,7 @@ public QueryResultSet findByPeriod(MetaContact contact, } } catch (IOException e) { - log.error("Could not read history", e); + logger.error("Could not read history", e); } } @@ -192,7 +198,7 @@ public QueryResultSet findByKeyword(MetaContact contact, String keyword) } } catch (IOException e) { - log.error("Could not read history", e); + logger.error("Could not read history", e); } } @@ -221,7 +227,7 @@ public QueryResultSet findByKeywords(MetaContact contact, String[] keywords) } } catch (IOException e) { - log.error("Could not read history", e); + logger.error("Could not read history", e); } } @@ -255,7 +261,7 @@ public QueryResultSet findLast(MetaContact contact, int count) } } catch (IOException e) { - log.error("Could not read history", e); + logger.error("Could not read history", e); } } @@ -289,6 +295,53 @@ private History getHistory(Contact localContact, Contact remoteContact) return retVal; } + /** + * starts the service. Check the current registerd protocol providers + * which supports BasicIM and adds message listener to them + * + * @param bc BundleContext + */ + public void start(BundleContext bc) + { + logger.debug("Starting the meta contact list implementation."); + this.bundleContext = bc; + + // start listening for newly register or removed protocol providers + bc.addServiceListener(this); + + ServiceReference[] protocolProviderRefs = null; + try + { + protocolProviderRefs = bc.getServiceReferences( + ProtocolProviderService.class.getName(), + null); + } + catch (InvalidSyntaxException ex) + { + // this shouldn't happen since we're providing no parameter string + // but let's log just in case. + logger.error( + "Error while retrieving service refs", ex); + return; + } + + // in case we found any + if (protocolProviderRefs != null) + { + logger.debug("Found " + + protocolProviderRefs.length + + " already installed providers."); + for (int i = 0; i < protocolProviderRefs.length; i++) + { + ProtocolProviderService provider = (ProtocolProviderService) bc + .getService(protocolProviderRefs[i]); + + this.handleProviderAdded(provider); + } + } + } + + // ////////////////////////////////////////////////////////////////////////// public void messageReceived(MessageReceivedEvent evt) { this.writeMessage("in", null, evt.getSourceContact(), evt @@ -313,7 +366,7 @@ private void writeMessage(String direction, Contact source, message.getEncoding(), message.getMessageUID(), message.getSubject() }, timestamp); } catch (IOException e) { - log.error("Could not add message to history", e); + logger.error("Could not add message to history", e); } } @@ -327,7 +380,7 @@ public void addProtocolProvider(ProtocolProviderService protocolProvider) { .get(key); basicIntantMessaging.addMessageListener(this); - log.debug("New protocol provider service implementing the " + logger.debug("New protocol provider service implementing the " + "OperationSetBasicInstantMessaging registered: " + protocolProvider.getProtocolName() + ". Listening for messages."); @@ -343,7 +396,7 @@ public void removeProtocolProvider(ProtocolProviderService protocolProvider) { .get(key); basicIntantMessaging.removeMessageListener(this); - log.debug("Protocol provider service: " + logger.debug("Protocol provider service: " + protocolProvider.getProtocolName() + " unregistered."); } } @@ -351,27 +404,27 @@ public void removeProtocolProvider(ProtocolProviderService protocolProvider) { /** * Set the configuration service. * - * @param configurationService + * @param configurationService ConfigurationService */ public void setConfigurationService( ConfigurationService configurationService) { synchronized (this.syncRoot_Config) { this.configurationService = configurationService; - log.debug("New configuration service registered."); + logger.debug("New configuration service registered."); } } /** * Remove a configuration service. * - * @param configurationService + * @param configurationService ConfigurationService */ public void unsetConfigurationService( ConfigurationService configurationService) { synchronized (this.syncRoot_Config) { if (this.configurationService == configurationService) { this.configurationService = null; - log.debug("Configuration service unregistered."); + logger.debug("Configuration service unregistered."); } } } @@ -379,7 +432,7 @@ public void unsetConfigurationService( /** * Set the configuration service. * - * @param historyService + * @param historyService HistoryService * @throws IOException * @throws IllegalArgumentException */ @@ -388,23 +441,71 @@ public void setHistoryService(HistoryService historyService) synchronized (this.syncRoot_HistoryService) { this.historyService = historyService; - log.debug("New history service registered."); + logger.debug("New history service registered."); } } /** * Remove a configuration service. * - * @param historyService + * @param historyService HistoryService */ public void unsetHistoryService(HistoryService historyService) { synchronized (this.syncRoot_HistoryService) { if (this.historyService == historyService) { this.historyService = null; - log.debug("History service unregistered."); + logger.debug("History service unregistered."); } } } + /** + * When new protocol provider is registered we check + * does it supports BasicIM and if so add a listener to it + * + * @param serviceEvent ServiceEvent + */ + public void serviceChanged(ServiceEvent serviceEvent) + { + Object sService = bundleContext.getService(serviceEvent.getServiceReference()); + + logger.trace("Received a service event for: " + sService.getClass().getName()); + + // we don't care if the source service is not a protocol provider + if (! (sService instanceof ProtocolProviderService)) + { + return; + } + + logger.debug("Service is a protocol provider."); + if (serviceEvent.getType() == ServiceEvent.REGISTERED) + { + logger.debug("Handling registration of a new Protocol Provider."); + + this.handleProviderAdded((ProtocolProviderService)sService); + } + } + + private void handleProviderAdded( + ProtocolProviderService provider) + { + logger.debug("Adding protocol provider " + provider.getProtocolName()); + + // check whether the provider has a basic im operation set + OperationSetBasicInstantMessaging opSetIm + = (OperationSetBasicInstantMessaging) provider + .getSupportedOperationSets().get( + OperationSetBasicInstantMessaging.class.getName()); + + if (opSetIm != null) + { + opSetIm.addMessageListener(this); + } + else + { + logger.debug("Service did not have a im op. set."); + } + } + } diff --git a/test/net/java/sip/communicator/slick/msghistory/MsgHistoryServiceLick.java b/test/net/java/sip/communicator/slick/msghistory/MsgHistoryServiceLick.java index f74427e1e..0fce84271 100644 --- a/test/net/java/sip/communicator/slick/msghistory/MsgHistoryServiceLick.java +++ b/test/net/java/sip/communicator/slick/msghistory/MsgHistoryServiceLick.java @@ -10,10 +10,7 @@ import org.osgi.framework.*; import junit.framework.*; -import net.java.sip.communicator.impl.protocol.mock.*; -import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.util.*; -import net.java.sip.communicator.service.msghistory.MessageHistoryService; /** * @@ -24,31 +21,6 @@ public class MsgHistoryServiceLick extends TestSuite implements BundleActivator protected static BundleContext bc = null; - static final String TEST_CONTACT_NAME = "Mincho_Penchev"; - - /** - * The provider that we use to make a dummy server-stored contactlist - * used for testing. The mockProvider is instantiated and registered - * by the metacontactlist slick activator. - */ - public static MockProvider mockProvider = null; - - /** - * The persistent presence operation set of the default mock provider. - */ - public static MockPersistentPresenceOperationSet mockPresOpSet = null; - - public static MockBasicInstantMessaging mockBImOpSet = null; - - /** - * A reference to the registration of the first mock provider. - */ - public static ServiceRegistration mockPrServiceRegistration = null; - - private static ServiceReference msgHistoryServiceRef = null; - public static MessageHistoryService msgHistoryService = null; - - /** * Start the History Sevice Implementation Compatibility Kit. * @@ -63,45 +35,10 @@ public void start(BundleContext bundleContext) throws Exception { Hashtable properties = new Hashtable(); properties.put("service.pid", getName()); - addTestSuite(TestMsgHistoryService.class); + addTest(TestMsgHistoryService.suite()); bundleContext.registerService(getClass().getName(), this, properties); logger.debug("Successfully registered " + getClass().getName()); - - MockProvider provider = new MockProvider("SlickMockUser"); - - //store thre presence op set of the new provider into the fixture - Map supportedOperationSets = - provider.getSupportedOperationSets(); - - //get the operation set presence here. - MsgHistoryServiceLick.mockPresOpSet = - (MockPersistentPresenceOperationSet) supportedOperationSets.get( - OperationSetPersistentPresence.class.getName()); - - MsgHistoryServiceLick.mockBImOpSet = - (MockBasicInstantMessaging) supportedOperationSets.get( - OperationSetBasicInstantMessaging.class.getName()); - - // fill in a contact to comunicate with - MockContactGroup root = - (MockContactGroup) MsgHistoryServiceLick.mockPresOpSet - .getServerStoredContactListRoot(); - - root.addContact(new MockContact(TEST_CONTACT_NAME, provider)); - - - MsgHistoryServiceLick.mockPrServiceRegistration - = registerMockProviderService(provider); - - //store the created mock provider for later reference - MsgHistoryServiceLick.mockProvider = provider; - - msgHistoryServiceRef = - bundleContext.getServiceReference(MessageHistoryService.class.getName()); - - msgHistoryService = (MessageHistoryService) bundleContext.getService( - msgHistoryServiceRef); } /** @@ -111,42 +48,5 @@ public void start(BundleContext bundleContext) throws Exception { * @throws Exception */ public void stop(BundleContext bundlecontext) throws Exception { - BundleContext context = MsgHistoryServiceLick.bc; - - context.ungetService(this.msgHistoryServiceRef); - - if (MsgHistoryServiceLick.mockPrServiceRegistration != null) - MsgHistoryServiceLick.mockPrServiceRegistration.unregister(); - - this.msgHistoryService = null; - this.msgHistoryServiceRef = null; - } - - /** - * Registers the specified mock provider as an implementation of the - * ProtocolProviderService in the currently valid bundle context. - * - * @param provider the protocol provider we'd like to export as an OSGI - * service. - * @return the ServiceRegistration reference returned when registering - * the specified provider. - */ - public static ServiceRegistration registerMockProviderService( - MockProvider provider) - { - ServiceRegistration osgiRegistration = null; - Hashtable mockProvProperties = new Hashtable(); - mockProvProperties.put(ProtocolProviderFactory. - PROTOCOL_PROPERTY_NAME, - provider.getProtocolName()); - - osgiRegistration - = MsgHistoryServiceLick.bc.registerService( - ProtocolProviderService.class.getName(), - provider, - mockProvProperties); - logger.debug("Registered a mock protocol provider!"); - - return osgiRegistration; } } diff --git a/test/net/java/sip/communicator/slick/msghistory/TestMsgHistoryService.java b/test/net/java/sip/communicator/slick/msghistory/TestMsgHistoryService.java index 7d6d79701..82379190c 100644 --- a/test/net/java/sip/communicator/slick/msghistory/TestMsgHistoryService.java +++ b/test/net/java/sip/communicator/slick/msghistory/TestMsgHistoryService.java @@ -1,4 +1,3 @@ - /* * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. * @@ -11,9 +10,11 @@ import org.osgi.framework.*; 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.history.records.*; +import net.java.sip.communicator.service.msghistory.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.util.*; @@ -31,95 +32,191 @@ public class TestMsgHistoryService { private static final Logger logger = Logger.getLogger(TestMsgHistoryService.class); - private ServiceReference metaCLref = null; - private MetaContactListService metaClService = null; + static final String TEST_CONTACT_NAME = "Mincho_Penchev"; + + /** + * The provider that we use to make a dummy server-stored contactlist + * used for testing. The mockProvider is instantiated and registered + * by the metacontactlist slick activator. + */ + public static MockProvider mockProvider = null; + /** + * The persistent presence operation set of the default mock provider. + */ + public static MockPersistentPresenceOperationSet mockPresOpSet = null; + public static MockBasicInstantMessaging mockBImOpSet = null; + + private static ServiceReference msgHistoryServiceRef = null; + public static MessageHistoryService msgHistoryService = null; - private MetaContact testMetaContact = null; + private static MockContact testContact = null; - Message[] messagesToSend = null; + private static ServiceReference metaCLref = null; + private static MetaContactListService metaClService = null; + private static MetaContact testMetaContact = null; - public TestMsgHistoryService(String name) throws Exception + /** + * A reference to the registration of the first mock provider. + */ + public static ServiceRegistration mockPrServiceRegistration = null; + + private static Message[] messagesToSend = null; + + private static Date controlDate1 = null; + private static Date controlDate2 = null; + + public TestMsgHistoryService(String name) { super(name); } + public static Test suite() + { + TestSuite suite = new TestSuite(); + suite.addTest( + new TestMsgHistoryService("setupContact")); + suite.addTest( + new TestMsgHistoryService("writeRecords")); + suite.addTest( + new TestMsgHistoryService("readRecords")); + + return suite; + } + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception + { + } + + public void setupContact() + { + mockProvider = new MockProvider("MessageHistoryMockUser"); + + //store thre presence op set of the new provider into the fixture + Map supportedOperationSets = + mockProvider.getSupportedOperationSets(); + + //get the operation set presence here. + mockPresOpSet = + (MockPersistentPresenceOperationSet) supportedOperationSets.get( + OperationSetPersistentPresence.class.getName()); + + mockBImOpSet = + (MockBasicInstantMessaging) supportedOperationSets.get( + OperationSetBasicInstantMessaging.class.getName()); + + msgHistoryServiceRef = + MsgHistoryServiceLick.bc. + getServiceReference(MessageHistoryService.class.getName()); + + msgHistoryService = + (MessageHistoryService)MsgHistoryServiceLick.bc. + getService(msgHistoryServiceRef); + + // fill in a contact to comunicate with + MockContactGroup root = + (MockContactGroup)mockPresOpSet.getServerStoredContactListRoot(); + + testContact = new MockContact(TEST_CONTACT_NAME, mockProvider); + root.addContact(testContact); + metaCLref = MsgHistoryServiceLick.bc.getServiceReference( MetaContactListService.class.getName()); - metaClService = (MetaContactListService)MsgHistoryServiceLick.bc.getService(metaCLref); + metaClService = + (MetaContactListService)MsgHistoryServiceLick.bc.getService(metaCLref); - testMetaContact = - metaClService.getRoot(). - getMetaContact( - MsgHistoryServiceLick.mockProvider, - MsgHistoryServiceLick.TEST_CONTACT_NAME); + System.setProperty(MetaContactListService.PROVIDER_MASK_PROPERTY, "1"); - messagesToSend = new Message[] - { - MsgHistoryServiceLick.mockBImOpSet.createMessage("test message word1"), - MsgHistoryServiceLick.mockBImOpSet.createMessage("test message word2"), - MsgHistoryServiceLick.mockBImOpSet.createMessage("test message word3"), - MsgHistoryServiceLick.mockBImOpSet.createMessage("test message word4"), - MsgHistoryServiceLick.mockBImOpSet.createMessage("test message word5") - }; - } + Hashtable mockProvProperties = new Hashtable(); + mockProvProperties.put(ProtocolProviderFactory. + PROTOCOL_PROPERTY_NAME, mockProvider.getProtocolName()); + mockProvProperties.put(MetaContactListService.PROVIDER_MASK_PROPERTY, + "1"); - protected void tearDown() throws Exception - { - BundleContext context = MsgHistoryServiceLick.bc; + mockPrServiceRegistration = + MsgHistoryServiceLick.bc.registerService( + ProtocolProviderService.class.getName(), + mockProvider, + mockProvProperties); + logger.debug("Registered a mock protocol provider! "); - context.ungetService(this.metaCLref); + testMetaContact = metaClService.getRoot(). + getMetaContact(mockProvider, TEST_CONTACT_NAME); - this.metaClService = null; - this.metaCLref = null; + messagesToSend = new Message[] + { + mockBImOpSet.createMessage("test message word1"), + mockBImOpSet.createMessage("test message word2"), + mockBImOpSet.createMessage("test message word3"), + mockBImOpSet.createMessage("test message word4"), + mockBImOpSet.createMessage("test message word5") + }; } /** - * First send the messages then tests all read methods (finders) + * First send the messages */ - public void testReadRecords() + public void writeRecords() { + logger.info("write records "); + + assertNotNull("No metacontact", testMetaContact); + // First deliver message, so they are stored by the message history service - MsgHistoryServiceLick.mockBImOpSet.deliverMessage( - MsgHistoryServiceLick.TEST_CONTACT_NAME, messagesToSend[0]); + mockBImOpSet.deliverMessage(TEST_CONTACT_NAME, messagesToSend[0]); - Date controlDate1 = new Date(); + this.controlDate1 = new Date(); Object lock = new Object(); - synchronized(lock){ + synchronized (lock) + { // wait a moment - try{lock.wait(200);} - catch (InterruptedException ex){} + try + { + lock.wait(200); + } + catch (InterruptedException ex) + { + } } - MsgHistoryServiceLick.mockBImOpSet.deliverMessage( - MsgHistoryServiceLick.TEST_CONTACT_NAME, messagesToSend[1]); + mockBImOpSet.deliverMessage(TEST_CONTACT_NAME, messagesToSend[1]); - MsgHistoryServiceLick.mockBImOpSet.deliverMessage( - MsgHistoryServiceLick.TEST_CONTACT_NAME, messagesToSend[2]); + mockBImOpSet.deliverMessage(TEST_CONTACT_NAME, messagesToSend[2]); - Date controlDate2 = new Date(); - synchronized(lock){ + this.controlDate2 = new Date(); + synchronized (lock) + { // wait a moment - try{lock.wait(200);} - catch (InterruptedException ex){} + try + { + lock.wait(200); + } + catch (InterruptedException ex) + { + } } - MsgHistoryServiceLick.mockBImOpSet.deliverMessage( - MsgHistoryServiceLick.TEST_CONTACT_NAME, messagesToSend[3]); - - MsgHistoryServiceLick.mockBImOpSet.deliverMessage( - MsgHistoryServiceLick.TEST_CONTACT_NAME, messagesToSend[4]); + mockBImOpSet.deliverMessage(TEST_CONTACT_NAME, messagesToSend[3]); + mockBImOpSet.deliverMessage(TEST_CONTACT_NAME, messagesToSend[4]); + } + /** + * tests all read methods (finders) + */ + public void readRecords() + { +// try{ /** * This matches all written messages, they are minimum 5 */ - QueryResultSet rs = MsgHistoryServiceLick.msgHistoryService.findByKeyword( - testMetaContact, "test"); + QueryResultSet rs = msgHistoryService.findByKeyword(testMetaContact, "test"); assertTrue("Nothing found findByKeyword ", rs.hasNext()); @@ -127,13 +224,11 @@ public void testReadRecords() assertTrue("Messages too few - findByKeyword", msgs.size() >= 5); - /** * This must match also many messages, as tests are run many times * but the minimum is 3 */ - rs = MsgHistoryServiceLick.msgHistoryService.findByEndDate( - testMetaContact, controlDate2); + rs = msgHistoryService.findByEndDate(testMetaContact, controlDate2); assertTrue("Nothing found findByEndDate", rs.hasNext()); @@ -144,8 +239,9 @@ public void testReadRecords() /** * This must find also many messages but atleast one */ - rs = MsgHistoryServiceLick.msgHistoryService.findByKeywords( - testMetaContact, new String[]{"test", "word2"}); + rs = msgHistoryService.findByKeywords( + testMetaContact, + new String[]{"test", "word2"}); assertTrue("Nothing found findByKeywords", rs.hasNext()); msgs = getMessages(rs); @@ -154,62 +250,74 @@ public void testReadRecords() /** * Nothing to be found */ - rs = MsgHistoryServiceLick.msgHistoryService.findByKeywords( - testMetaContact, new String[]{"test1", "word2"}); + rs = msgHistoryService.findByKeywords( + testMetaContact, + new String[]{"test1", "word2"}); assertFalse("Something found findByKeywords", rs.hasNext()); /** * must find 2 messages */ - rs = MsgHistoryServiceLick.msgHistoryService.findByPeriod( - testMetaContact, controlDate1, controlDate2); + rs = msgHistoryService.findByPeriod( + testMetaContact, controlDate1, controlDate2); assertTrue("Nothing found findByPeriod", rs.hasNext()); msgs = getMessages(rs); assertEquals("Messages must be 2", msgs.size(), 2); - 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[1].getContent())); + assertTrue("Message no found", + msgs.contains(messagesToSend[2].getContent())); /** * must find 1 record */ - rs = MsgHistoryServiceLick.msgHistoryService.findByPeriod( - testMetaContact, controlDate1, controlDate2, new String[]{"word2"}); + rs = msgHistoryService.findByPeriod( + testMetaContact, controlDate1, controlDate2, new String[]{"word2"}); assertTrue("Nothing found findByPeriod", rs.hasNext()); msgs = getMessages(rs); assertEquals("Messages must be 1", msgs.size(), 1); - assertTrue("Message no found", msgs.contains(messagesToSend[1].getContent())); + assertTrue("Message no found", + msgs.contains(messagesToSend[1].getContent())); /** * must find 2 records */ - rs = MsgHistoryServiceLick.msgHistoryService.findByStartDate( - testMetaContact, controlDate2); + rs = msgHistoryService.findByStartDate(testMetaContact, controlDate2); assertTrue("Nothing found findByStartDate", rs.hasNext()); msgs = getMessages(rs); assertEquals("Messages must be 2", msgs.size(), 2); - 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[3].getContent())); + assertTrue("Message no found", + msgs.contains(messagesToSend[4].getContent())); /** * Must return exactly the last 3 messages */ - rs = MsgHistoryServiceLick.msgHistoryService.findLast( - testMetaContact, 3); + rs = msgHistoryService.findLast(testMetaContact, 3); assertTrue("Nothing found 8", rs.hasNext()); 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())); + 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())); +// } +// catch (Exception ex) +// {logger.error("damencho", ex); +// } + } private Vector getMessages(QueryResultSet rs) @@ -245,6 +353,5 @@ private void dumpResult(QueryResultSet rs) logger.info("----------------------"); } - } }