xmlBlaster 2.2.0 API

org.xmlBlaster.test
Class MsgInterceptor

java.lang.Object
  extended by junit.framework.Assert
      extended by org.xmlBlaster.test.MsgInterceptor
All Implemented Interfaces:
I_Callback, I_StreamingCallback, I_Update

public class MsgInterceptor
extends junit.framework.Assert
implements I_Callback, I_StreamingCallback, I_Update

Intercepts incoming message in update() and collects them in a Vector for nice handling.


Field Summary
private  I_Update contribTestsuite
           
private  boolean countErased
           
private  byte[] msgContent
           
private  I_StreamingCallback streamTestsuite
           
private  I_Callback testsuite
           
private  java.util.Vector<Msg> updateVec
           
private  int verbosity
           
private  java.lang.ref.WeakReference weakglob
           
private  java.lang.ref.WeakReference weaklog
           
 
Constructor Summary
MsgInterceptor(Global glob, java.util.logging.Logger log, I_Callback testsuite)
           
MsgInterceptor(Global glob, java.util.logging.Logger log, I_Callback testsuite, I_StreamingCallback streamTestsuite)
           
MsgInterceptor(Global glob, java.util.logging.Logger log, I_Callback testsuite, I_Update contribTestsuite)
           
 
Method Summary
 void add(Msg msg)
           
 void clear()
          Clears all arrived messages AND the countErased flag to false
 void compareToReceived(MsgUnit[] expectedArr, java.lang.String secretCbSessionId)
          Compares all messages given by parameter 'expectedArr' and compare them with the received ones.
 void compareToReceived(PublishReturnQos[] expectedArr)
          Compares all messages given by parameter 'expectedArr' and compare them with the received ones.
 int count()
           
 void countErased(boolean countErased)
           
 Global getGlobal()
           
 java.util.logging.Logger getLog()
           
 Msg getMsg(java.lang.String oid, java.lang.String state)
          Access the updated message filtered by the given oid and state.
 Msg[] getMsgs()
           
 Msg[] getMsgs(java.lang.String oid, java.lang.String state)
          Access the updated message filtered by the given oid and state.
 void remove(Msg msg)
           
 void setLogPrefix(java.lang.String prefix)
           
 void setMsgContent(byte[] msgContent)
           
 void setVerbosity(int val)
          0: no logging 1: simple logging 2: dump messages on arrival
 java.lang.String toString()
           
 void update(java.lang.String topic, java.io.InputStream is, java.util.Map attrMap)
          This is the callback method (I_StreamingCallback) invoked from xmlBlaster It directly calls the update method from the testsuite (delegation)
 java.lang.String update(java.lang.String cbSessionId, UpdateKey updateKey, byte[] content, UpdateQos updateQos)
          This is the callback method (I_Callback) invoked from xmlBlaster It directly calls the update method from the testsuite (delegation)
 java.lang.String update(java.lang.String cbSessionId, UpdateKey updateKey, java.io.InputStream is, UpdateQos updateQos)
          This is the callback method (I_StreamingCallback) invoked from xmlBlaster It directly calls the update method from the testsuite (delegation)
 int waitOnUpdate(long timeout)
          Sleeps until timeout and returns the arrived messages.
 int waitOnUpdate(long timeout, int countExpected)
           
 int waitOnUpdate(long timeout, java.lang.String oid, java.lang.String state)
          Sleeps until timeout and returns the number of arrived messages filtered by oid and state.
 int waitOnUpdate(long timeout, java.lang.String oid, java.lang.String state, int countExpected)
          Waits until the given number of messages arrived, the messages must match the given oid and state.
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

weakglob

private final java.lang.ref.WeakReference weakglob

weaklog

private final java.lang.ref.WeakReference weaklog

testsuite

private I_Callback testsuite

verbosity

private int verbosity

countErased

private boolean countErased

streamTestsuite

private I_StreamingCallback streamTestsuite

contribTestsuite

private I_Update contribTestsuite

msgContent

private byte[] msgContent

updateVec

private java.util.Vector<Msg> updateVec
Constructor Detail

MsgInterceptor

public MsgInterceptor(Global glob,
                      java.util.logging.Logger log,
                      I_Callback testsuite,
                      I_StreamingCallback streamTestsuite)
Parameters:
testsuite - If != null your update() variant will be called as well

MsgInterceptor

public MsgInterceptor(Global glob,
                      java.util.logging.Logger log,
                      I_Callback testsuite,
                      I_Update contribTestsuite)
Parameters:
testsuite - If != null your update() variant will be called as well

MsgInterceptor

public MsgInterceptor(Global glob,
                      java.util.logging.Logger log,
                      I_Callback testsuite)
Parameters:
testsuite - If != null your update() variant will be called as well
Method Detail

getGlobal

public final Global getGlobal()

getLog

public final java.util.logging.Logger getLog()

setLogPrefix

public void setLogPrefix(java.lang.String prefix)

