FileDocCategorySizeDatePackage
JUnitPerfTagHandler.javaAPI DocExample7258Tue Nov 26 19:49:32 GMT 2002com.oreilly.javaxp.xdoclet.perf

JUnitPerfTagHandler

public class JUnitPerfTagHandler extends xdoclet.XDocletTagSupport
Provides a window into the junitperf.xdt template file. The instance methods can be used in the template file to retrieve or perform logic. See the junitperf.xdt file for an example of these methods are used.
xdoclet.taghandler
namespace="Perf"
author
Brian M. Coyner
version
$version $Id: JUnitPerfTagHandler.java,v 1.11 2002/11/23 03:54:55 jepc Exp $

Fields Summary
public static final String
TIMED_TEST
public static final String
LOAD_TEST
public static final String
WAIT_FOR_COMPLETION
public static final String
NUMBER_OF_USERS
public static final String
NUMBER_OF_ITERATIONS
public static final String
MAX_ELAPSED_TIME
Constructors Summary
Methods Summary
public java.lang.StringclassName()
This shows an example of a content-level method that returns the name of the new name of the generated class. See the junitperf.xdt file for an example of how to use this method.

This method shows how to use the active Ant subtask to retrieve attributes defined in the Ant buildfile. Here we extract out the 'jUnitPerfPattern' attribute.

return
the new name of the generated class.

        JUnitPerfDocletSubTask task = (JUnitPerfDocletSubTask)
                getDocletContext().getActiveSubTask();

        String currentJUnitTest = getCurrentClass().getName();
        return MessageFormat.format(task.getJUnitPerfPattern(),
                                    new Object[]{currentJUnitTest});
    
private java.lang.StringgetJUnitConstructor()
Helper method that retrieves the current class being evaluated. This class should be an instance of a JUnit TestCase and therefore we pass in as a single parameter the current method name being evaluated. This produces a new instance of a TestCase that executes a single JUnit test method. For example: new TestExample("testExampleLoad"); might be the output of the method.

return
a line of code that constructs a new TestCase method for executing a single JUnit test method.

        return "new " + getCurrentClass().getName() + "(\"" +
                getCurrentMethod().getName() + "\")";
    
private java.lang.StringgetMaxElapsedTime()
Helper method that retrieves the max allowed time for a TimedTest to execute. This is another example of a mandatory attribute.

return
the max allowed time for a test to execute.
throws
XDocletException

        return getTagValue(XDocletTagSupport.FOR_METHOD,
                           TIMED_TEST,
                           MAX_ELAPSED_TIME,
                           null,
                           null,
                           false,
                           true);
    
private java.lang.StringgetNumberOfIterations()
Helper method that retrieves the number of iterations each user of a LoadTest must execute.

return
the number of iterations to use for a load test. If the value is not specified in the source file a default value of 1 is used.

        return getTagValue(XDocletTagSupport.FOR_METHOD,
                           LOAD_TEST,
                           NUMBER_OF_ITERATIONS,
                           null,
                           "1",
                           false,
                           false);
    
private java.lang.StringgetNumberOfUsers()
Helper method that retrieves the number of users to use for a LoadTest. This method shows an example of how to use the xdoclet.XDocletTagSupport.getMethodTagValue() method.

return
the number of users to use for a load test. This is a mandatory XDoclet tag parameter (attribute).
throws
XDocletException if this attribute does not exist in the source file; it's mandatory!

        return getTagValue(XDocletTagSupport.FOR_METHOD,
                           LOAD_TEST,
                           NUMBER_OF_USERS,
                           null,
                           null,
                           false,
                           true);
    
private java.lang.StringgetWaitForCompletion()
Helper method that retrieves whether or not the TimedTest should wait for the JUnit test method to complete before throwing an exception if the time has elapsed. This method shows an example of setting up two valid default values.

return
'true' if the timed test should wait for completion of the JUnit test method before throwing an exception; 'false' if an exception should be raised immediately.

        return getTagValue(XDocletTagSupport.FOR_METHOD,
                           TIMED_TEST,
                           WAIT_FOR_COMPLETION,
                           "true,false",
                           "false",
                           false,
                           false);
    
public voidifIsTestCase(java.lang.String template)
If the current class being evaluated extends TestCase then add the data contained in the given parameter.

param
template the current block of text to be parsed.


                                    
          
        if (TypeTagsHandler.isOfType(getCurrentClass(),
                                     "junit.framework.TestCase",
                                     TypeTagsHandler.TYPE_HIERARCHY)) {
            generate(template);
        }
    
public java.lang.StringloadTest()
This method shows an example of how to use XDoclet to output code that instantiates an object.

return
a line of code that instantiates a new JUnitPerf LoadTest.

        return "new LoadTest(" + getJUnitConstructor() +
                ", " + getNumberOfUsers() +
                ", " + getNumberOfIterations() + ");";
    
public java.lang.StringtimedTest()
This method shows an example of how to use XDoclet to output code that instantiates an object.

return
a line of code that instantiates a new JUnitPerf TimedTest.

        return "new TimedTest(" + getJUnitConstructor() +
                ", " + getMaxElapsedTime() +
                ", " + getWaitForCompletion() + ");";