mirror of https://github.com/sipwise/jitsi.git
parent
a060a4d6cc
commit
67bccdb603
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
{
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -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…
Reference in new issue