You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2005/10/25 02:13:32 UTC
svn commit: r328193 -
/beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/xmlbeans/XMLHelper.java
Author: ekoneil
Date: Mon Oct 24 17:13:29 2005
New Revision: 328193
URL: http://svn.apache.org/viewcvs?rev=328193&view=rev
Log:
More cleanup in XMLHelper before moving off of XMLBeans.
BB: self
Test: NetUI pass
Modified:
beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/xmlbeans/XMLHelper.java
Modified: beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/xmlbeans/XMLHelper.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/xmlbeans/XMLHelper.java?rev=328193&r1=328192&r2=328193&view=diff
==============================================================================
--- beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/xmlbeans/XMLHelper.java (original)
+++ beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/xmlbeans/XMLHelper.java Mon Oct 24 17:13:29 2005
@@ -19,8 +19,6 @@
import java.util.List;
import java.util.ArrayList;
-import java.util.Set;
-import java.util.Iterator;
import java.util.LinkedList;
import java.io.File;
import java.io.IOException;
@@ -37,7 +35,6 @@
import org.apache.beehive.netui.tools.testrecorder.shared.config.*;
import org.apache.beehive.netui.tools.testrecorder.shared.*;
import org.apache.beehive.netui.tools.testrecorder.x2004.*;
-import org.apache.beehive.netui.tools.testrecorder.x2004.TestsType;
import org.apache.beehive.netui.tools.testrecorder.x2004.TestType;
import org.apache.beehive.netui.tools.testrecorder.x2004.diffsession.RecorderDiffDocument;
import org.apache.beehive.netui.tools.testrecorder.x2004.diffsession.TestDiffType;
@@ -138,12 +135,8 @@
if (LOGGER.isInfoEnabled()) {
LOGGER.info("file( " + file.getAbsolutePath() + " )");
}
+ String resourceIdentifier = file.getAbsolutePath();
InputStream is = new FileInputStream(file);
- return getRecordSessionBean(is, file.getAbsolutePath());
- }
-
- public static RecordSessionBean getRecordSessionBean(InputStream is, String resourceIdentifier)
- throws SessionXMLException, IOException {
RecorderSessionDocument doc = null;
try {
@@ -179,45 +172,63 @@
}
RecorderSessionDocument.RecorderSession xmlSession = doc.getRecorderSession();
RecordSessionBean bean = new RecordSessionBean(xmlSession.getSessionName());
- bean = getRecordSessionBean(bean, doc);
- return bean;
- }
-
- public static PlaybackSessionBean getPlaybackSessionBean(InputStream is, String resourceIdentifier)
- throws SessionXMLException, IOException {
- RecorderSessionDocument doc = null;
+ bean.setTester(xmlSession.getTester());
+ bean.setDescription(xmlSession.getDescription());
try {
- XmlOptions loadOptions = new XmlOptions();
- loadOptions.setLoadLineNumbers();
- doc = RecorderSessionDocument.Factory.parse(is, loadOptions);
- }
- catch (XmlException e) {
- LOGGER.fatal("test recorder parse exception", e);
- SessionXMLException ex = new SessionXMLException("ERROR: failed parsing test recorder playback session XML, file( " +
- resourceIdentifier + " )", e);
- LOGGER.fatal(ex);
- throw ex;
+ bean.setStartDate(xmlSession.getStartDate());
}
- finally {
- if (is != null) {
- try {
- is.close();
- }
- catch (IOException e) {
- LOGGER.error("ERROR: failed to close stream for file( " + resourceIdentifier + " )");
- }
- }
+ catch (ParseException e) {
+ String msg = "ERROR: failed parsing start date( " + xmlSession.getStartDate() + " )";
+ LOGGER.error(msg);
+ throw new SessionXMLException(msg, e);
}
-
- assert doc != null;
try {
- validate(doc, resourceIdentifier,
- "ERROR: test recorder playback session XML document is not valid against the schema");
+ bean.setEndDate(xmlSession.getEndDate());
}
- catch (ConfigException e) {
- throw new SessionXMLException(e.getMessage(), e);
+ catch (ParseException e) {
+ String msg = "ERROR: failed parsing end date( " + xmlSession.getEndDate() + " )";
+ LOGGER.error(msg);
+ throw new SessionXMLException(msg, e);
+ }
+ org.apache.beehive.netui.tools.testrecorder.x2004.session.TestsType tests = xmlSession.getTests();
+ org.apache.beehive.netui.tools.testrecorder.x2004.session.TestType[] testArray = tests.getTestArray();
+ org.apache.beehive.netui.tools.testrecorder.x2004.session.TestType testType = null;
+ RequestType requestType = null;
+ ResponseType responseType = null;
+ for (int i = 0; i < testArray.length; i++) {
+ testType = testArray[i];
+ requestType = testType.getRequest();
+ RequestData request = new RequestData();
+ request.setProtocol(requestType.getProtocol().toString());
+ request.setProtocolVersion(requestType.getProtocolVersion());
+ request.setHost(requestType.getHost());
+ request.setPort(requestType.getPort());
+ request.setPath(requestType.getUri());
+ request.setMethod(requestType.getMethod().toString());
+ request.setParameters(getNVPairs(requestType.getParameters().getParameterArray()));
+ request.setHeaders(getNVPairs(requestType.getHeaders().getHeaderArray()));
+
+ NameValueType[] nvArray = requestType.getCookies().getCookieArray();
+ Cookie[] cookies = new Cookie[nvArray.length];
+ Cookie cookie = null;
+ NameValueType nv = null;
+ for (int k = 0; k < nvArray.length; k++) {
+ nv = nvArray[k];
+ cookie = new Cookie(nv.getName(), nv.getValue());
+ cookies[k] = cookie;
+ }
+
+ request.setCookies(cookies);
+
+ responseType = testType.getResponse();
+
+ ResponseData response = new ResponseData(request.getHost(), request.getPort());
+ response.setStatusCode(responseType.getStatusCode());
+ response.setReason(responseType.getReason());
+ response.setBody(responseType.getResponseBody());
+
+ bean.addRequestResponseData(request, response);
}
- PlaybackSessionBean bean = getPlaybackSessionBean(doc);
return bean;
}
@@ -225,12 +236,8 @@
if (LOGGER.isInfoEnabled()) {
LOGGER.info("file( " + file.getAbsolutePath() + " )");
}
+ String resourceIdentifier = file.getAbsolutePath();
InputStream is = new FileInputStream(file);
- return getDiffResults(is, file.getAbsolutePath());
- }
-
- public static List getDiffResults(InputStream is, String resourceIdentifier)
- throws SessionXMLException, IOException {
RecorderDiffDocument doc = null;
try {
XmlOptions loadOptions = new XmlOptions();
@@ -245,14 +252,8 @@
throw ex;
}
finally {
- if (is != null) {
- try {
- is.close();
- }
- catch (IOException e) {
- LOGGER.error("ERROR: failed to close stream for file( " + resourceIdentifier + " )");
- }
- }
+ if (is != null)
+ is.close();
}
assert doc != null;
@@ -263,7 +264,18 @@
catch (ConfigException e) {
throw new SessionXMLException(e.getMessage(), e);
}
- List list = getDiffResults(doc);
+
+ RecorderDiffDocument.RecorderDiff diff = doc.getRecorderDiff();
+ List list = new ArrayList(diff.sizeOfRequestArray());
+ TestDiffType diffType = null;
+ TestResults results = null;
+ for (int i = 0; i < diff.sizeOfRequestArray(); i++) {
+ diffType = diff.getRequestArray(i);
+ results = new TestResults(diffType.getTestNumber(), diffType.getUri(), false, false);
+ results.addDiffResult(diffType.getDiffResults());
+ list.add(results);
+ }
+
return list;
}
@@ -279,7 +291,22 @@
XmlOptions xmlOptions = new XmlOptions();
xmlOptions.setSavePrettyPrint();
xmlOptions.setSavePrettyPrintIndent(3);
- RecorderSessionDocument doc = createPlaybackSessionDocument(bean, xmlOptions);
+ RecorderSessionDocument doc = createRecorderSessionDocument(bean, xmlOptions);
+ RecorderSessionDocument.RecorderSession session = doc.getRecorderSession();
+ int count = doc.getRecorderSession().getTests().sizeOfTestArray();
+ org.apache.beehive.netui.tools.testrecorder.x2004.session.TestsType tests =
+ doc.getRecorderSession().getTests();
+ org.apache.beehive.netui.tools.testrecorder.x2004.session.TestType test = null;
+ for (int i = 0; i < count; i++) {
+ test = tests.getTestArray(i);
+ TestResultsType testResultsType = test.addNewTestResults();
+ TestResults testResults = bean.getTestResults(i);
+ testResultsType.setTestStatus(StatusType.Enum.forString(testResults.getStatus().toLowerCase()));
+ }
+ session.setSessionStatus(StatusType.Enum.forString(bean.getStatus().toLowerCase()));
+ session.setPassedCount(bean.getPassedCount());
+ session.setFailedCount(bean.getFailedCount());
+ session.setTestCount(bean.getTestCount());
doc.save(playbackFile, xmlOptions);
}
@@ -287,12 +314,7 @@
XmlOptions xmlOptions = new XmlOptions();
xmlOptions.setSavePrettyPrint();
xmlOptions.setSavePrettyPrintIndent(3);
- RecorderDiffDocument doc = createDiffSessionDocument(bean, xmlOptions);
- doc.save(diffFile, xmlOptions);
- }
-
- private static RecorderDiffDocument createDiffSessionDocument(PlaybackSessionBean bean, XmlOptions options) {
- RecorderDiffDocument doc = RecorderDiffDocument.Factory.newInstance(options);
+ RecorderDiffDocument doc = RecorderDiffDocument.Factory.newInstance(xmlOptions);
RecorderDiffDocument.RecorderDiff diff = doc.addNewRecorderDiff();
TestResults results = null;
RequestData request = null;
@@ -301,23 +323,23 @@
if (results.isTestPassed()) {
continue;
}
+
// failure, persist diff data
+ List list = results.getDiffResults();
+ StringBuffer sb = new StringBuffer(64 * list.size());
+ sb.append("\n");
+ for (int j = 0; j < list.size(); j++) {
+ sb.append(list.get(j) + "\n");
+ }
+ String diffString = sb.toString();
+
request = bean.getRequestData(i);
- populateTestDiffType(diff.addNewRequest(), results, request);
+ TestDiffType diffType = diff.addNewRequest();
+ diffType.setTestNumber(results.getTestNumber());
+ diffType.setUri(request.getPath());
+ diffType.setDiffResults(diffString);
}
- return doc;
- }
-
- private static RecorderSessionDocument createPlaybackSessionDocument(PlaybackSessionBean bean,
- XmlOptions options) {
- RecorderSessionDocument doc = createRecorderSessionDocument(bean, options);
- RecorderSessionDocument.RecorderSession session = doc.getRecorderSession();
- addTestResults(doc, bean);
- session.setSessionStatus(StatusType.Enum.forString(bean.getStatus().toLowerCase()));
- session.setPassedCount(bean.getPassedCount());
- session.setFailedCount(bean.getFailedCount());
- session.setTestCount(bean.getTestCount());
- return doc;
+ doc.save(diffFile, xmlOptions);
}
private static RecorderSessionDocument createRecorderSessionDocument(RecordSessionBean bean,
@@ -325,9 +347,55 @@
RecorderSessionDocument doc = createRecorderSessionDocument((SessionBean) bean, options);
RecorderSessionDocument.RecorderSession session = doc.getRecorderSession();
session.setTestCount(bean.getTestCount());
- // TODO add for record
- // session.setSessionStatus( );
- addTests(doc, bean);
+ /* todo: add for record */
+ org.apache.beehive.netui.tools.testrecorder.x2004.session.TestsType tests =
+ doc.getRecorderSession().addNewTests();
+ org.apache.beehive.netui.tools.testrecorder.x2004.session.TestType test = null;
+ for (int i = 0; i < bean.getTestCount(); i++) {
+ test = tests.addNewTest();
+ test.setTestNumber(i + 1);
+ RequestType requestType = test.addNewRequest();
+ RequestData data = bean.getRequestData(i);
+ requestType.setProtocol(ProtocolType.Enum.forString(data.getProtocol()));
+ requestType.setProtocolVersion(data.getProtocolVersion());
+ requestType.setHost(data.getHost());
+ requestType.setPort(data.getPort());
+ requestType.setUri(data.getPath());
+ requestType.setMethod(MethodType.Enum.forString(data.getMethod()));
+
+ ParametersType paramsType = requestType.addNewParameters();
+ NameValueType param = null;
+ for (int k = 0; k < data.getParamCount(); k++) {
+ param = paramsType.addNewParameter();
+ param.setName(data.getParamName(k));
+ param.setValue(data.getParamValue(k));
+ }
+ {
+ CookiesType cookies = requestType.addNewCookies();
+ NameValueType cookie = null;
+ for (int m = 0; m < data.getCookieCount(); m++) {
+ cookie = cookies.addNewCookie();
+ cookie.setName(data.getCookieName(m));
+ cookie.setValue(data.getCookieValue(m));
+ }
+ }
+ {
+ HeadersType headersType = requestType.addNewHeaders();
+ NameValueType header = null;
+ for (int n = 0; n < data.getHeaderCount(); n++) {
+ header = headersType.addNewHeader();
+ header.setName(data.getHeaderName(n));
+ header.setValue(data.getHeaderValue(n));
+ }
+ }
+
+ ResponseType responseType = test.addNewResponse();
+ ResponseData responseData = bean.getResponseData(i);
+ responseType.setStatusCode(responseData.getStatusCode());
+ responseType.setReason(responseData.getReason());
+ responseType.setResponseBody(responseData.getBody());
+
+ }
return doc;
}
@@ -342,220 +410,6 @@
return doc;
}
- private static void addTests(RecorderSessionDocument doc, RecordSessionBean bean) {
- org.apache.beehive.netui.tools.testrecorder.x2004.session.TestsType tests = doc.getRecorderSession()
- .addNewTests();
- org.apache.beehive.netui.tools.testrecorder.x2004.session.TestType test = null;
- for (int i = 0; i < bean.getTestCount(); i++) {
- test = tests.addNewTest();
- test.setTestNumber(i + 1);
- populateRequestType(test.addNewRequest(), bean.getRequestData(i));
- populateResponseType(test.addNewResponse(), bean.getResponseData(i));
- }
- }
-
- private static void addTestResults(RecorderSessionDocument doc, PlaybackSessionBean bean) {
- int count = doc.getRecorderSession().getTests().sizeOfTestArray();
- org.apache.beehive.netui.tools.testrecorder.x2004.session.TestsType tests = doc.getRecorderSession()
- .getTests();
- org.apache.beehive.netui.tools.testrecorder.x2004.session.TestType test = null;
- for (int i = 0; i < count; i++) {
- test = tests.getTestArray(i);
- populateTestResultsType(test.addNewTestResults(), bean.getTestResults(i));
- }
- return;
- }
-
- /**
- * @param requestType
- * @param data
- */
- private static RequestType populateRequestType(final RequestType requestType, final RequestData data) {
- requestType.setProtocol(ProtocolType.Enum.forString(data.getProtocol()));
- requestType.setProtocolVersion(data.getProtocolVersion());
- requestType.setHost(data.getHost());
- requestType.setPort(data.getPort());
- requestType.setUri(data.getPath());
- requestType.setMethod(MethodType.Enum.forString(data.getMethod()));
- populateParametersType(requestType.addNewParameters(), data);
- populateCookiesType(requestType.addNewCookies(), data);
- populateHeadersType(requestType.addNewHeaders(), data);
- return requestType;
- }
-
- private static ResponseType populateResponseType(final ResponseType responseType, final ResponseData data) {
- responseType.setStatusCode(data.getStatusCode());
- responseType.setReason(data.getReason());
- responseType.setResponseBody(data.getBody());
- return responseType;
- }
-
- private static TestResultsType populateTestResultsType(final TestResultsType testResultsType,
- final TestResults data) {
- testResultsType.setTestStatus(StatusType.Enum.forString(data.getStatus().toLowerCase()));
- return testResultsType;
- }
-
- private static TestDiffType populateTestDiffType(final TestDiffType diffType,
- final TestResults results, final RequestData request) {
- diffType.setTestNumber(results.getTestNumber());
- diffType.setUri(request.getPath());
- diffType.setDiffResults(getDiffString(results));
- return diffType;
- }
-
- private static String getDiffString(TestResults results) {
- List list = results.getDiffResults();
- StringBuffer sb = new StringBuffer(64 * list.size());
- sb.append("\n");
- for (int i = 0; i < list.size(); i++) {
- sb.append((String) list.get(i) + "\n");
- }
- return sb.toString();
- }
-
- private static ParametersType populateParametersType(final ParametersType paramsType, final RequestData data) {
- NameValueType param = null;
- for (int i = 0; i < data.getParamCount(); i++) {
- param = paramsType.addNewParameter();
- param.setName(data.getParamName(i));
- param.setValue(data.getParamValue(i));
- }
- return paramsType;
- }
-
- private static CookiesType populateCookiesType(final CookiesType cookies, final RequestData data) {
- NameValueType cookie = null;
- for (int i = 0; i < data.getCookieCount(); i++) {
- cookie = cookies.addNewCookie();
- cookie.setName(data.getCookieName(i));
- cookie.setValue(data.getCookieValue(i));
- }
- return cookies;
- }
-
- private static HeadersType populateHeadersType(final HeadersType headersType, final RequestData data) {
- NameValueType header = null;
- for (int i = 0; i < data.getHeaderCount(); i++) {
- header = headersType.addNewHeader();
- header.setName(data.getHeaderName(i));
- header.setValue(data.getHeaderValue(i));
- }
- return headersType;
- }
-
- /**
- * returns a List of TestResults objects.
- *
- * @param document
- * @return
- * @throws SessionXMLException
- */
- private static List getDiffResults(RecorderDiffDocument document) throws SessionXMLException {
- RecorderDiffDocument.RecorderDiff diff = document.getRecorderDiff();
- List list = new ArrayList(diff.sizeOfRequestArray());
- TestDiffType diffType = null;
- TestResults results = null;
- for (int i = 0; i < diff.sizeOfRequestArray(); i++) {
- diffType = diff.getRequestArray(i);
- results = new TestResults(diffType.getTestNumber(), diffType.getUri(), false, false);
- results.addDiffResult(diffType.getDiffResults());
- list.add(results);
- }
- return list;
- }
-
- private static PlaybackSessionBean getPlaybackSessionBean(RecorderSessionDocument document)
- throws SessionXMLException {
- RecorderSessionDocument.RecorderSession xmlSession = document.getRecorderSession();
- boolean error = true;
- String status = null;
- status = xmlSession.getSessionStatus().toString();
- if (Constants.ERROR.equals(status)) {
- error = true;
- }
- PlaybackSessionBean bean = new PlaybackSessionBean(xmlSession.getSessionName(), error);
- bean = (PlaybackSessionBean) getRecordSessionBean(bean, document);
- org.apache.beehive.netui.tools.testrecorder.x2004.session.TestsType tests = xmlSession.getTests();
- org.apache.beehive.netui.tools.testrecorder.x2004.session.TestType testType = null;
- boolean passed = false;
- for (int i = 0; i < tests.sizeOfTestArray(); i++) {
- testType = tests.getTestArray(i);
- status = testType.getTestResults().getTestStatus().toString();
- if (Constants.ERROR.equals(status)) {
- error = true;
- passed = false;
- }
- else if (Constants.PASS.equals(status)) {
- error = false;
- passed = true;
- }
- else {
- error = false;
- passed = false;
- }
- bean.addTestResults(
- new TestResults(testType.getTestNumber(), testType.getRequest().getUri(), error, passed));
- }
- // TODO add recorded count to XML populate bean with data.
- bean.setRecordedTestCount(xmlSession.getTestCount());
- return bean;
- }
-
- // doc -> object
- private static RecordSessionBean getRecordSessionBean(RecordSessionBean bean,
- RecorderSessionDocument document) throws SessionXMLException {
- RecorderSessionDocument.RecorderSession xmlSession = document.getRecorderSession();
- bean.setTester(xmlSession.getTester());
- bean.setDescription(xmlSession.getDescription());
- try {
- bean.setStartDate(xmlSession.getStartDate());
- }
- catch (ParseException e) {
- String msg = "ERROR: failed parsing start date( " + xmlSession.getStartDate() + " )";
- LOGGER.error(msg);
- throw new SessionXMLException(msg, e);
- }
- try {
- bean.setEndDate(xmlSession.getEndDate());
- }
- catch (ParseException e) {
- String msg = "ERROR: failed parsing end date( " + xmlSession.getEndDate() + " )";
- LOGGER.error(msg);
- throw new SessionXMLException(msg, e);
- }
- org.apache.beehive.netui.tools.testrecorder.x2004.session.TestsType tests = xmlSession.getTests();
- org.apache.beehive.netui.tools.testrecorder.x2004.session.TestType[] testArray = tests.getTestArray();
- org.apache.beehive.netui.tools.testrecorder.x2004.session.TestType testType = null;
- RequestType requestType = null;
- ResponseType responseType = null;
- RequestData request = null;
- ResponseData response = null;
- for (int i = 0; i < testArray.length; i++) {
- testType = testArray[i];
- requestType = testType.getRequest();
- request = getRequestData(requestType);
- responseType = testType.getResponse();
- response = getResponseData(responseType, request);
- bean.addRequestResponseData(request, response);
- }
- return bean;
- }
-
- private static RequestData getRequestData(RequestType requestType) {
- RequestData request = new RequestData();
- request.setProtocol(requestType.getProtocol().toString());
- request.setProtocolVersion(requestType.getProtocolVersion());
- request.setHost(requestType.getHost());
- request.setPort(requestType.getPort());
- request.setPath(requestType.getUri());
- request.setMethod(requestType.getMethod().toString());
- request.setParameters(getNVPairs(requestType.getParameters().getParameterArray()));
- request.setHeaders(getNVPairs(requestType.getHeaders().getHeaderArray()));
- request.setCookies(getCookies(requestType.getCookies().getCookieArray()));
- return request;
- }
-
private static NVPair[] getNVPairs(NameValueType[] nvArray) {
NVPair[] pairs = new NVPair[nvArray.length];
NVPair pair = null;
@@ -568,84 +422,6 @@
return pairs;
}
- /* todo: change to Http client cookies? */
- private static Cookie[] getCookies(NameValueType[] nvArray) {
- Cookie[] cookies = new Cookie[nvArray.length];
- Cookie cookie = null;
- NameValueType nv = null;
- for (int i = 0; i < nvArray.length; i++) {
- nv = nvArray[i];
- cookie = new Cookie(nv.getName(), nv.getValue());
- cookies[i] = cookie;
- }
- return cookies;
- }
-
- private static ResponseData getResponseData(ResponseType responseType, RequestData request) {
- ResponseData response = new ResponseData(request.getHost(), request.getPort());
- response.setStatusCode(responseType.getStatusCode());
- response.setReason(responseType.getReason());
- response.setBody(responseType.getResponseBody());
- return response;
- }
-
- public static TestDefinitionsDocument createTestDefDocument(Set tests, Set categories) {
- TestDefinitionsDocument doc = TestDefinitionsDocument.Factory.newInstance();
- org.apache.beehive.netui.tools.testrecorder.x2004.TestDefinitionsDocument.TestDefinitions defs =
- doc.addNewTestDefinitions();
- CategoriesType catsType = defs.addNewCategories();
- Category category = null;
- CategoryType catType = null;
- for (Iterator it = categories.iterator(); it.hasNext();) {
- category = (Category) it.next();
- catType = catsType.addNewCategory();
- populateCategory(catType, category);
- }
- TestsType testsType = defs.addNewTests();
- TestDefinition testDef = null;
- TestType testType = null;
- for (Iterator it = tests.iterator(); it.hasNext();) {
- testDef = (TestDefinition) it.next();
- testType = testsType.addNewTest();
- populateTest(testType, testDef);
- }
- return doc;
- }
-
- private static CategoryType populateCategory(CategoryType type, Category category) {
- type.setName(category.getName());
- type.setDescription(category.getDescription());
- return type;
- }
-
- private static TestType populateTest(TestType type, TestDefinition def) {
- type.setName(def.getName());
- type.setDescription(def.getDescription());
- type.setWebapp(def.getWebapp().getName());
- if (def.getCategories().size() > 0) {
- TestCategoriesType catType = type.addNewCategories();
- populateTestCategories(catType, def);
- type.setCategories(catType);
- }
- else {
- if (LOGGER.isWarnEnabled()) {
- LOGGER.warn("WARNING: no categories for test( " + def.getName() + " ), size( " +
- def.getCategories().size() +
- " )");
- }
- }
- return type;
- }
-
- private static TestCategoriesType populateTestCategories(TestCategoriesType type, TestDefinition def) {
- List categories = def.getCategories();
- for (int i = 0; i < categories.size(); i++) {
- Category category = (Category) categories.get(i);
- type.addCategory(category.getName());
- }
- return type;
- }
-
public static TestDefinitions getTestDefinitionsInstance(ClassLoader loader) {
InputStream is = loader.getResourceAsStream(Constants.CONFIG_FILE);
if (is == null) {
@@ -692,8 +468,8 @@
}
TestDefinitions testDefinitions = null;
try {
- testDefinitions = XMLHelper.getTestDefinitionsInstance(is, Constants.TESTS_FILE, webapps,
- config.getBaseDirectory().getAbsolutePath());
+ testDefinitions = getTestDefinitionsInstance(is, Constants.TESTS_FILE, webapps,
+ config.getBaseDirectory().getAbsolutePath());
}
catch (ConfigException e) {
throw new RuntimeConfigException(e.getMessage(), e);
@@ -711,7 +487,6 @@
public static Config getConfig(final InputStream xmlInputStream, final String xmlResourcePath) {
- //System.out.println("===== TestRecorder::getConfig -- " + xmlResourcePath);
Document document = null;
final String xsdResourcePath = Constants.SCHEMA_LOCATION + "/" + Constants.CONFIG_SCHEMA_NAME;
InputStream xsdInputStream = XMLHelper.class.getClassLoader().getResourceAsStream(xsdResourcePath);
@@ -799,15 +574,37 @@
ServerDocument.Server serverXML = doc.getServer();
ServerConfig server = new ServerConfig(serverXML.getName(), serverXML.getHostname(), serverXML.getPort());
- List webappList = new ArrayList();
- webappList = getWebappList(serverXML.getWebapps().getWebappArray(), webappList, server, config);
- return new Webapps(webappList);
- }
- public static TestDefinitions getTestDefinitionsInstance(File file, Webapps webapps, String baseDirPath)
- throws ConfigException, IOException {
- InputStream is = new FileInputStream(file);
- return getTestDefinitionsInstance(is, file.getAbsolutePath(), webapps, baseDirPath);
+ Config defaultConfig = config;
+ WebappType[] webappTypes = serverXML.getWebapps().getWebappArray();
+ ArrayList webappList = new ArrayList();
+ for (int i = 0; i < webappTypes.length; i++) {
+ WebappType webappType = webappTypes[i];
+
+ Config webappConfig = null;
+ if (webappType.getOverrideDefaultConfig() == null)
+ webappConfig = defaultConfig;
+ else {
+ String[] suffixes = null;
+ String servletURI = null;
+ if (webappType.getOverrideDefaultConfig().getSuffixList() != null) {
+ suffixes = webappType.getOverrideDefaultConfig().getSuffixList().getSuffixArray();
+ servletURI = webappType.getOverrideDefaultConfig().getServletURI();
+ }
+ webappConfig = new Config(suffixes, servletURI, defaultConfig.getBaseDirectory().getAbsolutePath());
+ }
+
+ WebappConfig webapp = new WebappConfig(webappType.getName().trim(),
+ webappType.getDescription().trim(),
+ server,
+ webappType.getTestMode(),
+ webappType.getContextRoot().trim(),
+ webappType.getTestDefinitionsDirectory().trim(),
+ webappConfig);
+ webappList.add(webapp);
+ }
+
+ return new Webapps(webappList);
}
public static TestDefinitions getTestDefinitionsInstance(InputStream is, String resourceIdentifier,
@@ -836,66 +633,8 @@
// may throw ConfigException
validate(doc, resourceIdentifier,
"ERROR: test recorder test definitions document is not valid against the schema");
- return getTestDefinitionsInstance(doc, webapps, baseDirPath);
- }
-
- private static TestDefinitions getTestDefinitionsInstance(TestDefinitionsDocument document, Webapps webapps,
- String baseDirPath) throws ConfigException {
- CategoryType[] categoryTypes = document.getTestDefinitions().getCategories().getCategoryArray();
- Categories categories = getCategoriesInstance(categoryTypes, baseDirPath);
- TestType[] testTypes = document.getTestDefinitions().getTests().getTestArray();
- TestDefinitions tests = getTestDefinitionsInstance(testTypes, categories, webapps);
- return tests;
- }
-
-
- private static List getWebappList(WebappType[] webappTypes,
- List webappList,
- ServerConfig server,
- Config defaultConfig) {
- WebappType webappType = null;
- WebappConfig webapp = null;
- for (int i = 0; i < webappTypes.length; i++) {
- webappType = webappTypes[i];
- webapp = getWebapp(webappType, server, defaultConfig);
- webappList.add(webapp);
- }
- return webappList;
- }
-
- private static WebappConfig getWebapp(WebappType webappType,
- ServerConfig server,
- Config defaultConfig) {
- Config config = getConfig(webappType, defaultConfig);
- if (config == null) {
- config = defaultConfig;
- }
- WebappConfig webapp = new WebappConfig(webappType.getName().trim(),
- webappType.getDescription().trim(),
- server,
- webappType.getTestMode(),
- webappType.getContextRoot().trim(),
- webappType.getTestDefinitionsDirectory().trim(),
- config);
- return webapp;
- }
-
- private static Config getConfig(WebappType webappType, Config defaultConfig) {
- // values not specified do not override default config so return null
- if (webappType.getOverrideDefaultConfig() == null)
- return null;
-
- String[] suffixes = null;
- String servletURI = null;
- if (webappType.getOverrideDefaultConfig().getSuffixList() != null) {
- suffixes = webappType.getOverrideDefaultConfig().getSuffixList().getSuffixArray();
- servletURI = webappType.getOverrideDefaultConfig().getServletURI();
- }
- return new Config(suffixes, servletURI, defaultConfig.getBaseDirectory().getAbsolutePath());
- }
-
- private static Categories getCategoriesInstance(CategoryType[] categoryTypes, String baseDirPath)
- throws ConfigException {
+ CategoryType[] categoryTypes = doc.getTestDefinitions().getCategories().getCategoryArray();
+ //Categories categories = getCategoriesInstance(categoryTypes, baseDirPath);
List list = new ArrayList();
Category category = null;
CategoryType type = null;
@@ -905,7 +644,9 @@
list.add(category);
}
Categories categories = new Categories((Category[]) list.toArray(new Category[list.size()]));
- return (categories);
+
+ TestType[] testTypes = doc.getTestDefinitions().getTests().getTestArray();
+ return getTestDefinitionsInstance(testTypes, categories, webapps);
}
private static TestDefinitions getTestDefinitionsInstance(TestType[] testTypes,
@@ -915,18 +656,29 @@
List list = new ArrayList();
TestDefinition testDef = null;
TestType type = null;
- String[] testCategoryStrings = null;
- List testCategories = null;
WebappConfig webapp = null;
for (int i = 0; i < testTypes.length; i++) {
type = testTypes[i];
+
+ LinkedList testCategories = new LinkedList();
if (type.getCategories() != null) {
- testCategoryStrings = type.getCategories().getCategoryArray();
- testCategories = getCategories(testCategoryStrings, categories);
- }
- else {
- testCategories = new ArrayList();
+ String[] testCategoryStrings = type.getCategories().getCategoryArray();
+
+ String name = null;
+ Category category = null;
+ for (int k = 0; k < testCategoryStrings.length; k++) {
+ name = testCategoryStrings[k];
+ category = categories.getCategory(name);
+ if (category == null) {
+ ConfigException ce = new ConfigException("ERROR: unable to determine test recorder category for name( " + name + " )");
+ LOGGER.fatal(ce);
+ throw ce;
+ }
+ testCategories.add(category);
+ }
}
+ else testCategories = new LinkedList();
+
webapp = webapps.getWebapp(type.getWebapp());
if (webapp == null) {
ConfigException ce = new ConfigException("ERROR: unable to find test recorder webapp with name( " +
@@ -935,33 +687,11 @@
LOGGER.fatal(ce);
throw ce;
}
- testDef =
- new TestDefinition(type.getName().trim(), type.getDescription().trim(), webapp,
- testCategories);
+ testDef = new TestDefinition(type.getName().trim(), type.getDescription().trim(), webapp, testCategories);
categories.addTest(testDef);
list.add(testDef);
}
- TestDefinitions defs = new TestDefinitions(list, categories, webapps);
- return (defs);
- }
-
- private static List getCategories(String[] names, Categories categories)
- throws ConfigException {
- List list = new ArrayList();
- String name = null;
- Category category = null;
- for (int i = 0; i < names.length; i++) {
- name = names[i];
- category = categories.getCategory(name);
- if (category == null) {
- ConfigException ce = new ConfigException(
- "ERROR: unable to determine test recorder category for name( " + name + " )");
- LOGGER.fatal(ce);
- throw ce;
- }
- list.add(category);
- }
- return list;
+ return new TestDefinitions(list, categories, webapps);
}
private static void validate(XmlObject doc, String resourceIdentifier, String errorMsg)