Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class BWTSFileReaderWrapper {


public List<File> readBWTSFile(List<String> testSuiteList , String TestFolderPath, MavenProject project) throws IOException{
public List<File> readBWTSFile(List<String> testSuiteList , String TestFolderPath, MavenProject project, String testFoldername) throws IOException{
List<File> returnList = new ArrayList<>();
List<File> tempReturnList ;
HashMap<String,List<File>> testSuiteMap = new HashMap<String,List<File>>();
Expand All @@ -26,14 +26,19 @@ public List<File> readBWTSFile(List<String> testSuiteList , String TestFolderPat
BWTSModel bwtsModel = YMLBWTSFileReader.getModelFrom(path);
Object testCaseList = bwtsModel.getOthers().get("testCases");
tempReturnList = new ArrayList<>();
//to get the path till the the project module
String[] locationArray = TestFolderPath.split(testFoldername);

if(null != testCaseList){
for (Object obj : (ArrayList<?>)testCaseList) {
if(obj instanceof String){
returnList.add(new File(TestFolderPath.concat("//"+(String)obj)));
tempReturnList.add(new File(TestFolderPath.concat("//"+(String)obj)));
String location = locationArray[0]+testFoldername+File.separator+(String)obj;
returnList.add(new File(location));
tempReturnList.add(new File(location));
}
}
}

String testSuite = StringUtils.substringAfter(testSuiteName, TestFolderPath.concat("//"));
testSuiteMap.put(testSuite, tempReturnList);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
package com.tibco.bw.maven.plugin.testsuite;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputFilter;
import java.io.ObjectInputFilter.Config;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.project.MavenProject;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import com.tibco.bw.maven.plugin.test.helpers.BWTestConfig;
import com.tibco.bw.maven.plugin.utils.BWFileUtils;
Expand Down Expand Up @@ -39,14 +57,83 @@ public List<File> collectTestCasesList(String baseDir, MavenProject project) thr

BWTestConfig.INSTANCE.setTestSuiteNameList(project, testSuiteNameList);

File[] fileList = getFileList(baseDir);
String contents = FileUtils.readFileToString(fileList[0]);
String testFolderName = null;

if(contents != null) {
testFolderName = readProperties(contents,fileList[0]);
}

BWTSFileReaderWrapper fileReader = new BWTSFileReaderWrapper();
testSuitefile = fileReader.readBWTSFile(testSuiteNamePathList,testFolderPath, project);
testSuitefile = fileReader.readBWTSFile(testSuiteNamePathList,testFolderPath, project,testFolderName);
return testSuitefile;



}

private File[] getFileList(String baseDir) {
File dir = new File(baseDir);

File[] fileList = dir.listFiles(new FilenameFilter() {

public boolean accept(File dir, String name) {
return name.endsWith(".config");
}

});
return fileList;
}

protected static String readProperties(String contents,File propsFile) {
InputStream is = null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder builder = factory.newDocumentBuilder();
is = new ByteArrayInputStream(contents.getBytes(StandardCharsets.UTF_8));
Document document = builder.parse(is);
NodeList nodeList = document.getDocumentElement().getChildNodes();

for (int i = 0; i < nodeList.getLength(); i++)
{
Node node = nodeList.item(i);
if (node instanceof Element)
{
Element el = (Element) node;
if ("config:specialFolders".equals(el.getNodeName())) {

NodeList childNodes = el.getChildNodes();

for (int j = 0; j < childNodes.getLength(); j++) {

Node cNode = childNodes.item(j);

if (cNode instanceof Element) {
Element cEl = (Element) cNode;

if ("config:folder".equals(cEl.getNodeName()))
{

if(cNode.getAttributes().getNamedItem("kind").getNodeValue().equals("bwtf")) {
return cNode.getAttributes().getNamedItem("location").getNodeValue();
}

}
}

}
}
}
}

} catch (ParserConfigurationException | SAXException | IOException e) {
e.printStackTrace();
}
return null;
}


public List<File> collectTestCasesListFromESM(String baseDir) throws IOException{
List<File> testSuitefile = new ArrayList<File>();
List<String> testSuiteNamePathList = new ArrayList<String>();
Expand Down