Of course all this ugliness would go away, if the ReportFileNameSelector is just a regular TextField.  Instead, of a hidden parameter. What you guys think about that?

thanks, aaron


At 02:06 PM 5/10/2005, you wrote:
At 08:19 AM 5/10/2005, Philip wrote:
--On Tuesday, May 10, 2005 1:06 AM -1000 Aaron Kagawa <[EMAIL PROTECTED]> wrote:
I've manually tested the functionality and all appears to be ok. I've
wrote a test case to TestTelemetryChartAnalysis. But, I had to take it
out, because the HackystatTestConversation cannot set a parameter which
isn't in the WebForm.

How about making the chart name a "hidden" parameter in the JSP page, which (a) gives it a default value, and (b) allows you to override it in the GET command, and (c) allows you to write a test case?

Ok. I've came up a solution for this. And It was a little harder that I thought.

You can't change a hidden parameter using HttpUnit < http://httpunit.sourceforge.net/doc/faq.html#hidden>. In addition, to make sure the default value is not actually used I had to do a little work around in the Selector implementation.

1) I've altered the ReportFileNameSelector to _not_ store the user's selection in the User key-value pair storage.

2) Second, I've created a HiddenReportFileName.jsp selector that looks like this:
<input type="hidden" name="ReportFileName" size="80" value="NotAValidValue">

3) I've altered the getFileName in the ReportFileName to return an empty string if the default FileName is unchanged. I had to do this, to ensure that the default value is not used. So, if the user executes the command through a browser, the chart will always be something like "Temp1345.png". The only way to set the file name of the chart is through the URL.

  /**
   * Returns the report's file name that the user specified. If the file name is the default value
   *    "NotAValidValue" an empty string is returned, otherwise the file name parameter is returned.
   * @param request The request object containing the report file name attribute.
   * @return The string entered as the report file name.
   */
  public static String getFileName(HttpServletRequest request) {
    String fileName = request.getParameter(SELECTOR_TEXT_FIELD);
   
if ( "NotAValidValue" .equalsIgnoreCase(fileName)) {
     
return "";
    }
   
return fileName;
  }

4) I've added the following code to the test case:

    HackystatTestParameters[] params2 = {
       
new ReportTypeTestSelector( "Chart" ),
       
new ProjectTestSelector(projectName),
       
new IntervalTestSelector( "Day" , "01-Feb-2003", "05-Feb-2003"),
       
new TelemetryChartTestSelector( "ActiveTimeChart-ForUnitTest###Not Shared"),
       
new TemplateParameterTestSelector( "**/*.java, true"),
       
new SimpleTestSelector(ReportFileNameSelector.SELECTOR_TEXT_FIELD, "NotAValidValue")
    };
    test = test.invokeCommand(
"TelemetryChartAnalysis" , params2);

There are two things wrong (1) because HttpUnit doesn't allow changing the value of a hidden parameter I can't actually test using ReportFileName parameter to generate a chart with the specified FileName. For example, if I changed "NotAValidValue" to "foo", HttpUnit will throw an exception. Therefore, any HttpUnit test that generates a chart in the TelemetryChartAnalysis can never test the creation of a Chart with a specified name. (2) I can't seem to figure out how to test the file name of the chart that is created.

In addition, I added this code:

    params2[5] = new SimpleTestSelector(ReportFileNameSelector.SELECTOR_TEXT_FIELD,
       
"AReallyInvalidValue" );
   
try {
      test = test.invokeCommand(
"TelemetryChartAnalysis" , params2);
      fail(
"should throw an exception");
    }
   
catch (Exception e) {
      assertNotNull(
"the exception object should not be null", e);
    }

However, that seems it only tests HttpUnit and makes little sense. So, I removed it.


thanks, aaron



Reply via email to