BizUnit 3.0.1026.0 (3.0 Beta 2): XmlValidationStep.ExecuteValidation(Stream, Context) throws NullReferenceException

May 13, 2008 at 9:31 PM
I'm trying to run a simple proof-of-concept using BizUnit 3.0.1026, and XmlValidationStep.ExecuteValidation(Stream data, Context context) is blowing up. Apparently, this.xPathValidations is only initialized in XmlValidationStep.ExecuteValidation(Stream data, XmlNode validatorConfig, Context context), but that method isn't being called.

Here's the ValidationStep XML:

      <ValidationStep assemblyPath="" typeName="BizUnit.XmlValidationStep">
        <XmlSchemaPath>C:\play\BT_AutoTestingDemo\BT_AutoTestingDemo\Schemas\Member.xsd</XmlSchemaPath>
        <XmlSchemaNameSpace>http://BT_AutoTestingDemo.Member</XmlSchemaNameSpace>
        <XPathList>
          <XPathValidation query="//Member/FirstName">Fred</XPathValidation>
          <XPathValidation query="//Member/LastName">Foobar</XPathValidation>
        </XPathList>
      </ValidationStep>


And here's what's being written to Console.Out:

Info: Adding context property: BizUnitTestCaseName, value: GoodClient
 
-------------------------------------------------------------------------------
                                   S T A R T
 
Test: GoodClient started @ 16:25:59.449 13/05/2008 by FHP\sched01
-------------------------------------------------------------------------------
Info: Adding context property: BizUnitTestCaseStartTime, value: 5/13/2008 4:25:59 PM
Info: Adding context property: testData, value: C:\play\BT_AutoTestingDemo\DemoBizUnitTests\bin\Debug\..\..\TestData\ClientToMember_GoodClient_Input.xml
Info: Adding context property: inputPort, value: C:\play\BT_AutoTestingDemo\BT_AutoTestingDemo\Ports\IncomingClient\GoodClient_input.xml
Info: Adding context property: outputPort, value: C:\play\BT_AutoTestingDemo\BT_AutoTestingDemo\Ports\OutgoingGreeting\
 
Setup Test: GoodClient

Step: BizUnit.FileDeleteMultipleStep started @ 16:25:59.464 13/05/2008, failOnError = True
Info: 1 files were found matching the File Mask: "*.xml" in the directory: "C:\play\BT_AutoTestingDemo\BT_AutoTestingDemo\Ports\OutgoingGreeting\"
Info: File: "C:\play\BT_AutoTestingDemo\BT_AutoTestingDemo\Ports\OutgoingGreeting\{ACFE6A53-F40D-44B6-B6C3-F7CBBA856C4C}.xml" was successfully deleted.
Step: BizUnit.FileDeleteMultipleStep ended @ 16:25:59.464 13/05/2008
 
Execute Test: GoodClient

Step: BizUnit.FileCreateStep started @ 16:25:59.464 13/05/2008, failOnError = True
Info: FileCreateStep about to copy the data from File: C:\play\BT_AutoTestingDemo\DemoBizUnitTests\bin\Debug\..\..\TestData\ClientToMember_GoodClient_Input.xml to the File: C:\play\BT_AutoTestingDemo\BT_AutoTestingDemo\Ports\IncomingClient\GoodClient_input.xml
Step: BizUnit.FileCreateStep ended @ 16:25:59.480 13/05/2008

Step: BizUnit.FileValidateStep started @ 16:25:59.480 13/05/2008, failOnError = True
Info: Searching for files in: "C:\play\BT_AutoTestingDemo\BT_AutoTestingDemo\Ports\OutgoingGreeting\*.xml"
Info: 1 fies were found at : "C:\play\BT_AutoTestingDemo\BT_AutoTestingDemo\Ports\OutgoingGreeting\*.xml"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Data: Loaded FILE: C:\play\BT_AutoTestingDemo\BT_AutoTestingDemo\Ports\OutgoingGreeting\{EF6ECC08-25F5-4416-83FD-75C5DDA93C57}.xml
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<ns0:Member xmlns:ns0="http://BT_AutoTestingDemo.Member"><FirstName>Frank</FirstName><LastName>Success</LastName><EmailAddress>frank@example.com</EmailAddress></ns0:Member>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*******************************************************************************
Error: Exception caught!
System.NullReferenceException: Object reference not set to an instance of an object.
   at BizUnit.XmlValidationStep.ExecuteValidation(Stream data, Context context) in C:\play\BT_AutoTestingDemo\BizUnit 3.0\Src\BizUnit\ValidationSteps\XmlValidationStep.cs:line 151
   at BizUnit.FileValidateStep.Execute(Context context) in C:\play\BT_AutoTestingDemo\BizUnit 3.0\Src\BizUnit\TestSteps\FileValidateStep.cs:line 211
   at BizUnit.FileValidateStep.Execute(XmlNode testConfig, Context context) in C:\play\BT_AutoTestingDemo\BizUnit 3.0\Src\BizUnit\TestSteps\FileValidateStep.cs:line 162
   at BizUnit.BizUnitOM.BizUnitTestStepWrapper.Execute(Context ctx) in C:\play\BT_AutoTestingDemo\BizUnit 3.0\Src\BizUnit\BizUnitOM\BizUnitTestStepWrapper.cs:line 117
   at BizUnit.BizUnit.ExecuteTestStep(BizUnitTestStepWrapper stepWrapper) in C:\play\BT_AutoTestingDemo\BizUnit 3.0\Src\BizUnit\BizUnit.cs:line 1038
*******************************************************************************
 
Tear Down Test: GoodClient
-------------------------------------------------------------------------------
Test: GoodClient ended @ 16:26:00.105 13/05/2008
                             ****** F A I L ******

-------------------------------------------------------------------------------


Help?




Jun 24, 2008 at 5:48 AM

I modified FileValidateStep.cs by adding two private fields on line 97:

private XmlNode validationConfig;
private XmlNode contextConfig;

and then changing these lines at 168:

validationConfig = testConfig.SelectSingleNode("ValidationStep");
contextConfig = testConfig.SelectSingleNode("ContextLoaderStep");

and then changing line 219:

if (null != this.validationStep)
{
    this.validationStep.ExecuteValidation(data, this.validationConfig, context);
}

I also had to add this to XmlValidationStep.cs line 115:

if (this.xPathValidations == null)
{
    this.xPathValidations = new List<Pair>();
}

Don't know if this is what Kevin had in mind, but it makes FileValidationStep work in Build 3.0.1026.0

Jun 24, 2008 at 5:53 AM
Correction, that was Build 3.0.1027.0. Same bug AFAIK.
Jun 30, 2008 at 5:50 PM
Thanks, for saving me the debug time! I am using 3.0.1027.0 and that fixed it for me as well.
Jul 2, 2008 at 12:41 AM

One more addition to this one, if you intend to use ContextLoader in the FileValidationStep, you'll need to modify the following as well in this file:

 

 

if (null != this.contextLoaderStep)
{
    this.contextLoaderStep.ExecuteContextLoader(data, context);
}

To:

 

if (null != this.contextLoaderStep)
{
    this.contextLoaderStep.ExecuteContextLoader(data, this.contextConfig, context);
}