Thursday, January 30, 2014

Writing a simple Integration BPEL test case for WSO2 BPS

I assume the user has an idea about WSO2 BPS product. You can refer more information on :

http://wso2.com/products/business-process-server/


Following are the steps to write a simple test case for a simple bpel process.


As an example adder.process.zip is being used to write a test case.


In this example assign activity of BPEL will be used. 2 values will be added and the input will be the result.


Since this is a Basic bpel activity, we will be including our test case inside,
../integration/org.wso2.bps.bpel.taftests/



/home/../turing/products/bps/3.2.0/modules/integration/org.wso2.bps.bpel.taftests/src/test/java/org/wso2/carbon/bps/bpelactivities/BPELBasicActivitiesTest.java


Steps :


1. First of all we should include our artifact inside the
/home/../turing/products/bps/3.2.0/modules/integration/org.wso2.bps.bpel.taftests/src/test/resources/artifacts/bpel folder.



2. Since its a Basic activity test case, I will be adding it under BPELBasicActivitiesTest.java in /home/../turing/products/bps/3.2.0/modules/integration/org.wso2.bps.bpel.taftests/src/test/java/org/wso2/carbon/bps/bpelactivities/BPELBasicActivitiesTest.java


3.
 public class BPELBasicActivitiesTest extends BPSMasterTest {  
 //Extends the Test class  
   private static final Log log = LogFactory.getLog(BPELBasicActivitiesTest.class);  
 //Logs  
   BpelPackageManagementClient bpelPackageManagementClient;  
   RequestSender requestSender;  
   public void setEnvironment() throws LoginAuthenticationExceptionException, RemoteException {  
     init();  
     bpelPackageManagementClient = new BpelPackageManagementClient(backEndUrl, sessionCookie);  
 //Pass the Service endpoint and session cookie  
     requestSender = new RequestSender();  
   }  



Above section will be available already since there were already written test cases.

(I assume it was being explained during the automation training. )


4. To set the environment with AdderProcess.zip we should provide the name of it to upload.


   @BeforeClass(alwaysRun = true)  
   public void deployArtifact()  
       throws Exception {  
     setEnvironment();  
     uploadBpelForTest("AdderProcess");  
   }  



5. Following is the added test case.

  @Test(groups = {"wso2.bps", "wso2.bps.bpelactivities"}, description = "Adder Process case")  
   public void adderProcess() throws InterruptedException, RemoteException, PackageManagementException, MalformedURLException, XMLStreamException {  
     String payLoad = " <p:AdderProcessRequest xmlns:p=\"http://wso2.org/wso2con/2011/sample/adder\">\n" +  
         "   <!--Exactly 1 occurrence--><p:a>1</p:a>\n" +  
         "   <!--Exactly 1 occurrence--><p:b>2</p:b>  "  +  
         "  </p:AdderProcessRequest>";  
     String operation = "process";  
     String serviceName = "AdderProcessService";  
     String expectedResult = "3";  
     requestSender.assertRequest(backEndUrl + serviceName, operation, payLoad,  
         1, expectedResult, true);  
   }  




6. You can undeploy the uploaded zip file,

   @AfterClass(alwaysRun = true)  
   public void removeArtifacts()  
       throws PackageManagementException, InterruptedException, RemoteException,  
       LogoutAuthenticationExceptionException {  
       bpelPackageManagementClient.undeployBPEL("AdderProcess");  
 this.authenticatorClient.logOut();  
 }  
 }  

Explanation :


