protected static void validateReturnedOutOfBandHeader(Map<String, Object> responseContext) {
validateReturnedOutOfBandHeader(responseContext, true);
}
protected static void validateReturnedOutOfBandHeader(Map<String, Object> responseContext, boolean expect) {
OutofBandHeader hdrToTest = null;
List oobHdr = (List)responseContext.get(Header.HEADER_LIST);
if (!expect) {
if (oobHdr == null || (oobHdr != null && oobHdr.size() == 0)) {
return;
}
fail("Should have got *no* out-of-band headers, but some were found");
}
if (oobHdr == null) {
fail("Should have got List of out-of-band headers");
}
assertTrue("HeaderHolder list expected to conain 1 object received " + oobHdr.size(),
oobHdr.size() == 1);
if (oobHdr != null & oobHdr instanceof List) {
Iterator iter = oobHdr.iterator();
while (iter.hasNext()) {
Object hdr = iter.next();
if (hdr instanceof Header) {
Header hdr1 = (Header)hdr;
if (hdr1.getObject() instanceof Node) {
try {
JAXBElement job = (JAXBElement)JAXBContext
.newInstance(org.apache.cxf.outofband.header.ObjectFactory.class)
.createUnmarshaller().unmarshal((Node)hdr1.getObject());
hdrToTest = (OutofBandHeader)job.getValue();
} catch (JAXBException ex) {
ex.printStackTrace();
}
}
}
}
}
assertNotNull("out-of-band header should not be null", hdrToTest);
assertTrue("Expected out-of-band Header name testOobReturnHeaderName recevied :"
+ hdrToTest.getName(), "testOobReturnHeaderName".equals(hdrToTest.getName()));
assertTrue("Expected out-of-band Header value testOobReturnHeaderValue recevied :"
+ hdrToTest.getValue(), "testOobReturnHeaderValue".equals(hdrToTest.getValue()));
assertTrue("Expected out-of-band Header attribute testReturnHdrAttribute recevied :"
+ hdrToTest.getHdrAttribute(), "testReturnHdrAttribute"
.equals(hdrToTest.getHdrAttribute()));
}