/**
* This method loads and processes the xml configuration file of this
* test case.
*
* @return void
*/
public void load()
{
log.info("Loading test case from project [" +
xmlpp.getInfoProject().getProjectName() + "]");
BufferedReader in = null;
try
{
in = new BufferedReader(new FileReader(tcConfigFile));
}
catch (FileNotFoundException e)
{
log.warning("File [" + tcConfigFile.toString() +
"] not found...");
FailureMessage.printFailureMessage(MainClass.getController(),
"File [" + tcConfigFile.toString() + "] not found...");
}
XMLInputFactory factory = XMLInputFactory.newInstance();
try
{
XMLStreamReader parser = factory.createXMLStreamReader(in);
while(true)
{
int event = parser.next();
/**
* End of the Document
*/
if(event == XMLStreamConstants.END_DOCUMENT)
{
parser.close();
break;
}
/**
* a new Elements starts
*/
if(event == XMLStreamConstants.START_ELEMENT)
{
log.finest("XMLStreamConstants.START_ELEMENT: " +
parser.getLocalName());
if(parser.getLocalName().equals("tc"))
{
for(int i=0; i<parser.getAttributeCount(); i++)
{
log.finest("Reading xml attribute: (" +
parser.getAttributeLocalName(i) + "=" +
parser.getAttributeValue(i) + ")");
if(parser.getAttributeLocalName(i).equals
("name"))
{
infoTestCase.setTCName(parser.
getAttributeValue(i));
tcFolder = parser.getAttributeValue(i);
}
else
{
log.config("Unsupported attribute (" +
parser.getAttributeLocalName(i) + "=" +
parser.getAttributeValue(i) + ")");
FailureMessage.printFailureMessage(
MainClass.getController(),
"Unsupported attribute (" +
parser.getAttributeLocalName(i) + "=" +
parser.getAttributeValue(i) + ")");
}
}
}
else if(parser.getLocalName().equals("redirection"))
{
for(int i=0; i<parser.getAttributeCount(); i++)
{
log.finest("Reading xml attribute: (" +
parser.getAttributeLocalName(i) + "=" +
parser.getAttributeValue(i) + ")");
if(parser.getAttributeLocalName(i).equals
("mode"))
{
if(parser.getAttributeValue(i).equals
("enabled"))
{
log.config("Redirection [enabled] for" +
" test case [" + infoTestCase.
getTCName() + "]");
infoTestCase.setTCRedirection(true);
}
else if(parser.getAttributeValue(i).equals
("disabled"))
{
log.config("Redirection [disabled] " +
"for test case [" + infoTestCase.
getTCName() + "]");
infoTestCase.setTCRedirection(false);
}
else
{
log.warning("Wrong redirection " +
"configuration [" + parser.
getAttributeLocalName(i) + "=" +
parser.getAttributeValue(i) + "]");
FailureMessage.printFailureMessage(
MainClass.getController(),
"Wrong redirection " +
"configuration [" + parser.
getAttributeLocalName(i) + "=" +
parser.getAttributeValue(i) + "]");
}
}
else
{
log.config("Unsupported attribute (" +
parser.getAttributeLocalName(i) + "=" +
parser.getAttributeValue(i) + ")");
FailureMessage.printFailureMessage(
MainClass.getController(),
"Unsupported attribute (" +
parser.getAttributeLocalName(i) + "=" +
parser.getAttributeValue(i) + ")");
}
}
}
/**
* Steps in this test case...
*/
if(RegexPatterns.findStepInTestCase(
parser.getLocalName()))
{
numSteps = new Integer(numSteps.intValue() + 1);
TCStep tcs = new TCStep();
tcs.setNumStep(numSteps.intValue());
infoTestCase.setTCName(tcFolder);
/**
* processes all attributes of the current step.
*/
for(int i=0; i<parser.getAttributeCount(); i++)
{
log.finest("Reading xml attribute: (" +
parser.getAttributeLocalName(i) + "=" +
parser.getAttributeValue(i) + ")");
/**
* Determines how many times the request should
* repeated.
*/
if(parser.getAttributeLocalName(i).equals
("num"))
{
log.config("Repeating request " +
parser.getAttributeValue(i) + " times");
numRequestRepeats = new Integer(
parser.getAttributeValue(i));
}
/**
* What should be done.
*/
else if(parser.getAttributeLocalName(i).equals
("action"))
{
tcs.setAction(parser.getAttributeValue(i));
if(parser.getAttributeValue(i).
equals("sendRequest"))
{
if(parser.getAttributeLocalName(i+1).
equals("file"))
{
tcs.setFile(parser.
getAttributeValue(i+1).
replace("%projectFolder%",
xmlpp.getProjectFolder()).
replace("%tc%", tcFolder));
/**
* Create message pair to process.
*/
tcs.setHmp
(
loadRequestFromFile(new File
(
parser.getAttributeValue(i+1).
replace
(
"%projectFolder%",
xmlpp.getProjectFolder()
).replace
(
"%tc%", tcFolder
)
)),
new Response(
MainClass.
getOutputModeResponse())
);
}
else
{
log.info("If you want to" +
" send a request, you must" +
" define the request file!");
FailureMessage.printFailureMessage
(controller, "If you want to" +
" send a request, you must" +
" define the request file!");
}
}
else
{
log.warning("Unknown action" +
" in test case step [" + i + "];" +
parser.getAttributeValue(i));
FailureMessage.printFailureMessage
(controller, "Unknown action" +
" in test case step [" + i + "];" +
parser.getAttributeValue(i));
}
}
else if(parser.getAttributeLocalName(i).
equals("file"))
{
/**
* Do nothing. This attribute is parsed
* above during sendRequest detection.
* This is only to prevent failure
* message.
*/
}
/**
* The expected status code of the response.
*/
else if(parser.getAttributeLocalName(i).equals
("expStatusCode"))
{
log.config("expStatusCode (" + tcFolder +
") = " + parser.getAttributeValue(i));
/**
* Set the expected status code of the
* received response.
*/
tcs.getErd().setResponseStatusCode(
new Integer(parser.
getAttributeValue(i)));
}
/**
* The expected header which the response should
* contain.
*/
else if(parser.getAttributeLocalName(i).equals
("expHeader"))
{
log.config("expHeader (" + tcFolder +
") = " + parser.getAttributeValue(i));
if(parser.getAttributeValue(i).contains
("|"))
{
/**
* The headers with values...
* [name]:[value]
*/
String[] splitHeader = parser.
getAttributeValue(i).split("[|]");
for(int h=0; h<splitHeader.length; h++)
{
String[] hpSplit = splitHeader[h].
split(":");
tcs.getErd().getHeaders().add(
new HeaderPair<String, String>(
// name , value
hpSplit[0], hpSplit[1])
);
}
}
else
{
String[] hpSplit = parser.
getAttributeValue(i).split(":");
tcs.getErd().getHeaders().add(
new HeaderPair<String, String>(
// name , value
hpSplit[0], hpSplit[1])
);
}
}
/**
* The expected string which the response data
* should contains (only usable if the response
* data is text data).
*/
else if(parser.getAttributeLocalName(i).equals
("expStringsData"))
{
log.config("expStringsData (" + tcFolder +
") = " + parser.getAttributeValue(i));
if(parser.getAttributeValue(i).contains
("|"))
{
/**
* The strings...
*/
String[] split = parser.
getAttributeValue(i).split("|");
for(int s=0; s<split.length; s++)
{
tcs.getErd().getDataString().add(
split[s]);
}
}
else
{
tcs.getErd().getDataString().add(parser.
getAttributeValue(i));
}
}
else
{
log.config("Unsupported attribute (" +
parser.getAttributeLocalName(i) + "=" +
parser.getAttributeValue(i) + ")");
FailureMessage.printFailureMessage(
MainClass.getController(),
"Unsupported attribute (" +
parser.getAttributeLocalName(i) + "=" +
parser.getAttributeValue(i) + ")");
}
}
/**
* adds the request num times to the
* message pair array. num is
* defined in stepX element in test
* case configuration file
*/
for(int num=0; num<numRequestRepeats;
num++)
{
/**
* The first request num.
*/
if(num == 0)
{
log.info("Adding request first time.");
/**
* because in step to compare or anything like
* this, the message pair IS null!!!
*/
if(tcs.getHmp() != null)
{
/**
* panel for this test case.
*/
tcs.setPip(true);
/**
* Sets the number of the message pair.
*/
tcs.getHmp().setNum(num);
/**
* Set the object with the expected response
* data to the http message pair.
*/
tcs.getHmp().setExpResponseData(
tcs.getErd());
/**
* Add the new message pair for the actual
* step to the <code>msgPairs</code> vector.
*/
msgPairs.add(tcs.getHmp());
/**
* One <code>ProcessInfoPanel</code> for each
* step.
*/
tcs.getPip().getJLabelName().setText(
"tc" + num);
GuiProgressPanel.getInstance().
addProcessInfoPanel(tcs.getPip());
tcs.getPip().setVisible(true);
/**
* Add test case step to vector.
*/
infoTestCase.getTCSteps().add(tcs);
}
}
/**
* Repeating the same request.
*/
else if(num > 0)
{
log.info("Adding request (repeat)");
TCStep tcStep = new TCStep();
/**
* because in step to compare or anything
* like this, the message pair IS null!!!
*/
if(tcs.getHmp() != null)
{
tcStep.setNumStep(tcs.getNumStep());
tcStep.setAction(tcs.getAction());
tcStep.setFile(tcs.getFile());
tcStep.setReapeating(num+1);
/**
* A new TCStep for each request
* repeating.
*/
tcStep.setHmp(tcs.getHmp().getRequest(),
tcs.getHmp().getResponse());
/**
* panel for this test case.
*/
tcStep.setPip(true);
/**
* Sets the number of the message pair.
*/
tcStep.getHmp().setNum(num);
/**
* Set the object with the expected
* response data to the http message
* pair.
*/
tcStep.getHmp().setExpResponseData(
tcs.getErd());
/**
* Add the new message pair for the actual
* step to the <code>msgPairs</code> vector.
*/
msgPairs.add(tcStep.getHmp());
/**
* One <code>ProcessInfoPanel</code> for each
* step.
*/
tcStep.getPip().getJLabelName().setText(
"tc" + num);
GuiProgressPanel.getInstance().
addProcessInfoPanel(tcStep.getPip());
tcStep.getPip().setVisible(true);
/**
* Add test case step to vector.
*/
infoTestCase.getTCSteps().add(tcStep);
}
}
}
}
}
/**
* A String, e.g. ISA Server between <proxy> </proxy> Tags
*/
if(event == XMLStreamConstants.CHARACTERS)
{}
}
log.info("Loading test case finished");
/**
* panel for compare progress.
*/
log.fine("");
GuiProgressPanel.getInstance().addComparePanel(
new CompareInfoPanel());
ProcessInfoPanel reportPanel = new ProcessInfoPanel(false);
reportPanel.getJLabelName().setText("report");
GuiProgressPanel.getInstance().addProcessInfoPanel(reportPanel);
}
catch (XMLStreamException e)
{
log.warning("XMLStreamException in XMLTestCaseProcessor;" +
e.getMessage() + ";" + e.getCause() + ";" +
e.getLocation());
FailureMessage.printFailureMessage(MainClass.getController(),
"XMLStreamException in XMLTestCaseProcessor;" +
e.getMessage() + ";" + e.getCause() + ";" +
e.getLocation());
}
}