1. public void adderProcess() throws InterruptedException, RemoteException, PackageManagementException, MalformedURLException, XMLStreamException {

This above is the method written for adderProcess()

2.
String payLoad = " <p:AdderProcessRequest xmlns:p=\"http://wso2.org/wso2con/2011/sample/adder\">\n" +
               "      <!--Exactly 1 occurrence--><p:a>1</p:a>\n" +
               "      <!--Exactly 1 occurrence--><p:b>2</p:b>   "   +
               "   </p:AdderProcessRequest>";

      String operation = "process";
       String serviceName = "AdderProcessService";
         String expectedResult = "3";
Above is the variable assignment.

payLoad is what we get from try it tool when you deploy the adderProcess in a BPS distribution. 
operation  can be checked by the wsdl of adderProcess when you deploy it in a BPS distribution. E.g., <operation name="process">

serviceName this can also be checked by the wsdl of adderProcess when you deploy it in a BPS distribution. E.g., <service name="AdderProcessService">

3.     requestSender.assertRequest(backEndUrl + serviceName, operation, payLoad,
               1, expectedResult, true);
The above is the request to be sent and assertRequest method is called.
Definition would be :

public void assertRequest(java.lang.String eprUrl, java.lang.String operation, java.lang.String payload, int numberOfInstances, java.lang.String expectedException, boolean twoWay) throws javax.xml.stream.XMLStreamException, org.apache.axis2.AxisFault { }

backEndUrl  : This is the BPS backend URL

How to resolve WSO2 platform build failures come due to package does not exist

You can follow the steps on building Carbon by the link below :

http://docs.wso2.org/display/Carbon420/Building+from+Source

Following blog post is for the users who have fair knowledge in programming. Intended users will be Quality Assurance Engineers.

How to Isolate :

1. First of all, to isolate the problems you face, it is better to start building according to the modules defined in the pom.xml.

E.g.,

Open the pom.xml in ../platform/branches/turing/product-releases/chunk-07

You will see the modules defined like below.

             <modules>
                <module>dependencies</module>
                <module>service-stubs</module>
                <module>components</module>
                <module>platform-integration/test-automation-framework</module>
                <module>features</module>
                <module>products</module>
                <module>platform-integration/platform-automated-test-suite</module>
             </modules>

Build one by one by the following command.

mvn clean install --fail-at-end
fail-at-end will be used to continue the all modules bulding eventhough there is a build failure.


2. Imagine when you are building products you get an error like below.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project sample-utils: Compilation failure: Compilation failure:
[ERROR] /home/ushani/Downloads/Automation_TC/24_Jan_2014/turing/products/bps/3.2.0/modules/samples/product/sample-utils/src/main/java/org/wso2/bps/samples/util/PasswordEncryptUtil.java:[23,31] package org.apache.axiom.om.util does not exist
[ERROR] /home/ushani/Downloads/Automation_TC/24_Jan_2014/turing/products/bps/3.2.0/modules/samples/product/sample-utils/src/main/java/org/wso2/bps/samples/util/PasswordEncryptUtil.java:[58,66] package org.bouncycastle.jce.provider does not exist
[ERROR] /home/ushani/Downloads/Automation_TC/24_Jan_2014/turing/products/bps/3.2.0/modules/samples/product/sample-utils/src/main/java/org/wso2/bps/samples/util/PasswordEncryptUtil.java:[84,35] cannot find symbol
[ERROR] symbol  : variable Base64
[ERROR] location: class org.wso2.bps.samples.util.PasswordEncryptUtil
[ERROR] -> [Help 1]
[ERROR] Failed to execute goal org.wso2.maven:carbon-p2-plugin:1.5.3:p2-repo-gen (3-p2-repo-generation) on project wso2-bps-profile-gen: Error occured when processing the Feature Artifact: org.wso2.bps:org.wso2.bps.samples.utils.feature:3.2.0: ERROR: Failure to find org.wso2.bps:org.wso2.bps.samples.utils.feature:zip:3.2.0 in http://maven.wso2.org/nexus/content/groups/wso2-public/ was cached in the local repository, resolution will not be reattempted until the update interval of wso2-nexus has elapsed or updates are forced
[ERROR]

Identify the error, the affected place and the reason :
3. If you look at it properly, you see the error is in PasswordEncryptUtil.java class.
4. So the best thing is open the project in idea. from sample-utils/src/main/java/org/wso2/bps/samples onwards.
5. you will see the class name with a red curly underline since there is an error in the class.
6. Go to the class and check what is wrong in it. As per the above error, issue was with the symbol
variable Base64
7. In the code the following line was in red, exposing it as an error.

  String encodedString = Base64.encode(encryptedText);
8. Also there was another curly line in red mentioning the following import hasnt been done correctly.
import org.apache.axiom.om.util.Base64;

Solutions :

Solution 1.
a. Either you can check in you .m2 , which is also known as the maven repository in your machine.
.m2 is a repository that is created in every one of your machine, if you have installed maven properly. Whenever you need  any dependencies, it will automatically download in to your maven repository.
You can see your maven repo at the following place :
/home/<username>/.m2

b. Go to .m2 and follow the import path correctly in the file location.
E.g.,
 You should have a folder called axiom in the following file location.

/home/ushani/.m2/repository/org/apache
c. if you don't have a folder that means the issue is because it hasn't been downloaded properly. You can get it from someone else's .m2 repo and replace you one or can check from which location it has been taken. Sometimes axiom folder can be refereed from a different location.
if so you will have to provide the dependency manually in you pom.xml located in the related module.
E.g., I had the issue in sample-utils. So I will refer the pom.xml in that module.

/home/ushani/Downloads/Automation_TC/24_Jan_2014/turing/products/bps/3.2.0/modules/samples/product/sample-utils/pom.xml.
According to this the correct axiom is inside,

path : /home/ushani/.m2/repository/org/apache/ws/commons/axiom

Add the following dependency according to the correct location.

<dependency>
            <groupId>org.apache.ws.
commons.axiom</groupId>
            <artifactId>axiom-api</
artifactId>
            <version>1.2.8</version>
        </dependency>    
<dependency>
            <groupId>org.apache.ws.
commons.axiom</groupId>
            <artifactId>axiom-impl</
artifactId>
            <version>1.2.8</version>
    </dependency>

Solution 2:
1. Go near the issue underlined in red colour and get the your curosr top of it and the help comes in the left corner of your code editor window.
It will give you suggestions.

If there is a missing maven dependency it will ask whether to add. You have to click that suggestion and provide the correct path which will come automatically.

By this it will solve the problem and that dependency will be added in to your pom.xml automatically.