Add Metahistory tests.

cusax-fix
Damian Minkov 17 years ago
parent a060a4d6cc
commit 67bccdb603

@ -809,7 +809,7 @@
bundle-plugin-simpleaccreg,bundle-plugin-generalconfig,
bundle-plugin-googletalkaccregwizz,bundle-argdelegation-service,
bundle-argdelegation,bundle-zrtp4j,
bundle-filehistory,bundle-metahistory"/>
bundle-filehistory,bundle-metahistory,bundle-metahistory-slick"/>
<!--BUNDLE-SC-LAUNCHER-->
<target name="bundle-sc-launcher">
@ -1988,5 +1988,14 @@ javax.swing.event, javax.swing.border"/>
prefix="net/java/sip/communicator/impl/metahistory" />
</jar>
</target>
<!--BUNDLE-METAHISTORY-SLICK-->
<target name="bundle-metahistory-slick">
<jar compress="false" destfile="${bundles.dest}/metahistory-slick.jar"
manifest="${testsrc}/net/java/sip/communicator/slick/metahistory/metahistory.slick.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/slick/metahistory"
prefix="net/java/sip/communicator/slick/metahistory"/>
</jar>
</target>
</project>

@ -106,6 +106,8 @@ felix.auto.start.6= \
reference:file:sc-bundles/meta-cl.jar \
reference:file:sc-bundles/msghistory.jar \
reference:file:sc-bundles/callhistory.jar \
reference:file:sc-bundles/filehistory.jar \
reference:file:sc-bundles/metahistory.jar \
reference:file:sc-bundles/notification.jar \
reference:file:sc-bundles/osdependent.jar
@ -125,6 +127,7 @@ felix.auto.start.7= \
reference:file:sc-bundles/protocol-icq-slick.jar \
reference:file:sc-bundles/protocol-rss-slick.jar \
reference:file:sc-bundles/msghistory-slick.jar \
reference:file:sc-bundles/metahistory-slick.jar \
reference:file:sc-bundles/callhistory-slick.jar \
reference:file:sc-bundles/popupmessagehandler-slick.jar

@ -9,21 +9,22 @@
# n.b. a multi-line continuation is marked with {white-space + back-slash + newline}.
# Comments cannot be embedded in a multi-line value list!
#
net.java.sip.communicator.slick.runner.TEST_LIST=ConfigurationServiceLick \
MetaContactListServiceLick \
NetworkAddressManagerServiceLick \
FileAccessServiceLick \
HistoryServiceLick \
SlicklessTests \
MsgHistoryServiceLick \
CallHistoryServiceLick \
JabberProtocolProviderSlick \
YahooProtocolProviderSlick \
MsnProtocolProviderSlick \
GibberishProtocolProviderServiceLick \
RssProtocolProviderServiceLick \
PopupMessageHandlerSLick
net.java.sip.communicator.slick.runner.TEST_LIST=MetaHistoryServiceSLick
#ConfigurationServiceLick \
# MetaContactListServiceLick \
# NetworkAddressManagerServiceLick \
# FileAccessServiceLick \
# HistoryServiceLick \
# SlicklessTests \
# MsgHistoryServiceLick \
# CallHistoryServiceLick \
# JabberProtocolProviderSlick \
# YahooProtocolProviderSlick \
# MsnProtocolProviderSlick \
# GibberishProtocolProviderServiceLick \
# RssProtocolProviderServiceLick \
# PopupMessageHandlerSLick
# Note that NetworkAddressManagerServiceLick currently runs
# successfully because it sets up ZERO tests - the

