diff options
author | slewis | 2007-01-29 06:19:40 +0000 |
---|---|---|
committer | slewis | 2007-01-29 06:19:40 +0000 |
commit | 17a4093acb576ef6de307961cea9de8765cbfe8c (patch) | |
tree | 1df8ce09cd4f80ade525d80c9c0ec97556bf4d2c /tests/bundles | |
parent | 6eab284f3a310453b1ea879def81afacdaad2f7d (diff) | |
download | org.eclipse.ecf-17a4093acb576ef6de307961cea9de8765cbfe8c.tar.gz org.eclipse.ecf-17a4093acb576ef6de307961cea9de8765cbfe8c.tar.xz org.eclipse.ecf-17a4093acb576ef6de307961cea9de8765cbfe8c.zip |
update to test case code
Diffstat (limited to 'tests/bundles')
-rwxr-xr-x | tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/tests/datashare/ChannelTest.java | 61 |
1 files changed, 57 insertions, 4 deletions
diff --git a/tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/tests/datashare/ChannelTest.java b/tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/tests/datashare/ChannelTest.java index a01fa8d70..2b41fcf3c 100755 --- a/tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/tests/datashare/ChannelTest.java +++ b/tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/tests/datashare/ChannelTest.java @@ -11,6 +11,8 @@ package org.eclipse.ecf.tests.datashare; +import java.util.Hashtable; + import org.eclipse.ecf.core.identity.ID; import org.eclipse.ecf.core.identity.IDCreateException; import org.eclipse.ecf.core.identity.IDFactory; @@ -18,10 +20,19 @@ import org.eclipse.ecf.datashare.IChannel; import org.eclipse.ecf.datashare.IChannelContainerAdapter; import org.eclipse.ecf.datashare.IChannelListener; import org.eclipse.ecf.datashare.events.IChannelEvent; +import org.eclipse.ecf.datashare.events.IChannelMessageEvent; import org.eclipse.ecf.tests.ContainerAbstractTestCase; public class ChannelTest extends ContainerAbstractTestCase { + /** + * + */ + private static final String CHANNEL_NAME = "channel"; + private static final String CHANNEL_NAME_1 = "channel1"; + + protected Hashtable messageEvents = new Hashtable(); + /* * (non-Javadoc) * @@ -40,9 +51,22 @@ public class ChannelTest extends ContainerAbstractTestCase { protected void setUp() throws Exception { super.setUp(); createServerAndClients(); + addChannelToClients(); + connectClients(); + } + + /** + * + */ + private void addChannelToClients() throws Exception { + for(int i=0; i < clientCount; i++) { + IChannelContainerAdapter channelContainer = getChannelContainer(i); + channelContainer.createChannel(getNewID(CHANNEL_NAME),getIChannelListener(getContainerID(i)),null); + } } protected void clearClientEvents() { + messageEvents.clear(); } /* @@ -56,6 +80,10 @@ public class ChannelTest extends ContainerAbstractTestCase { clearClientEvents(); } + protected ID getContainerID(int clientIndex) { + return getClients()[clientIndex].getID(); + } + protected IChannelContainerAdapter getChannelContainer(int clientIndex) { return (IChannelContainerAdapter) getClients()[clientIndex].getAdapter(IChannelContainerAdapter.class); } @@ -65,21 +93,46 @@ public class ChannelTest extends ContainerAbstractTestCase { assertNotNull(channelContainer); } - public void testGetChannel() throws Exception { + public void testCreateChannel() throws Exception { IChannelContainerAdapter channelContainer = getChannelContainer(0); - IChannel channel = channelContainer.createChannel(getNewID("0"),getIChannelListener(),null); + IChannel channel = channelContainer.createChannel(getNewID(CHANNEL_NAME_1),getIChannelListener(getContainerID(0)),null); assertNotNull(channel); assertNotNull(channel.getID()); assertNotNull(channel.getListener()); } + public void testGetChannelFromContainer() throws Exception { + IChannelContainerAdapter channelContainer = getChannelContainer(0); + channelContainer.createChannel(getNewID(CHANNEL_NAME_1),getIChannelListener(getContainerID(0)),null); + assertNotNull(channelContainer.getChannel(getNewID(CHANNEL_NAME_1))); + } + + public void testGetChannelNamespace() throws Exception { + IChannelContainerAdapter channelContainer = getChannelContainer(0); + assertNotNull(channelContainer.getChannelNamespace()); + } + + public void testSender() throws Exception { + IChannelContainerAdapter senderContainer = getChannelContainer(0); + IChannel sender = senderContainer.getChannel(getNewID(CHANNEL_NAME)); + assertNotNull(sender); + sender.sendMessage(new String("hello").getBytes()); + sleep(3000); + assertNotNull(messageEvents.get(getContainerID(1))); + assertNotNull(messageEvents.get(getContainerID(2))); + assertNotNull(messageEvents.get(getContainerID(3))); + assertNotNull(messageEvents.get(getContainerID(4))); + } /** * @return */ - private IChannelListener getIChannelListener() throws Exception { + private IChannelListener getIChannelListener(final ID id) throws Exception { return new IChannelListener() { public void handleChannelEvent(IChannelEvent event) { - //System.out.println("handleChannelEvent("+event+")"); + if (event instanceof IChannelMessageEvent) { + IChannelMessageEvent cme = (IChannelMessageEvent) event; + messageEvents.put(id,event); + } }}; } |