* @param action the active test action
* @throws Exception if a processing exception occurs
*/
public void testAction(CfgAction action) throws Exception {
RequestContext rc = null;
RequestHandler handler = null;
boolean succeeded = false;
try {
// make the HTTP servlet request
String actionName = action.nodeName;
String queryString = null;
if (action.nodeName.equalsIgnoreCase("url")) {
queryString = Val.chkStr(action.nodeText);
}
HttpServletRequestFacade httpRequest = new HttpServletRequestFacade(queryString);
// set up an administrative publisher
if (this.admin == null) {
RequestContext rc2 = null;
try {
rc2 = RequestContext.extract(null);
this.admin = Publisher.makeSystemAdministrator(rc2);
} finally {
if (rc2 != null) rc2.onExecutionPhaseCompleted();
}
}
httpRequest.getSession().setAttribute("com.esri.gpt.user",admin);
// make the CSW request handler
rc = RequestContext.extract(httpRequest);
handler = ProviderFactory.newHandler(rc);
RequestOptions rOptions = handler.getOperationContext().getRequestOptions();
rOptions.getTransactionOptions().setAutoApprove(true);
// execute the testable action
if (action.nodeName.equalsIgnoreCase("url")) {
handler.handleGet(httpRequest);
} else if (actionName.equalsIgnoreCase("xml")) {
handler.handleXML(Val.chkStr(action.nodeText));
} else if (actionName.equalsIgnoreCase("file")) {
handler.handleXML(XmlIoUtil.readXml(action.dataFile.getCanonicalPath()));
} else {
throw new Exception(action.makeMessagePrefix()+" The action is invalid: "+actionName);
}
if (this.verbose) {
System.err.println(handler.getOperationContext().getOperationResponse().getResponseXml());
}
// assert that the action should have passed
succeeded = true;
action.onSucceeded();
// OWS exceptions
} catch (OwsException ows) {
if (this.verbose) {
System.err.println(ows.getReport());
}
action.onFailed(ows,false);
// assert the owsLocator and owsCode if set
NamedNodeMap nnmItemAttributes = action.item.node.getAttributes();
String owsCode = Val.chkStr(DomUtil.getAttributeValue(nnmItemAttributes,"owsCode"));
String owsLocator = Val.chkStr(DomUtil.getAttributeValue(nnmItemAttributes,"owsLocator"));
if (owsLocator.startsWith("@")) {
owsLocator = Val.chkStr(owsLocator.substring(1));
}
if (owsLocator.length() > 0) {
String msg = action.makeMessagePrefix()+" The OwsException locator is incorrect.";
org.junit.Assert.assertEquals(msg,owsLocator,ows.getLocator());
}
if (owsCode.length() > 0) {
String msg = action.makeMessagePrefix()+" The OwsException code is incorrect.";
org.junit.Assert.assertEquals(msg,owsCode,ows.getCode());
}
// other exceptions
} catch (Exception e) {
action.onFailed(e,true);
} finally {
if (rc != null) rc.onExecutionPhaseCompleted();
}
// handle remaining assertions
CfgAssertion[] assertions = action.item.assertions;
if (succeeded && (assertions != null) && (assertions.length > 0)) {
CfgAssertionHelper helper = new CfgAssertionHelper();
OperationContext ctx = handler.getOperationContext();
String resultXml = ctx.getOperationResponse().getResponseXml();
if (this.xpath == null) {
CswNamespaces ns = new CswNamespaces();
this.xpath = XPathFactory.newInstance().newXPath();
this.xpath.setNamespaceContext(ns.makeNamespaceContext());