private QName getResponseBodyElementName(RestMessageExchange messageExchange) { try { XmlObject xmlObject = XmlObject.Factory.parse(messageExchange.getResponseContentAsXml()); Element docElement = ((Document) xmlObject.getDomNode()).getDocumentElement(); return new QName(docElement.getNamespaceURI(), docElement.getLocalName()); } catch (XmlException e) { SoapUI.logError(e); } return null; }
private AssertionError[] assertResponse( RestMessageExchange messageExchange, RestRepresentation.Type type) { List<AssertionError> result = new ArrayList<AssertionError>(); QName responseBodyElementName = getResponseBodyElementName(messageExchange); RestRequestInterface restRequest = messageExchange.getRestRequest(); boolean asserted = false; for (RestRepresentation representation : restRequest.getRepresentations(type, messageExchange.getResponseContentType())) { if (representation.getStatus().isEmpty() || representation.getStatus().contains(messageExchange.getResponseStatusCode())) { SchemaType schemaType = representation.getSchemaType(); if (schemaType != null && representation.getElement().equals(responseBodyElementName)) { try { XmlObject xmlObject = schemaType .getTypeSystem() .parse(messageExchange.getResponseContentAsXml(), schemaType, new XmlOptions()); // create internal error list List<?> list = new ArrayList<Object>(); XmlOptions xmlOptions = new XmlOptions(); xmlOptions.setErrorListener(list); xmlOptions.setValidateTreatLaxAsSkip(); xmlObject.validate(xmlOptions); for (Object o : list) { if (o instanceof XmlError) result.add(new AssertionError((XmlError) o)); else result.add(new AssertionError(o.toString())); } asserted = true; } catch (XmlException e) { SoapUI.logError(e); } } else { asserted = true; } } } if (!asserted && result.isEmpty()) { result.add( new AssertionError( "Missing matching representation for request with contentType [" + messageExchange.getResponseContentType() + "]")); } return result.toArray(new AssertionError[result.size()]); }