Added a call to the following method in my unit test constructor:
Code:
protected void createNamingContext() {
SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
try {
TypeConverter converter = new SimpleTypeConverter();
XPath xpath = XPathFactory.newInstance().newXPath();
Document webxmlDom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new FileInputStream(WEB_XML_PATH));
NodeList enventries = (NodeList)xpath.evaluate("/web-app/env-entry", webxmlDom, XPathConstants.NODESET);
for (int n = 0; n < enventries.getLength(); n++) {
Node enventry = enventries.item(n);
String entryName = (String)xpath.evaluate("env-entry-name", enventry, XPathConstants.STRING);
String entryValue = (String)xpath.evaluate("env-entry-value", enventry, XPathConstants.STRING);
String entryType = (String)xpath.evaluate("env-entry-type", enventry, XPathConstants.STRING);
logger.debug("Loading " + entryName + " into the naming context");
Class type = Class.forName(entryType);
builder.bind("java:comp/env/" + entryName, converter.convertIfNecessary(entryValue, type));
}
builder.activate();
} catch (Exception e) {
logger.fatal(e.getMessage(), e);
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, AbstractSpringTestCase.class.getPackage().getName() + ".MockInitialContextFactory");
}
}
I'm still sure I've just re-invented the wheel, but ...
Cheers
Simon