setVerbosity

public void setVerbosity(int val)
0: no logging 1: simple logging 2: dump messages on arrival


countErased

public void countErased(boolean countErased)
Parameters:
countErased - Set to true to count the erased notifications as well

update

public java.lang.String update(java.lang.String cbSessionId,
                               UpdateKey updateKey,
                               byte[] content,
                               UpdateQos updateQos)
                        throws XmlBlasterException
This is the callback method (I_Callback) invoked from xmlBlaster It directly calls the update method from the testsuite (delegation)

Specified by:
update in interface I_Callback
Parameters:
cbSessionId - The session ID specified by the client which registered the callback. You can specify a cbSessionId during connection (with ConnectQos) and this is bounced back here so you can authenticate the message.
updateKey - The arrived key containing the topic name
content - The arrived message content. This is your payload.
Throws:
XmlBlasterException
See Also:
I_XmlBlasterAccess

update

public java.lang.String update(java.lang.String cbSessionId,
                               UpdateKey updateKey,
                               java.io.InputStream is,
                               UpdateQos updateQos)
                        throws XmlBlasterException
This is the callback method (I_StreamingCallback) invoked from xmlBlaster It directly calls the update method from the testsuite (delegation)

Specified by:
update in interface I_StreamingCallback
Parameters:
cbSessionId - The session ID specified by the client which registered the callback. You can specify a cbSessionId during connection (with ConnectQos) and this is bounced back here so you can authenticate the message.
updateKey - The arrived key containing the topic name
Throws:
XmlBlasterException
See Also:
I_XmlBlasterAccess

update

public void update(java.lang.String topic,
                   java.io.InputStream is,
                   java.util.Map attrMap)
            throws java.lang.Exception
This is the callback method (I_StreamingCallback) invoked from xmlBlaster It directly calls the update method from the testsuite (delegation)

Specified by:
update in interface I_Update
Parameters:
topic - The topic name
attrMap - A map with attribute, can be null
Throws:
java.lang.Exception

waitOnUpdate

public int waitOnUpdate(long timeout,
                        int countExpected)
See Also:
waitOnUpdate(long, String, String, int)

waitOnUpdate

public int waitOnUpdate(long timeout,
                        java.lang.String oid,
                        java.lang.String state,
                        int countExpected)
Waits until the given number of messages arrived, the messages must match the given oid and state. It is not checked if more messages would arrive as we return after countExpected are here.

ERASE notifies are not returned

This method does not assert() it return the number of messages arrived which you can use to assert yourself.

Parameters:
timeout - in milliseconds
oid - The expected message oid, if null the oid is not checked (all oids are OK)
state - The expected state, if null the state is not checked (all states are OK)
Returns:
Number of messages arrived

waitOnUpdate

public int waitOnUpdate(long timeout)
Sleeps until timeout and returns the arrived messages.

ERASE notifies are not returned

See Also:
waitOnUpdate(long, String, String)

waitOnUpdate

public int waitOnUpdate(long timeout,
                        java.lang.String oid,
                        java.lang.String state)
Sleeps until timeout and returns the number of arrived messages filtered by oid and state.

ERASE notifies are not returned

Parameters:
timeout - in milliseconds
oid - The expected message oid, if null the oid is not checked (all oids are OK)
state - The expected state, if null the state is not checked (all states are OK)
Returns:
Number of messages arrived

add

public void add(Msg msg)

remove

public void remove(Msg msg)

clear

public void clear()
Clears all arrived messages AND the countErased flag to false


getMsgs

public Msg[] getMsgs(java.lang.String oid,
                     java.lang.String state)
Access the updated message filtered by the given oid and state.

Parameters:
oid - if null the oid is not checked
state - if null the state is not checked

getMsgs

public Msg[] getMsgs()

getMsg

public Msg getMsg(java.lang.String oid,
                  java.lang.String state)
           throws XmlBlasterException
Access the updated message filtered by the given oid and state.

Returns:
null or the message
Throws:
If - more than one message is available
XmlBlasterException

count

public int count()

compareToReceived

public void compareToReceived(MsgUnit[] expectedArr,
                              java.lang.String secretCbSessionId)
Compares all messages given by parameter 'expectedArr' and compare them with the received ones. On failure a junit - assert() is thrown.

The correct sequence and the message data is checked.

Parameters:
expectedArr - The published messages which we expect here as updates
secretCbSessionId - If not null it is checked as well

compareToReceived

public void compareToReceived(PublishReturnQos[] expectedArr)
Compares all messages given by parameter 'expectedArr' and compare them with the received ones. On failure a junit - assert() is thrown.

Especially the sequence and the rcvTimestamp is checked.

Parameters:
expectedArr - The published messages which we expect here as updates

setMsgContent

public void setMsgContent(byte[] msgContent)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

xmlBlaster 2.2.0 API

Copyright © 1999-2014 The xmlBlaster.org contributers.