<%@ include file="MethodBodyGenerator.template"%>
<%@ include file="InvocationGenerator.template"%>
<%
	String packageName = helper.getPackageName(testSuite);
	String className = helper.retrieveClassName(testSuite);
	String description = testSuite.getDescription();
	if(description != null)
		description = StringUtil.replace(description.trim(), NL, NL + " * ");
	else
		description = "";
		
	helper.setImportManager(new ImportManager(packageName));
	helper.getImportedName(packageName + "." + className);
%>
package <%=packageName%>;

<%
	helper.addImport("junit.framework.Test");
	helper.addImport("org.eclipse.hyades.test.common.junit.DefaultTestArbiter");
	helper.addImport("org.eclipse.hyades.test.common.junit.HyadesTestCase");
	helper.addImport("org.eclipse.hyades.test.common.junit.HyadesTestSuite");
	helper.markImportLocation(stringBuffer);

	final String hyadesTestSuiteClassName = helper.getImportedName("org.eclipse.hyades.test.common.junit.HyadesTestSuite");
	final String hyadesTestCaseClassName = helper.getImportedName("org.eclipse.hyades.test.common.junit.HyadesTestCase");
	String exceptionClassName = helper.getImportedName("java.lang.Exception");
	String filePath = helper.getFilePath(testSuite);
%>

/**
 * Generated code for the test suite <b><%=helper.getLabel(testSuite)%><%if(filePath != null){%></b> located at
 * <i><%=filePath%></i><%}%>.<%if(description.length() > 0){%>
 *
 * <%=description%><%}%>
 */
public class <%=className%>
extends <%=hyadesTestCaseClassName%>
{
	/**
	 * Constructor for <%=className%>.
	 * @param name
	 */
	public <%=className%>(String name)
	{
		super(name);
	}

	/**
	 * Returns the JUnit test suite that implements the <b><%=helper.getLabel(testSuite)%></b>
	 * definition.
	 */
	public static Test suite()
	{<% 
		String javaElement = helper.retrieveIdentifierName(testSuite, "SUITE"); 
		String code = new InvocationGenerator(hyadesTestSuiteClassName).generate(javaElement, testSuite.getImplementor().getBlock().getActions()).toString();

%>		<%=hyadesTestSuiteClassName%> <%=javaElement%> = new <%=hyadesTestSuiteClassName%>("<%=helper.getLabel(testSuite)%>");
		<%=javaElement%>.setArbiter(DefaultTestArbiter.INSTANCE).setId("<%=testSuite.getId()%>");
		
        <%=code%>

		return <%=javaElement%>;
	}
	
	/**
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp()
	throws <%=exceptionClassName%>
	{
	}

	/**
	 * @see junit.framework.TestCase#tearDown()
	 */
	protected void tearDown()
	throws <%=exceptionClassName%>
	{
	}	
<%
	MethodBodyGenerator methodBodyGenerator = new MethodBodyGenerator();
	for(Iterator i=testSuite.getITestCases().iterator(); i.hasNext();)
	{
		ITestCase testCase = (ITestCase)i.next();
		
		code = methodBodyGenerator.generate(testCase).toString();
		String identifier = testCase.getImplementor().getResource();
		if(identifier == null)
			identifier = helper.retrieveIdentifierName(testCase, "METHOD");

		if(identifier != null)
		{
			description = testCase.getDescription();
			description = StringUtil.replace(description, NL, NL + " * ");
%>

/**
 * <%=helper.getLabel(testCase)%><%if(description != null){%>
 *
 * <%=description%>
 * <%}%>
 * @throws <%=exceptionClassName%>
 */
	public void <%=identifier%>()
	throws <%=exceptionClassName%>
	{
		<%=code%>
	}
<%
		}
	}
%>
<%@ include file="ExtraMethods.template"%>
}
<%helper.emitSortedImports();%>