Contact Us 1-800-596-4880

Previewing DataMapper Results on Sample Data

Mule Runtime Engine versions 3.5, 3.6, and 3.7 reached End of Life on or before January 25, 2020. For more information, contact your Customer Success Manager to determine how you can migrate to the latest Mule version.

Anypoint™ DataMapper gives you the ability to preview the result of a data mapping flow design by running it on sample input data of your choice. You can also get a live preview in the Graphical view of the Mapping Editor once you define sample input data.

Setting Up DataMapper Preview

To access the preview functionality, select Preview in the Mapping Editor:

image2013-4-10+16:54:44

To provide an input file for preview:

  • Click the ellipsis (…​) button to right of the Input Data field.

  • Browse to the desired input sample data file.

The Input Data file contents depend on the input data type for your DataMapper.

Sample Input for CSV, XML, Fixed Width, JSON or Excel

For the CSV, JSON, XML, and Excel input types, supply an input file of sample data that matches the structure defined in your DataMapper.

For CSV, JSON, Fixed Width, and Excel, by default, the input field contains the name of the input file specified as sample data when setting up DataMapper metadata. You can choose a different file for preview.

Simulating Input for POJO or Map Input

For POJO, Maps, and complex structures like List of Maps, supply a Groovy script that contains a function that returns the required object or collection of objects as input. This script will be executed and the returned object passed into DataMapper.

Groovy is the only scripting language supported. Other JSR-223 scripting languages supported elsewhere in Mule are not supported for creating DataMapper preview data.

For example, consider a DataMapper that accepts as input an object of class InputPojo:

public class InputPojo {
     private String description;
     private Integer id;
     private Long creationTimestamp;
     private String value1;
     private String value2;

     public InputPojo() {
     }
    //getters and setters omitted
    …
}

The following Groovy script creates, populates, and returns an instance of InputPojo, which provides DataMapper the needed input for previewing the results:

import org.mulesoft.dmia.example.InputPojo
InputPojo sample = new InputPojo()
sample.description = "Sample Description"
sample.id = 1000
sample.creationTimestamp = System.currentTimeMillis()
sample.value1 = "Sample Name"
sample.value2 = "Sample un-used value"
return sample

Setting Input Arguments for Preview

To preview output of DataMapper that uses input arguments:

  1. Click the Input Arguments button in the Preview window. A dialog opens listing the input arguments for this DataMapper.

  2. Click the Name column of your sample input to select the input argument to set.

  3. Then click the Value column for that row, and enter your input argument value, which can be any Mule Expression Language expression. Note that you must respect the data types of the input arguments. For example, you must use quotes around any string input value.

  4. Click OK when finished.

    input_args

Running the Mapping Preview

To run the mapping and preview the output, click Run Mapping.

If the mapping executes successfully, the preview results appear in the output window. You can use the tabs to choose between Text and Graphic views of the results:

image2013-4-10+17:9:8

If there is an error in executing the mapping, an error alert appears in the upper left of the preview window:

image2013-4-10+17:32:26

This error can indicate an error in the mapping itself, or a problem with the preview input data or input arguments. For example, an Excel input sheet may have values of the wrong type for an operation in the mapping or a Groovy script may not generate objects of the class or structure that the mapping accept as input.

Click the alert to see more details about the error:

image2013-4-10+17:41:7

If there are multiple errors, they will be listed: select each one to see the error details.

Live Preview in DataMapper Graphical View

Once you have populated your DataMapper with sample data for preview, you will find the Graphical Mapping Editor is updated with in=place live preview based on the first records in the sample data. You will see the input values and the corresponding outputs. This can help you see the effects of mapping design changes as you work, without requiring you to re-run the entire mapping preview.

image2013-4-10+16:35:54