Testing logic – the most-used pattern
This is probably the most-used job design in Talend programming, and is used to ensure that a snippet of new code is not influenced by external factors within a large and complex job. This simple recipe shows how this can easily be achieved.
Getting ready
Open the jo_cook_ch10_0140_logicTest
job.
How to do it...
The steps for testing logic are as follows:
- In tFixedFlowInput, tick the box labeled Use Inline Table.
- Add the values, as shown in the following screenshot:
- In the tMap, add a new field to the output named ageCheckValid, and populate it with the following code:
customer.age >= 21 && customer.country.equals("UK") ? true : customer.age >= 18 && !customer.country.equals("UK") ? true : false
- Run the job to see the results of the test.
How it works...
In this example, we are testing an age limit; 21 or over is valid for the UK, 18 or over valid for the rest of the world.
In tFixedFlowInput
, we defined a set of...