log.warning("XmlBlasterException: " + e.getMessage());
assertTrue("publish - XmlBlasterException: " + e.getMessage(), false);
}
try {
GetQos qos = new GetQos(glob);
qos.addAccessFilter(new AccessFilterQos(glob, "ContentLenFilter", "1.0", ""+filterMessageContentBiggerAs));
MsgUnit[] msgUnits = con.get("<key oid='MSG'/>", qos.toXml());
assertTrue("Expected one returned message", msgUnits!=null);
assertTrue("Expected exactly one returned message", msgUnits.length==1);
assertTrue("Message content in corrupted '" + new String(msgUnits[0].getContent()) + "' versus '" + content + "'",
msgUnits[0].getContent().length == content.length());
log.info("Success: Got one message.");
} catch(XmlBlasterException e) {
log.warning("XmlBlasterException: " + e.getMessage());
assertTrue("get - XmlBlasterException: " + e.getMessage(), false);
}
log.info("TEST 2: Testing filtered message");
content = "12345678901"; // content is too long, our plugin denies this message
try {
con.publish(new MsgUnit("<key oid='MSG'/>", content.getBytes(), null));
} catch(XmlBlasterException e) {
log.warning("XmlBlasterException: " + e.getMessage());
assertTrue("publish - XmlBlasterException: " + e.getMessage(), false);
}
try {
GetQos qos = new GetQos(glob);
qos.addAccessFilter(new AccessFilterQos(glob, "ContentLenFilter", "1.0", ""+filterMessageContentBiggerAs));
MsgUnit[] msgUnits = con.get("<key oid='MSG'/>", qos.toXml());
assertTrue("Expected one returned message", msgUnits!=null);
assertEquals("Expected no returned message", 0, msgUnits.length);
log.info("Success: Got no message.");
} catch(XmlBlasterException e) {
log.warning("XmlBlasterException: " + e.getMessage());
fail("get - XmlBlasterException: " + e.getMessage());
}
log.info("TEST 3: Test what happens if the plugin throws an exception");
try { // see THROW_EXCEPTION_FOR_LEN=3
con.publish(new MsgUnit("<key oid='MSG'/>", "123".getBytes(), null));
} catch(XmlBlasterException e) {
log.warning("XmlBlasterException: " + e.getMessage());
fail("publish - XmlBlasterException: " + e.getMessage());
}
try {
GetQos qos = new GetQos(glob);
qos.addAccessFilter(new AccessFilterQos(glob, "ContentLenFilter", "1.0", ""+filterMessageContentBiggerAs));
MsgUnit[] msgUnits = con.get("<key oid='MSG'/>", qos.toXml());
fail("get() message should throw an XmlBlasterException, but it didn't happen");
} catch(XmlBlasterException e) {
log.info("SUCCESS: We expected an XmlBlasterException: " + e.getMessage());
}