@ -221,10 +221,10 @@ public void updateRecord(String idProperty, String idValue,
throws IOException
{
Iterator<String> fileIterator = this.historyImpl.getFileList();
String filename = null;
while (fileIterator.hasNext())
{
String filename = fileIterator.next();
filename = fileIterator.next();
Document doc = this.historyImpl.getDocumentForFile(filename);
@ -284,10 +284,15 @@ public void updateRecord(String idProperty, String idValue,
// write changes
synchronized (this.docWriteLock)
{
if(historyImpl.getHistoryServiceImpl().isCacheEnabled())
this.historyImpl.writeFile(filename);
else
this.historyImpl.writeFile(filename, doc);
this.historyImpl.writeFile(filename, doc);
}
// this prevents that the current writer, which holds
// instance for the last document he is editing will not
// override our last changes to the document
if(filename.equals(this.currentFile))
{
this.currentDoc = doc;
}
break;

@ -342,7 +342,7 @@ else if(serv instanceof CallHistoryService)
{
CallRecord callRecord = iter.next();
if(matchAnyCallParticipant(
if(matchCallParticipant(
callRecord.getParticipantRecords(), keywords, caseSensitive))
result.add(callRecord);
}
@ -479,7 +479,7 @@ else if(serv instanceof CallHistoryService)
{
CallRecord callRecord = iter.next();
if(matchAnyCallParticipant(
if(matchCallParticipant(
callRecord.getParticipantRecords(), keywords, caseSensitive))
result.add(callRecord);
}
@ -557,7 +557,13 @@ else if(serv instanceof CallHistoryService)
}
listenWrapper.fireLastProgress(null, null, null);
return result;
LinkedList resultAsList = new LinkedList(result);
int startIndex = resultAsList.size() - count;
if(startIndex < 0)
startIndex = 0;
return resultAsList.subList(startIndex, resultAsList.size());
}
/**
@ -627,7 +633,10 @@ else if(serv instanceof CallHistoryService)
Collection col = chs.findByStartDate(date);
if(col.size() > count)
{
// before we make a sublist make sure there are sorted in the
// right order
List l = new LinkedList(col);
Collections.sort(l, new RecordsComparator());
result.addAll(l.subList(0, count));
}
else
@ -636,8 +645,13 @@ else if(serv instanceof CallHistoryService)
}
}
listenWrapper.fireLastProgress(date, null, null);
LinkedList resultAsList = new LinkedList(result);
return result;
int toIndex = count;
if(toIndex > resultAsList.size())
toIndex = resultAsList.size();
return resultAsList.subList(0, toIndex);
}
/**
@ -717,7 +731,13 @@ else if(serv instanceof CallHistoryService)
}
listenWrapper.fireLastProgress(date, null, null);
return result;
LinkedList resultAsList = new LinkedList(result);
int startIndex = resultAsList.size() - count;
if(startIndex < 0)
startIndex = 0;
return resultAsList.subList(startIndex, resultAsList.size());
}
/**
@ -781,6 +801,50 @@ else if(callParticipant.getParticipantAddress().toLowerCase().
return false;
}
private boolean matchCallParticipant(
List<CallParticipantRecord> cps, String[] keywords, boolean caseSensitive)
{
Iterator<CallParticipantRecord> iter = cps.iterator();
while (iter.hasNext())
{
boolean match = false;
CallParticipantRecord callParticipant = iter.next();
for (int i = 0; i < keywords.length; i++)
{
String k = keywords[i];
if(caseSensitive)
{
if(callParticipant.getParticipantAddress().contains(k))
{
match = true;
}
else
{
match = false;
break;
}
continue;
}
else if(callParticipant.getParticipantAddress().toLowerCase().
contains(k.toLowerCase()))
{
match = true;
}
else
{
match = false;
break;
}
}
if(match) return true;
}
return false;
}
public void serviceChanged(ServiceEvent serviceEvent)
{
if(serviceEvent.getType() == ServiceEvent.UNREGISTERING)

@ -0,0 +1,73 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.mock;
import java.io.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
/**
*
* @author Damian Minkov
*/
public class MockFileTransferImpl
extends AbstractFileTransfer
{
private String id = null;
private int direction;
private File file = null;
private Contact contact = null;
public MockFileTransferImpl(Contact c, File file, String id, int direction)
{
this.id = id;
this.direction = direction;
this.file = file;
this.contact = c;
}
/**
* Notifies all status listeners that a new
* <tt>FileTransferStatusChangeEvent</tt> occured.
*/
public void fireStatusChangeEvent(int newStatus)
{
super.fireStatusChangeEvent(newStatus);
}
@Override
public void cancel()
{
fireStatusChangeEvent(FileTransferStatusChangeEvent.CANCELED);
}
@Override
public long getTransferedBytes()
{
return 1;
}
public String getID()
{
return id;
}
public int getDirection()
{
return direction;
}
public File getFile()
{
return file;
}
public Contact getContact()
{
return contact;
}
}

@ -0,0 +1,234 @@
package net.java.sip.communicator.impl.protocol.mock;
import java.io.*;
import java.util.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
/**
* A mock implementation of a basic telephony opearation set
*
* @author Damian Minkov
*/
public class MockOperationSetFileTransfer
implements OperationSetFileTransfer
{
private static final Logger logger =
Logger.getLogger(MockOperationSetFileTransfer.class);
/**
* A list of listeners registered for file transfer events.
*/
private Vector<FileTransferListener> fileTransferListeners
= new Vector<FileTransferListener>();
/**
* A reference to the <tt>ProtocolProviderServiceSipImpl</tt> instance
* that created us.
*/
private MockProvider protocolProvider = null;
public MockOperationSetFileTransfer(MockProvider protocolProvider)
{
this.protocolProvider = protocolProvider;
}
/**
* Sends a file transfer request to the given <tt>toContact</tt> by
* specifying the local and remote file path and the <tt>fromContact</tt>,
* sending the file.
*
* @return the transfer object
*
* @param toContact the contact that should receive the file
* @param fromContact the contact sending the file
* @param remotePath the remote file path
* @param localPath the local file path
*/
public FileTransfer sendFile(Contact toContact, File file)
throws IllegalStateException,
IllegalArgumentException
{
MockFileTransferImpl fileTrans = new MockFileTransferImpl(
toContact,
file,
generateID(),
FileTransfer.OUT);
fireFileTransferCreated(new FileTransferCreatedEvent(fileTrans, new Date()));
changeFileTransferStatus(fileTrans, FileTransferStatusChangeEvent.PREPARING);
return fileTrans;
}
public void changeFileTransferStatus(FileTransfer ft, int newstatus)
{
((MockFileTransferImpl)ft).fireStatusChangeEvent(newstatus);
}
private String generateID()
{
return String.valueOf( System.currentTimeMillis()) +
String.valueOf(hashCode());
}
public void receiveFile(final File file,
final Contact from)
{
final Date requestDate = new Date();
final String id = generateID();
fireFileTransferRequest(
new FileTransferRequestEvent(
new IncomingFileTransferRequest()
{
public String getID()
{
return id;
}
public String getFileName()
{
return file.getName();
}
public String getFileDescription()
{
return file.toString();
}
public long getFileSize()
{
return file.length();
}
public Contact getSender()
{
return from;
}
public FileTransfer acceptFile(File file)
{
MockFileTransferImpl fileTrans =
new MockFileTransferImpl(
from,
file,
id,
FileTransfer.IN);
fireFileTransferCreated(
new FileTransferCreatedEvent(fileTrans, requestDate));
changeFileTransferStatus(fileTrans,
FileTransferStatusChangeEvent.PREPARING);
return fileTrans;
}
public void rejectFile()
{
}
}, requestDate));
}
/**
* Sends a file transfer request to the given <tt>toContact</tt> by
* specifying the local and remote file path and the <tt>fromContact</tt>,
* sending the file.
*
* @return the transfer object
*
* @param toContact the contact that should receive the file
* @param fromContact the contact sending the file
* @param remotePath the remote file path
* @param localPath the local file path
*/
public FileTransfer sendFile(Contact toContact, Contact fromContact, String remotePath, String localPath)
throws IllegalStateException,
IllegalArgumentException
{
return this.sendFile(toContact, new File(localPath));
}
/**
* Adds the given <tt>FileTransferListener</tt> that would listen for
* file transfer requests and created file transfers.
*
* @param listener the <tt>FileTransferListener</tt> to add
*/
public void addFileTransferListener(FileTransferListener listener)
{
synchronized(fileTransferListeners)
{
if(!fileTransferListeners.contains(listener))
{
this.fileTransferListeners.add(listener);
}
}
}
/**
* Removes the given <tt>FileTransferListener</tt> that listens for
* file transfer requests and created file transfers.
*
* @param listener the <tt>FileTransferListener</tt> to remove
*/
public void removeFileTransferListener(FileTransferListener listener)
{
synchronized(fileTransferListeners)
{
this.fileTransferListeners.remove(listener);
}
}
/**
* Delivers the specified event to all registered file transfer listeners.
*
* @param event the <tt>EventObject</tt> that we'd like delivered to all
* registered file transfer listeners.
*/
private void fireFileTransferRequest(FileTransferRequestEvent event)
{
Iterator<FileTransferListener> listeners = null;
synchronized (fileTransferListeners)
{
listeners = new ArrayList<FileTransferListener>
(fileTransferListeners).iterator();
}
while (listeners.hasNext())
{
FileTransferListener listener = listeners.next();
listener.fileTransferRequestReceived(event);
}
}
/**
* Delivers the file transfer to all registered listeners.
*
* @param fileTransfer the <tt>FileTransfer</tt> that we'd like delivered to
* all registered file transfer listeners.
*/
void fireFileTransferCreated(FileTransferCreatedEvent event)
{
Iterator<FileTransferListener> listeners = null;
synchronized (fileTransferListeners)
{
listeners = new ArrayList<FileTransferListener>
(fileTransferListeners).iterator();
}
while (listeners.hasNext())
{
FileTransferListener listener = listeners.next();
listener.fileTransferCreated(event);
}
}
}

@ -78,6 +78,13 @@ public MockProvider(String userName)
this.supportedOperationSets.put(
OperationSetBasicTelephony.class.getName(),
mockTelphonyOpSet);
MockOperationSetFileTransfer mockFileTransferOpSet =
new MockOperationSetFileTransfer(this);
this.supportedOperationSets.put(
OperationSetFileTransfer.class.getName(),
mockFileTransferOpSet);
}
/**

@ -119,7 +119,7 @@ public Collection<FileRecord> findByKeyword(
* @return Collection of FileRecords
* @throws RuntimeException
*/
Collection<FileRecord> findByKeyword(
public Collection<FileRecord> findByKeyword(
MetaContact contact, String keyword, boolean caseSensitive)
throws RuntimeException;

@ -0,0 +1,59 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.slick.metahistory;
import java.util.*;
import org.osgi.framework.*;
import junit.framework.*;
import net.java.sip.communicator.util.*;
/**
*
* @author Damian Minkov
*/
public class MetaHistoryServiceLick
extends TestSuite
implements BundleActivator
{
private static Logger logger = Logger.getLogger(MetaHistoryServiceLick.class);
protected static BundleContext bc = null;
/**
* Start the File History Sevice Implementation Compatibility Kit.
*
* @param bundleContext
* BundleContext
* @throws Exception
*/
public void start(BundleContext bundleContext)
throws Exception
{
MetaHistoryServiceLick.bc = bundleContext;
setName("MetaHistoryServiceSLick");
Hashtable properties = new Hashtable();
properties.put("service.pid", getName());
addTest(TestMetaHistoryService.suite());
bundleContext.registerService(getClass().getName(), this, properties);
logger.debug("Successfully registered " + getClass().getName());
}
/**
* stop
*
* @param bundlecontext BundleContext
* @throws Exception
*/
public void stop(BundleContext bundlecontext)
throws Exception
{
}
}

@ -0,0 +1,26 @@
Bundle-Activator: net.java.sip.communicator.slick.metahistory.MetaHistoryServiceLick
Bundle-Name: Meta History Service Implementation Compatibility Kit
Bundle-Description: A Service Implementation Compatibility Kit for the File History Service
Bundle-Vendor: sip-communicator.org
Bundle-Version: 0.0.1
System-Bundle: yes
Import-Package: junit.framework,
net.java.sip.communicator.slick.history,
net.java.sip.communicator.service.history.records,
net.java.sip.communicator.service.history,
net.java.sip.communicator.service.filehistory,
net.java.sip.communicator.service.callhistory,
net.java.sip.communicator.service.msghistory,
net.java.sip.communicator.service.contactlist,
net.java.sip.communicator.service.metahistory,
net.java.sip.communicator.impl.protocol.mock,
net.java.sip.communicator.service.protocol,
net.java.sip.communicator.service.protocol.event,
org.osgi.framework,
org.w3c.dom,
javax.xml.parsers,
net.java.sip.communicator.util,
net.java.sip.communicator.util.xml,
javax.xml.transform,
javax.xml.transform.dom,
javax.xml.transform.stream
Loading…
Cancel
Save