Monday, April 25, 2016

XSLT Transformation Script elements

Hi all,

Lets clarify some of elements in an XSLT transform script.

I used this scenario within WSO2 ESB "XSLT" mediator. When defining XSLT mediator u have to give exact transform script to run exact mediation function.

Lets consider about some of elements of xslt transform script.
  • Can use following two methods to declare XSL style sheet
<xsl:stylesheet version="1.0"
xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform">

OR

<xsl:transform version="1.0"
xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform">                          
  • <xsl:template> element is used to build templates.
"match" attribute used to associate with XML element. 

 <xsl:template match="/">  ----> This define consider whole document


Examples of match patterns:


<xsl:template match="table">
 
can be applied on any element named table.

<xsl:template match="x/y">

can be applied on any element named y whose parent is an element named x.

<xsl:template match="*">
can be applied to any element.

<xsl:template match="/*">

can be applied only to the top element of an XML document.

<xsl:template match="@*">

can be applied to any attribute.

<xsl:template match="text()">

can be applied to any text node.

<xsl:template match="comment()">

can be applied to any comment node.

<xsl:template match="processing-instruction()">

can be applied to any processing instruction node.

<xsl:template match="node()">

can be applied to any node: element, text, comment or processing instruction.


<xsl: output> element defines the format of the output document


<xsl:output method="xml|html|text|name"

version="string"

encoding="string"

omit-xml-declaration="yes|no"

standalone="yes|no"

doctype-public="string"

doctype-system="string"

cdata-section-elements="namelist"

indent="yes|no"

media-type="string"/>


<xsl:copy> element creates a copy of the current node. 

<xsl:copy use-attribute-sets="name-list">

  <!-- Content:template -->

</xsl:copy>

<xsl:apply-templates> element applies a template to the current element or to the current element's child nodes.

Like wise you can elements. In here, I summarised few of main elements. Value additions are welcome :)

Thursday, April 21, 2016

Starting with git repo

Hey,

I need to create a repository and make a clone of it. Creating a repo in git id easy and you can do it via github UI. I guess you are familiar with github and you may have played with some git repos.

This post will summarize steps of creating a clone in local machine and make a commit using that.
Lets begin...

Preconditions:

  • Have account in github.
  • Installed git in your local machine
  • Have access to repo which is going to clone (Most probably it may be a public or your own one)

Steps to follow:

You have to use following commands:

         git clone <link>
                Ex: git clone https://github.com/Dilshani/BlogStuff.git
     
         git config --global user.email "you@example.com"

         git config --global user.name "Your Name"
 
         git remote add <name for repo> <url of repo>

         git add .         -->  (This will add all new files to commit)

         git commit -m "message"

         git push origin master

Then newly added stuff will be committed to repo. (If you own the repo, you don't need to make a  commit request by github UI. Otherwise, you have to go and make a pull request)

When you are committing files again, you can proceed with "git add" command onwards.

Note: You can add files separately or add all at once.

git add <file name>  ----  > Add file by file

git add .   -----> Add all files at once

Now you know how to add commits to git hub repo. Well Done :)



Sunday, April 10, 2016

[WSO2][ESB][Class Mediator]How to create an Empty OMElement Array?

Hi all,

Let's find out very interesting topic. While using store mediator in ESB, I just wanted to create an empty OMElement array.

If I clarify inside mediation within ESB, when it receive a message, it may convert into OMElements which will is used to next mediation process. Therefore, I can't send empty OMElement array from outside as it is an inside process of ESB (Just like sending SOAP or REST messages).

So we have to convert the message into OMElements within ESB.In my case, I have to add empty OMElement array to the message.

ESB is a marvellous middleware which will provide magical operations. Here it comes "Class Mediator". The Class mediator will retrieve a class and it may act as custom mediator.

So Class Mediator helped me to do my task.

Let's begin...

1) Write a java class which will set OMElement array to the message.

When writing java class which is going to deploy as a "Class Mediator", it must extend from "Abstract Mediator"

In here I used message context (org.apache.synapse.MessageContext) to add empty array.

As a property set new array without any elements.

Sample Configuration

 package org.wso2.test;  
 import java.util.ArrayList;  
 import org.apache.synapse.MessageContext;  
 import org.apache.synapse.mediators.AbstractMediator;  
 public class OMElementEmptyArray  
 extends AbstractMediator {  
   public boolean mediate(MessageContext context) {  
     context.setProperty("EMPTY_ARRAY", new ArrayList());  
     System.out.println("Routed through Class Mediator");  
     return true;  
   }  
 }  

2) Java class packaged as .jar and should be inside $ESB_HOME/repository/components/lib

3) ESB should be up and running.

4) Login to ESB and create an API which will add class mediator.

Sample Configuration:

 <api context="/SerializeProperty" name="StoreMediatorSerialize">  
     <resource methods="GET" protocol="http" url-mapping="/serializeOMArray">  
       <inSequence>  
         <class name="org.wso2.test.OMElementEmptyArray"/>  
       </inSequence>  
       <outSequence/>  
       <faultSequence/>  
     </resource>  
   </api>  

5) Invoke API.

Sample Invocation through REST Client:

GET      http://10.100.7.120:8280/SerializeProperty

Terminal will print follow log:

Routed through Class Mediator


Happy Coding !!!


Thursday, April 7, 2016

[WSO2] [QA] [TestLink] How to write a good Test Case ? (2)

Hey,

Hope you read the first part of this blog post. If not, better to read it first and come to this add more value. Then consider about best practices...

Best Practices:

1) Should not add links in the test case (Important in WSO2 culture, as its' product version release frequently.). If you need something relevant to a document/link add its name, not the link.

Ex:

Not this link : https://docs.wso2.com/display/ESB490/Header+Mediator

Add it as: Refer Header Mediator Documents 

2) Should not add several test steps. Then it will be bored to read.

3) Add short, point form steps to test case. It makes easy to read.

Ex:

Add sequence mediator to the above sequence.
Select "Key Type" as dynamic key 
Give previously created property as Referring sequence.

Ex: {get-property('property')}

4) Add relevant configuration in user-friendly manner (Ex: Adding header mediator with relevant configurations)

Ex: Rather than saying "Create a Header mediator with this and this", you can give configuration as below:

Create a sequence with header mediator which adding "SOAP Header" to incoming SOAP message.

Header Mediator configuration:
  • Name:wsa:newHeader
  • Action:Set
  • Value:Accept
  • Scope:Synapse

[WSO2] [QA] [TestLink] How to write a good Test Case ?

Hello Beginners,

So you may be a beginner or someone who are interesting to improve yourself. Great :) Lets begin...

In my case, I am using Test Link to add test cases. How are we going to write a good test case ?

1) First, you must have the overall idea of what you are going to test and write test cases. So read feature or use case and understand it well.

In my case, I will read documentations and relevant scenarios to learn exact feature.

2) Then design the plan or mind map to test. Through that, you will identify many possible scenarios to test.

As we are human, we may miss some points or testing scenarios. So it will be great if you are using a paper of design to sketch the diagram/design.

Ex:

Aggregate Mediator ----> How we implement Aggregate mediator (Can use iterate/clone mediator)
                                          At where? (In sequence /  out sequence)
                                          What can we do with that? (Aggregate messages/aggregate and put in to one element etc.)
       
Note: It will better to design/sketch diagrams rather than note down. Because visual representations easy to grab and easy to follow.

3) Let's write a test case for identified scenario.

Let's take example from Header Mediator (WSO2 ESB). Through Header mediator, it can handle HTTP headers and SOAP headers. Let's consider "Adding new SOAP header ".

So giving the name of the test case as "Adding new SOAP header for incoming messages".

Name of the test case must identify
  • What is the action we do through the test case (Ex: Adding)
  • What will be the result (Ex: New SOAP header)
  • For what we doing/ Where are we going to do that (Ex: For incoming messages)

4) Then it is the summary. As the name indicate it must summarize what you are going to do through the test case.

It may also include things which considered in the "Name". If something to specify more, you can use the summary to do that. But always it may short and sweet as the "Name" given.

Sample Summary:

This test case will cover adding new SOAP header for messages

5) Then it is "Preconditions".

In here, You must include everything which is required to continue test steps without any problem.

For example: I am testing WSO2 ESB header and it is needed to have ESB server up and running. And other requirements also should be included according to the scenario.

Sample Preconditions:
  • User should be login to ESB with proper credentials
  • Deploy the SimpleStockQuoteService on axis2 server and start axis2 server
6) Let's write test steps. Every step is must be meaningful and must have an expected result.

Add sample configurations to test steps and sample results in expected results.

Sample Test Steps:

Step Action

Create a sequence with header mediator which adding header to incoming SOAP message.

Header Mediator configuration:
  • Name:wsa:newHeader
  • Action:Set
  • Value:Accept
  • Scope:Synapse

Note: As a good practice add relevant configuration in a user friendly manner. Rather than saying "Create a Header mediator with this and this", you can give configuration as above example.

Expected Result

Sequence should be created.

Sample configuration:

<sequence name="seq30" xmlns="http://ws.apache.org/ns/synapse">
    <log level="full">
        <property name="Message" value="==========Before Header========="/>
    </log>
    <header name="wsa:newHeader" scope="default" value="Accept" xmlns:wsa="http://www.w3.org/2005/08/addressing"/>
    <log level="full">
        <property name="Message" value="==========After Header========="/>
    </log>
</sequence>



7) Check twice. Every step you write needed to care about.

Keep maintain less number of test steps while having steps which are easy to read.

Highlight words you want to impress.

8) Add correct status of Test case. After finished your test case, change Status to "Ready for review"

In Test Link, there are several status for test cases:

Draft - When you are working on the test case
Ready for review - Finished test case
Review in progress
Rework - This will add by reviewer if something has to change. And reviewer may add some comments under status saying what should have to change.
Obsolete - When this test case not useful anymore.
Future - In future, must add something. This may be used in improving the feature. After development, it has to update.
Final - Test case is done.

So now we are in Final State of the blog post.

Happy QAing :) :) :)