Saturday 30 June 2007

Importance of stub services

Todays world of software engineering involves communication with different applications accross different domains. Lots of time is wasted in integrating with the realtime applications in the development environment. The development and testing of our applications is hindered because of the unavailability or issues not related to our application.
The best way to avoid this is to go for the creation of stubs for all the third party services in the beginning of the development cycle. These stubs should be developed by creating a sample response that will be returned by the 3rd party. For eg.
Here is the sample code for a real web service:

[WebMethod]
public response CheckAvailability(request) {
//Actual Business Logic
...
...
...
return response;
}

The above code can be replaced by a stub service as follows:
[WebMethod]
public response CheckAvailability(request)
{return sampleResponse;}

This leads to a heavy reduction in loss of time in fixing of the issues in the actual service. The best usage of this approach is of performance testing of the application. The performance testing can be done using the stubbed services to deterime the actual resource usage by our application without taking into consideration the behaviour of the external services. If a delay of 2 sec. in response from the external service is required, same can be achieved as follows:
[WebMethod]
public response CheckAvailability(request)
{Thread.Sleep(2000);
return sampleResponse;}

This approach can be further extended to test the individual components/layers in our application by stubbing out the other components/layers. The usage of stubbed or actual service can be made configurable by using a config setting. Other way is to host them on different urls and change the urls as per the requirement.

Friday 29 June 2007

Automate deployment of Business Rules



You must be tired of using biztalk business rules engine deployment wizard to export and import policies and vocabularies. For eg. if you have 40 business rules and 20 vocabs defined in business rule composer, you need to run the wizard again and again to export to an xml and import from an xml. It becomes painful to run the wizard. The code in the images helps you to do the same without using the wizard. All you need to do is to create a batch file and invoke an exe created by putting the following in a console application. The following code shows how to export the policies and vocabs to an xml file.
Once you have exported to an xml file, you will need to import them to another machine or even again on your own machine. The second image shows how to import the policies and vocabs to any machine by running the exe through a batch file. These two code pieces can be used for even deleting the policies and vocabs. They publish the vocabs and deploy the policies too. The following sample shows the contents of the batch file used to run these console applications. The calls can be used in a sequence in a single file.

The below sample is for importing the policies and vocabs from xml:

REM *** Call ApplicationName Policy/VocabularyName FileLocation

REM *** Delete Policies
call ImportBRE " " " " "CustomerPolicy"

REM *** Import Vocabularies
call ImportBRE "CommonField" "..\vocabulary files\CommonField-1.0.xml" "CommonField"

REM *** Import Policies
call ImportBRE "CustomerPolicy" "..\policy files\CustomerPolicy.xml" "1"

The below sample is for exporting the policies and vocabs:

REM *** Call ApplicationName Policy/VocabularyName MajorRevision MinorRevision
REM *** Export Vocabularies

call ExportBRE "CommonField" "1" "0"

REM *** Export Policies
call ExportBRE "CustomerPolicy" "1" "0"