use of biz.xsoftware.mock.CalledMethod in project webpieces by deanhiller.
the class TestUnpacketizer method doLastPartOfSplitHeaderVerification.
private void doLastPartOfSplitHeaderVerification(ByteBuffer b, byte b1, String test) throws IOException {
helper.eraseBuffer(b);
b.put(b1);
helper.putString(b, test);
b.put(PACKET_SEPARATOR);
helper.doneFillingBuffer(b);
unpacketizer.incomingData(b, null);
CalledMethod method = listener.expect(PACKET_METHOD);
assertTrue("evt should have been an instance of ByteBuffer", method.getAllParams()[0] instanceof ByteBuffer);
b = (ByteBuffer) method.getAllParams()[0];
String s = helper.readString(b, b.remaining());
assertEquals("remaining once read should be 0", 0, b.remaining());
assertEquals("strings should be equal", test, s);
}
use of biz.xsoftware.mock.CalledMethod in project webpieces by deanhiller.
the class TestWrites method xxtestAsynchWrite.
public void xxtestAsynchWrite() throws Exception {
mockSelect.setDefaultReturnValue("getThread", Thread.currentThread());
MySelectableChannel channel = new MySelectableChannel((SocketChannel) mockSunsChannel);
MyKey key = new MyKey(channel);
mockSunsChannel.setDefaultReturnValue("getSelectableChannel", channel);
MockObject mockKey = key.getMock();
mockKey.setDefaultReturnValue("channel", mockSunsChannel);
mockKey.setDefaultReturnValue("readyOps", SelectionKey.OP_WRITE);
mockSunsChannel.setDefaultBehavior("write", new NoReadByteBuffer2(0));
client1.oldConnect(null);
mockSunsChannel.expect("connect");
ByteBuffer b = ByteBuffer.allocate(1000);
String expected = "abc";
HELPER.putString(b, expected);
HELPER.doneFillingBuffer(b);
mockSelect.addReturnValue("createRegistrationListener", mockRegListener);
mockSunsChannel.addReturnValue("write", 0);
client1.oldWrite(b, (OperationCallback) mockWriteHandler);
mockSunsChannel.expect("write");
mockSelect.setDefaultReturnValue("getKeyFromChannel", key);
String[] methodNames = new String[] { "getKeyFromChannel", "register" };
CalledMethod[] methods = mockSelect.expect(methodNames);
Object attachment = methods[1].getAllParams()[2];
key.attach(attachment);
Set<SelectionKey> set = new HashSet<SelectionKey>();
set.add(key);
mockSelect.addReturnValue("select", 1);
mockSelect.addReturnValue("selectedKeys", set);
mockKey.addReturnValue("interestOps", SelectionKey.OP_WRITE);
mockSunsChannel.addReturnValue("write", b.remaining());
//now, simlute the jdk selector going off....
listener.selectorFired();
CalledMethod m = mockSunsChannel.expect("write");
ByteBuffer actual = (ByteBuffer) m.getAllParams()[0];
String msg = HELPER.readString(actual, actual.remaining());
assertEquals(expected, msg);
}
use of biz.xsoftware.mock.CalledMethod in project webpieces by deanhiller.
the class TestNewAsynchSSLEngine2 method testDelayedRunTask.
/**
* This tests the Runnable task being run in between packets such that it
* should not cause packet feeds to create new Runnables, and can
* run before all packets are in.
*/
public void testDelayedRunTask() throws Exception {
log.trace("B*******************************************");
clientEngine.beginHandshake();
CalledMethod m = clientList.expect("packetEncrypted");
ByteBuffer b = (ByteBuffer) m.getAllParams()[0];
serverEngine.feedEncryptedPacket(b, null);
m = serverList.expect("runTask");
Runnable r = (Runnable) m.getAllParams()[0];
r.run();
m = serverList.expect("packetEncrypted");
b = (ByteBuffer) m.getAllParams()[0];
clientEngine.feedEncryptedPacket(b, null);
m = clientList.expect("runTask");
r = (Runnable) m.getAllParams()[0];
r.run();
String[] methodNames = new String[3];
methodNames[0] = "packetEncrypted";
methodNames[1] = "packetEncrypted";
methodNames[2] = "packetEncrypted";
CalledMethod[] methods = clientList.expect(methodNames);
ByteBuffer b0 = (ByteBuffer) methods[0].getAllParams()[0];
serverEngine.feedEncryptedPacket(b0, null);
ByteBuffer b1 = (ByteBuffer) methods[1].getAllParams()[0];
m = serverList.expect("runTask");
r = (Runnable) m.getAllParams()[0];
serverEngine.feedEncryptedPacket(b1, null);
ByteBuffer b2 = (ByteBuffer) methods[2].getAllParams()[0];
//THIS IS THE DELAYED RUN TASK run after second feed of data to sslEngine...
r.run();
serverEngine.feedEncryptedPacket(b2, null);
String[] methodNames1 = new String[3];
methodNames1[0] = "packetEncrypted";
methodNames1[1] = "packetEncrypted";
methodNames1[2] = "encryptedLinkEstablished";
CalledMethod[] methods1 = serverList.expect(methodNames1);
ByteBuffer b01 = (ByteBuffer) methods1[0].getAllParams()[0];
clientEngine.feedEncryptedPacket(b01, null);
ByteBuffer b11 = (ByteBuffer) methods1[1].getAllParams()[0];
clientEngine.feedEncryptedPacket(b11, null);
clientList.expect("encryptedLinkEstablished");
log.trace("E*******************************************");
}
use of biz.xsoftware.mock.CalledMethod in project webpieces by deanhiller.
the class TestNewAsynchSSLEngine2 method testHalfPackets.
public void testHalfPackets() throws Exception {
clientEngine.beginHandshake();
CalledMethod m = clientList.expect("packetEncrypted");
ByteBuffer b = (ByteBuffer) m.getAllParams()[0];
feedPacket(serverEngine, b);
m = serverList.expect("runTask");
Runnable r = (Runnable) m.getAllParams()[0];
r.run();
m = serverList.expect("packetEncrypted");
b = (ByteBuffer) m.getAllParams()[0];
log.trace("remain1=" + b.remaining());
feedPacket(clientEngine, b);
m = clientList.expect("runTask");
r = (Runnable) m.getAllParams()[0];
r.run();
String[] methodNames = new String[3];
methodNames[0] = "packetEncrypted";
methodNames[1] = "packetEncrypted";
methodNames[2] = "packetEncrypted";
CalledMethod[] methods = clientList.expect(methodNames);
ByteBuffer b0 = (ByteBuffer) methods[0].getAllParams()[0];
feedPacket(serverEngine, b0);
m = serverList.expect("runTask");
r = (Runnable) m.getAllParams()[0];
r.run();
ByteBuffer b1 = (ByteBuffer) methods[1].getAllParams()[0];
feedPacket(serverEngine, b1);
ByteBuffer b2 = (ByteBuffer) methods[2].getAllParams()[0];
feedPacket(serverEngine, b2);
methodNames = new String[3];
methodNames[0] = "packetEncrypted";
methodNames[1] = "packetEncrypted";
methodNames[2] = "encryptedLinkEstablished";
methods = serverList.expect(methodNames);
b0 = (ByteBuffer) methods[0].getAllParams()[0];
feedPacket(clientEngine, b0);
b1 = (ByteBuffer) methods[1].getAllParams()[0];
feedPacket(clientEngine, b1);
clientList.expect("encryptedLinkEstablished");
}
use of biz.xsoftware.mock.CalledMethod in project webpieces by deanhiller.
the class TestNewAsynchSSLEngine2 method testOneAndHalfPackets.
public void testOneAndHalfPackets() throws Exception {
clientEngine.beginHandshake();
CalledMethod m = clientList.expect("packetEncrypted");
ByteBuffer b = (ByteBuffer) m.getAllParams()[0];
serverEngine.feedEncryptedPacket(b, null);
m = serverList.expect("runTask");
Runnable r = (Runnable) m.getAllParams()[0];
r.run();
m = serverList.expect("packetEncrypted");
b = (ByteBuffer) m.getAllParams()[0];
clientEngine.feedEncryptedPacket(b, null);
m = clientList.expect("runTask");
r = (Runnable) m.getAllParams()[0];
r.run();
String[] methodNames = new String[3];
methodNames[0] = "packetEncrypted";
methodNames[1] = "packetEncrypted";
methodNames[2] = "packetEncrypted";
CalledMethod[] methods = clientList.expect(methodNames);
ByteBuffer b0 = (ByteBuffer) methods[0].getAllParams()[0];
ByteBuffer b1 = (ByteBuffer) methods[1].getAllParams()[0];
ByteBuffer b2 = (ByteBuffer) methods[2].getAllParams()[0];
int total = b0.remaining() + b1.remaining() + b2.remaining();
ByteBuffer combined = ByteBuffer.allocate(total);
combined.put(b0);
int lim = b1.limit();
//we only want to put part of b1 in payload
b1.limit(3);
combined.put(b1);
helper.doneFillingBuffer(combined);
serverEngine.feedEncryptedPacket(combined, null);
combined.clear();
b1.limit(lim);
combined.put(b1);
combined.put(b2);
helper.doneFillingBuffer(combined);
serverEngine.feedEncryptedPacket(combined, null);
m = serverList.expect("runTask");
r = (Runnable) m.getAllParams()[0];
r.run();
methodNames = new String[3];
methodNames[0] = "packetEncrypted";
methodNames[1] = "packetEncrypted";
methodNames[2] = "encryptedLinkEstablished";
methods = serverList.expect(methodNames);
b0 = (ByteBuffer) methods[0].getAllParams()[0];
b1 = (ByteBuffer) methods[1].getAllParams()[0];
total = b0.remaining() + b1.remaining();
combined = ByteBuffer.allocate(total);
combined.put(b0);
combined.put(b1);
helper.doneFillingBuffer(combined);
clientEngine.feedEncryptedPacket(combined, null);
clientList.expect("encryptedLinkEstablished");
}
Aggregations