All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tibco.bw.maven.plugin.test.rest.AssertionsLoader Maven / Gradle / Ivy

Go to download

Plugin Code for Apache Maven and TIBCO BusinessWorks™. This is the Maven Plugin for BW6 and BWCE Build.

There is a newer version: 2.9.9
Show newest version
package com.tibco.bw.maven.plugin.test.rest;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.apache.maven.project.MavenProject;

import com.tibco.bw.maven.plugin.test.dto.TestSuiteDTO;
import com.tibco.bw.maven.plugin.test.helpers.BWTestConfig;
import com.tibco.bw.maven.plugin.test.helpers.TestFileParser;
import com.tibco.bw.maven.plugin.testsuite.BWTestSuiteLoader;
import com.tibco.bw.maven.plugin.utils.BWFileUtils;

public class AssertionsLoader 
{

	MavenProject project;
	
	  File esmFile;
	
	public AssertionsLoader( MavenProject project)
	{
		
		this.project = project;
	}
	
	public AssertionsLoader(File file)
		{
			this.esmFile = file;
	 	}
	 
	
	@SuppressWarnings({ "unused", "rawtypes" })
	public TestSuiteDTO loadAssertions() throws Exception
	{
		List files = getAssertionsFromProject();
		Map> testSuiteMap = BWTestConfig.INSTANCE.getTestSuiteMap(this.project);
		TestSuiteDTO suite = new TestSuiteDTO();
		List testCaseList = new ArrayList();
		BWTestConfig.INSTANCE.getLogger().info("");
		//BWTestConfig.INSTANCE.getLogger().info("-----------------BW Engine Logs End--------------------");

		if(null != BWTestConfig.INSTANCE.getTestSuiteName() && !BWTestConfig.INSTANCE.getTestSuiteName().isEmpty()){
			for (String suiteName : BWTestConfig.INSTANCE.getTestSuiteNameList(this.project)){
				BWTestConfig.INSTANCE.getLogger().info("");
				BWTestConfig.INSTANCE.getLogger().info(" ## Running Test Suite "+ suiteName + " ##");
				for( File file : testSuiteMap.get(suiteName) ){
					
					BWTestConfig.INSTANCE.getLogger().info("      Running Test for "+ file.getName());

					String assertionxml = FileUtils.readFileToString( file );

					TestFileParser.INSTANCE.collectAssertions(assertionxml , suite ,project.getBasedir().getAbsolutePath());
				}
			}
			return suite;
		}
		else{
			for( File file : files )
			{
				BWTestConfig.INSTANCE.getLogger().info("## Running Test for "+file.getName()+" ##");

				String assertionxml = FileUtils.readFileToString( file );

				TestFileParser.INSTANCE.collectAssertions(assertionxml , suite ,project.getBasedir().getAbsolutePath());

			}

			return suite;
		}
	}
	
	public TestSuiteDTO loadAssertionsFromESM() throws Exception
	{
		TestSuiteDTO suite = new TestSuiteDTO();
		String filePath = esmFile.getAbsolutePath();
		Map> testSuiteMap = BWTestConfig.INSTANCE.getEsmTestSuiteMap(filePath);
		
		if(null !=testSuiteMap && !testSuiteMap.isEmpty()){
			for (String suiteName : BWTestConfig.INSTANCE.getEsmTestSuiteNameList(filePath)){
				BWTestConfig.INSTANCE.getLogger().info("");
				BWTestConfig.INSTANCE.getLogger().info(" ## Running Test Suite ["+ suiteName+"]" +" From ESM ["+ esmFile.getName()  + "] ##");
				for( File file : testSuiteMap.get(suiteName) ){
					
					BWTestConfig.INSTANCE.getLogger().info("      Running Test for "+ file.getName());

					String assertionxml = FileUtils.readFileToString( file );

					TestFileParser.INSTANCE.collectAssertions(assertionxml , suite ,filePath);
				}
			}
			return suite;
		}else{
			List files = getAssertionsFromESM();
			for( File file : files )
			{
				BWTestConfig.INSTANCE.getLogger().info("");

				
				BWTestConfig.INSTANCE.getLogger().info("## Running Test for "+file.getName()+" ##");

				String assertionxml = FileUtils.readFileToString( file );

				TestFileParser.INSTANCE.collectAssertions(assertionxml , suite ,filePath);

			}

			return suite;
		}
		
	}

	
	private List getAssertionsFromProject()
	{
			return BWTestConfig.INSTANCE.getTestCasesList(this.project);
	
	}
	
	private List getAssertionsFromESM()
	{
			return BWTestConfig.INSTANCE.getEsmTestCasesList(esmFile.getAbsolutePath());
	
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy