This post guides how to create a maven project from the scratch and integrate it with TestNG. If you are a beginner at test automation, this post may help you.

Image for post
Image for post

Setting up Eclipse

  1. Download Eclipse from here, make sure you select Eclipse for Java Developers.
  2. Make sure you install testng plugin for Eclipse from Eclipse Market space. Help -> Eclipse Marketspace and search for testng, and install it

Creating a Maven Project

  1. Let’s first create a maven project. Go to File -> New -> Project -> Maven Project.
  2. Let’s create a project from an archetype. An archetype is nothing but a template. …

Image for post
Image for post

Paxos algorithm is used to achieve consensus among a distributed set of computers that communicate via an asynchronous network.

We will understand the Paxos Algorithm by taking a simple problem such as detecting Prime Numbers in a distributed environment.

In order to start the consensus, first, we need to have a coordinator node in our cluster. It is explained in my previous article how can we decide the master node in a distributed environment using the Bully Algorithm. You can check that here.

Once the master node is decided, it starts its work as described below.

  • Firstly master node checks the service registry and figures out the active nodes in the cluster. …

This blog post explains the end to end implementation of the Bully Algorithm which is a leader election algorithm in Distributed Systems.

Image for post
Image for post

What is a Distributed System

A distributed system is a collection of independent computers that appears to its users as a single coherent system.

These multiple nodes are physically separate but linked with each other. They communicate with each other to complete each others’ and one end goal.

Distributed Algorithms

Distributed Algorithms run in a Distributed System. We have two types of Distributed algorithms which are Leader Election Algorithms and Consensus Algorithms.

In a clustered system, Leader Election Algorithms helps nodes to decide who the leader of the system is. …


Image for post
Image for post

Assume that your actual Rest API gets a number of identical hits, but actually that Rest Endpoint expects only one hit in order to proceed with the rest of the work!

How to handle this?

In Python, we can handle the scenario by developing a proxy.

Assume that our actual API resides at ‘http://localhost:6001/response’

But we need to send only one request to this API, but actually it getting hit by 100 calls. In order to avoid this, we can make this simple trick.

Create another API as below and count the number of hits.

@app.route('/proxy', methods=['POST'])
def proxy():
with counter.get_lock():
counter.value += 1
unique_count = counter.value

url = 'http://localhost:6001/response'
if unique_count == 1:
data = request.get_json() …


Image for post
Image for post

We can invoke APIs using a request payload or sending them in the URL as query parameters.

We can do several operations using the property mediator with the query parameters.

Verify if the query params exist in the URL.

We can check this using a simple property as below. Assume my URL is as below. We can check if all these query params exist in the URL. The query params in this URL are name, term, and amount.

http://localhost:8290/api?name=isruu&term=30&amount=250000

You can further read about Query Parameters from this doc.

Let’s look at the following scenario. Assume the user enters the customer name, term, and loan amount in the request as above. …


Using WSO2 Enrich mediator

Assume we need to copy a whole message context to a property for further use. As an example, if we use Amazon SQS Connector, we may need that message to send it to a Queue as the message body, but we need to pass it as a property. How can we achieve this?

Let’s assume that we are building a message which needs to be passed to the SimpleStockQuote. The request simply follows like this.

<m0:getQuote xmlns:m0="http://services.samples">
<m0:request>
<m0:symbol>WSO2</m0:symbol>
</m0:request>
</m0:getQuote>

Thinking from the ease of the user, we do not want the user to send this message as the input. Therefore we ask from the user only the value for the symbol parameter. …


By default XPath 2.0 functions are disabled in WSO2 EI. In this post, we will look at how can we use them in EI 6 and EI7.

Image for post
Image for post

Enable XPath 2.0 in WSO2 EI 7

  1. Download WSO2 EI 7 from here.
  2. Go to <PRODUCT-HOME>/conf/deployment.toml file and add the following.
[mediation]
synapse.enable_xpath_dom_failover="true"

Enable XPath 2.0 in WSO2 EI 6

  1. Download WSO2 EI 6 from here.
  2. Go to <PRODUCT-HOME>/conf/synapse.properties file uncomment the following.
synapse.xpath.dom.failover.enabled=true

Example

Assume we get the following request payload from the user.

The QueueURL contains QueueId and the QueueName. Assume we need to extract only the QueueId which is ‘728847610545’.

We can simply substring the URL by using XPath 2.0 functions. …


We can build messages via sending parameters in the URL or as a payload as a POST request. In both ways, we can build a customized message using Payload Factory.

Image for post
Image for post

Prerequisites

  • Start the SimpleStockQuote Service since we use this as our backend.

Starting SimpleStockQuote Service

  1. Download WSO2 EI 6.6.0 Distribution from here.
  2. Go to <PRODUCT-HOME>/samples/axis2Server and run the following command to start the axis2Server.
./axis2Server.sh

3. Go to <PRODUCT-HOME>/samples/axis2Server/src/SimpleStockQuoteService folder and build it using the following command.

ant

Sending as the Payload as a POST request

Let’s move to our first scenario.

Below will be the payload that the user needs to send.

{
"companyName":"WSO2"
}

Below is the API. You can build the API using the WSO2 Integration Studio. …


This tutorial guides you on how to expose the data in a CSV file as a data service using WSO2 Integration Studio and WSO2 Micro Integrator.

Image for post
Image for post
Picture Courtesy: Lynda.com

Creating the Data Service using WSO2 Integration Studio

  1. Download and install the WSO2 Integration Studio from here.
  2. From the Getting Started page, you can select Create Data Service Project in the Data Service tab. (If you do not see this page, you can get this through Help -> Getting Started) Provide a name for the Data Service Project and click on Finish.
Image for post
Image for post

3. Right-click on the created Data Service project and select, New -> Data Service.

Image for post
Image for post

4. Provide the Data Service name as CSVDataService, and select the transports as HTTP, HTTPS, and Local. …


Using WSO2 Gmail Connector we can achieve the above the use case just with a simple GET request.

Image for post
Image for post

The Scenario

This scenario contains a service that can be invoked through an HTTP GET request. Once the service is invoked, it returns the contents of unread emails in the Inbox under the label ‘customers’, while sending an automated response to the customers, thanking them for their feedback.

Configuring the Gmail API

Obtaining Client ID and Client Secret

  1. Navigate to API Credentials Page and sign in with your Google account.
  2. Click Select a Project and click NEW PROJECT, to create a project.
Image for post
Image for post

3. Enter GmailConnector as the name of the project and click Create.

Image for post
Image for post

4. Click Configure consent screen in the next screen. …

About

Isuru Uyanage

Software Engineer — QA at WSO2

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store