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