Arcones
Arcones

Reputation: 4642

How to test a Mule application flow?

I have been assigned with the following task regarding a Mule flow application currently in production:

I have knowledge in Java core and SQL but null background with Mule. All the people that I can ask are in the same situation.

Once I get the app package (the one that is currently in production) up and running, I have stopped it and add the following elements to the flow:

  1. In a subflow with some initial tasks, I have addded a database element to store the IP of the computer which is using the webservice (The user_request is a table I have just created in the DB which stores the IP and date of connection.):

insert into user_request values (#[MULE_REMOTE_CLIENT_ADDRESS], #[function:datestamp:dd-MM-yy])

  1. To ask the website, a database element performs a select query to provide a choice with some inputs. Depending on the value of those inputs the request is done to the website or not:

Database (Select) --> Choice --> Ask or not to the website depending on the select output

So, there, I have added to the database element that performs the select and additional output that is a count of user_request table for current IP and current day so it can provide the choice with the original inputs as usual and also this extra one (I am copying only the suquery I added):

SELECT COUNT(*) as TRIES FROM USER_REQUEST 
WHERE IP_ADDRESS=#[MULE_REMOTE_CLIENT_ADDRESS] 
AND REQUEST_DATE=#[function:datestamp:dd-MM-yy] 
  1. In the choice, I have added this condition to the path that finally ask the website:

#[payload.get(0).TRIES < 10]

Reached this point, the app runs and give no errors but I don't know how to test it. Where does the flow start? How can I test it as I was the user?

Aditionally, if you see anything wrong in the syntax I used above, I would appreciate if you tell me.

Thanks in advance!!!

Upvotes: 0

Views: 87

Answers (1)

dlb
dlb

Reputation: 357

munit will require you to learn the basics of this process first, but it is the primary testing tool of mule. With it, you will create a test suite to execute various flows and verify that when given know inputs the correct processing occur in a repeatable manner. In the test, you can mock critical calls, such as a write to your DB so that the actual is called but not actually done so as to not modify your DB table. Likewise, on reads from the DB you can either actually make a call to get known data, or returned mocked test data to exercise all paths in the flow.

Upvotes: 3

Related Questions