10139N/A/*
10139N/A * CDDL HEADER START
10139N/A *
12173N/A * The contents of this file are subject to the terms of the
10139N/A * Common Development and Distribution License, Version 1.0 only
10139N/A * (the "License"). You may not use this file except in compliance
10139N/A * with the License.
10139N/A *
10139N/A * You can obtain a copy of the license at
10139N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
10139N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
10139N/A * See the License for the specific language governing permissions
12091N/A * and limitations under the License.
10139N/A *
10139N/A * When distributing Covered Code, include this CDDL HEADER in each
10139N/A * file and include the License file at
10139N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
10686N/A * add the following below this CDDL HEADER, with the fields enclosed
12135N/A * by brackets "[]" replaced with your own identifying information:
10139N/A * Portions Copyright [yyyy] [name of copyright owner]
11055N/A *
10322N/A * CDDL HEADER END
12173N/A *
12173N/A *
12204N/A * Copyright 2008 Sun Microsystems, Inc.
12204N/A */
12310N/Aimport java.io.*;
12310N/Aimport java.lang.*;
12545N/Aimport java.util.ArrayList;
12545N/A
10139N/Apublic class ParseData
10139N/A{
10139N/A private String suite;
10139N/A private String fileFormat;
10139N/A private ArrayData arrayData;
10139N/A
10139N/A public ParseData(String inName, String inFileFormat)
10139N/A {
10139N/A suite = inName;
10139N/A fileFormat = inFileFormat;
10139N/A arrayData = new ArrayData();
10139N/A }
10139N/A
10139N/A // Parse out data from all the files in the directory.
10139N/A // Place the data into an ArrayData object.
10139N/A // Return the ArrayData object.
10139N/A public ArrayData ParseFile(String fileDir, ArrayList arrayFiles, String strParentDirName) throws IOException
10139N/A {
10139N/A String currTestSuite = strParentDirName + "/" + fileDir;
10139N/A
10139N/A for(int j=0; j<arrayFiles.size(); j++)
10139N/A {
10139N/A File currFile = (File)(arrayFiles.get(j));
10139N/A if(currFile.toString().indexOf(currTestSuite) >= 0)
10139N/A {
10139N/A // synthesize the filename for the current file to parse
10322N/A String filename = currTestSuite + "/" + currFile.getName();
12173N/A
12204N/A File inputFile = new File(filename);
12315N/A
12545N/A // Final check to make sure inputFile is a real file
10139N/A if(inputFile.isFile())
10139N/A {
10139N/A FileInputStream fis = new FileInputStream(inputFile);
10139N/A LineNumberReader fin = new LineNumberReader(new InputStreamReader(fis));
10139N/A
10139N/A String tmpStr;
10139N/A while((tmpStr = fin.readLine()) != null)
10139N/A {
10139N/A // First check the line to see if there is any QA test marker, #@, at all.
10139N/A if(tmpStr.indexOf("#@") >= 0)
10139N/A {
10139N/A if(tmpStr.indexOf("#@TestSuiteName") >= 0)
10139N/A {
10139N/A arrayData.setTestSuiteName(StripSubstring(tmpStr, "#@TestSuiteName"));
10139N/A //System.out.println("Test suite name is " + arrayData.getTestSuiteName());
10139N/A }
10139N/A else if(tmpStr.indexOf("#@TestGroupName") >= 0)
10139N/A {
10139N/A arrayData.setGroupName(StripSubstring(tmpStr, "#@TestGroupName"));
10139N/A }
10139N/A else if(tmpStr.indexOf("#@TestGroupPurpose") >= 0)
11303N/A {
10139N/A arrayData.setGroupPurpose(MultipleLines(tmpStr, "#@TestGroupPurpose", fin));
10139N/A }
10139N/A else if(tmpStr.indexOf("#@TestSubgroupName") >= 0)
10139N/A {
10139N/A arrayData.setSubgroupName(StripSubstring(tmpStr, "#@TestSubgroupName"));
10139N/A }
10139N/A else if(tmpStr.indexOf("#@TestSuitePurpose") >= 0)
10139N/A {
12173N/A arrayData.setTestSuitePurpose(MultipleLines(tmpStr, "#@TestSuitePurpose", fin));
12173N/A }
10139N/A else if(tmpStr.indexOf("#@TestSuiteID") >= 0)
10139N/A {
10139N/A arrayData.setTestSuiteID(StripSubstring(tmpStr, "#@TestSuiteID"));
10139N/A }
10139N/A else if(tmpStr.indexOf("#@TestSuiteGroup") >= 0)
10139N/A {
10139N/A arrayData.setTestSuiteGroup(StripSubstring(tmpStr, "#@TestSuiteGroup"));
10139N/A }
10139N/A else if(tmpStr.indexOf("#@TestSuitePreamble") >= 0)
10807N/A {
10139N/A arrayData.setTestSuitePreamble(StripSubstring(tmpStr, "#@TestSuitePreamble"));
10139N/A }
10139N/A else if(tmpStr.indexOf("#@TestSuitePostamble") >= 0)
10139N/A {
10139N/A arrayData.setTestSuitePostamble(StripSubstring(tmpStr, "#@TestSuitePostamble"));
10139N/A }
10139N/A else if(tmpStr.indexOf("#@TestName") >= 0)
10139N/A {
10139N/A arrayData.setTestName(MultipleLines(tmpStr, "#@TestName", fin));
10273N/A arrayData.setTestSuite(fileDir);
10139N/A }
10139N/A else if(tmpStr.indexOf("#@TestMarker") >= 0)
10139N/A {
10139N/A arrayData.setTestMarker(StripSubstring(tmpStr, "#@TestMarker"));
10139N/A }
10139N/A else if(tmpStr.indexOf("#@TestID") >= 0)
10139N/A {
10139N/A arrayData.setTestID(StripSubstring(tmpStr, "#@TestID"));
10139N/A }
10139N/A else if(tmpStr.indexOf("#@TestIssue") >= 0)
10139N/A {
10139N/A arrayData.setTestIssue(StripSubstring(tmpStr, "#@TestIssue"));
10139N/A }
10139N/A else if(tmpStr.indexOf("#@TestGroup") >= 0)
10139N/A {
10139N/A arrayData.setTestGroup(StripSubstring(tmpStr, "#@TestGroup"));
10139N/A }
10139N/A else if(tmpStr.indexOf("#@TestScript") >= 0)
10139N/A {
10139N/A arrayData.setTestScript(StripSubstring(tmpStr, "#@TestScript"));
10139N/A }
10139N/A else if(tmpStr.indexOf("#@TestHTMLLink") >= 0)
10139N/A {
12545N/A arrayData.setTestHTMLLink(StripSubstring(tmpStr, "#@TestHTMLLink"));
12545N/A }
12310N/A else if(tmpStr.indexOf("#@TestPreamble") >= 0)
12315N/A {
12205N/A arrayData.setTestPreamble(StripSubstring(tmpStr, "#@TestPreamble"));
12205N/A }
12205N/A else if(tmpStr.indexOf("#@TestStep") >= 0)
12173N/A {
12173N/A ArrayList <String> strIndividualSteps = new ArrayList<String>();
12173N/A fin.mark(1000);
12091N/A
12091N/A while(tmpStr.indexOf("#@TestStep") >= 0)
12052N/A {
12052N/A String strStep = StripSubstring(tmpStr, "#@TestStep");
11903N/A tmpStr = fin.readLine();
11903N/A
11303N/A while((tmpStr.indexOf("#@")) < 0)
11303N/A {
11074N/A strStep = strStep + " " + tmpStr.toString();
11074N/A tmpStr = fin.readLine();
10889N/A }
10889N/A
10695N/A strIndividualSteps.add(strStep);
10695N/A }
10690N/A
10690N/A arrayData.setTestSteps(strIndividualSteps);
10686N/A fin.reset();
10686N/A tmpStr = fin.readLine();
10514N/A while(tmpStr.indexOf("#@") < 0 || tmpStr.indexOf("#@TestStep") >= 0)
10514N/A {
10391N/A fin.mark(100);
10391N/A tmpStr = fin.readLine();
10349N/A }
10349N/A fin.reset();
10322N/A }
10322N/A else if(tmpStr.indexOf("#@TestPostamble") >= 0)
10273N/A {
10273N/A arrayData.setTestPostamble(StripSubstring(tmpStr, "#@TestPostamble"));
10139N/A }
10139N/A else if(tmpStr.indexOf("#@TestPurpose") >= 0)
10139N/A {
10139N/A arrayData.setTestPurpose(MultipleLines(tmpStr, "#@TestPurpose", fin));
10139N/A }
10139N/A else if(tmpStr.indexOf("#@TestResult") >= 0)
10139N/A {
10139N/A if(fileFormat.startsWith("xml"))
10139N/A {
10139N/A arrayData.setTestResult(MultipleLines(tmpStr, "#@TestResult", fin));
10139N/A }
10139N/A else if(fileFormat.startsWith("java"))
10139N/A {
10139N/A arrayData.setTestResult(StripSubstring(tmpStr, "#@TestResult"));
10139N/A
10139N/A // parse test purpose from java doc comments
10139N/A fin.mark(1000);
10139N/A String oneMoLine = new String(fin.readLine().trim());
10139N/A while((oneMoLine.indexOf("/**")) < 0)
10139N/A {
10139N/A oneMoLine = new String(fin.readLine().trim());
10139N/A }
10139N/A oneMoLine = new String(fin.readLine().trim());
10139N/A
10139N/A String strPurpose = StripSubstring(oneMoLine, "*");
10139N/A oneMoLine = new String(fin.readLine().trim());
10139N/A while((oneMoLine.indexOf("@")) < 0)
10139N/A {
10139N/A strPurpose += " ";
10139N/A strPurpose += StripSubstring(oneMoLine.toString().trim(), "*");
10139N/A oneMoLine = new String(fin.readLine().trim());
10139N/A }
10139N/A fin.reset();
10139N/A int starIndex = strPurpose.lastIndexOf("*");
10139N/A if(starIndex > 0)
10139N/A {
10139N/A String strPurpose2 = new String(strPurpose.substring(0, starIndex));
arrayData.setTestPurpose(strPurpose2.toString());
}
else
{
arrayData.setTestPurpose(strPurpose.toString());
}
}
}
}
}
fin.close();
}
}
}
return arrayData;
}
private String StripSubstring(String tmpStr, String subStr)
{
int index = tmpStr.indexOf(subStr);
String retStr = tmpStr.substring(index + subStr.length());
return (retStr.trim());
}
private String MultipleLines(String tmpStr, String tag, LineNumberReader fin) throws IOException
{
String currValue = StripSubstring(tmpStr, tag);
fin.mark(1000);
String oneMoLine = new String(fin.readLine().trim());
while((oneMoLine.indexOf("#@") < 0) && (oneMoLine.indexOf("-->") < 0)) {
currValue = currValue + " " + oneMoLine;
oneMoLine = new String(fin.readLine().trim());
}
fin.reset();
return currValue;
}
}