Dynamically generating response schema and data on the fly

Chris ColosimoChris Colosimo Posts: 71 admin
edited December 2016 in Virtualize

Choice type parameterizaton is not supported currently in SOA/Virt but there is a way that you can work around this. You can dynamically build request/response structure (Schema) and data using a data source.

Define the Data Source

Here is an example of a datasource where I am defining the name of a choice Element and supplying fields that are defined as available for that complex type

In this datasource I am doing 3 things

  • Defining the Name of the choice Type Element
  • Defining the Name and Value of Children Elements
  • Indicating whether the elements will be excluded (More on that later)

From this I can Dynamically build my XML request/response using paramterization and an option called Data Source Exclude with empty String.

Build your responder or Message Client

Here is an example of my request

The first thing I have done is to Parameterize the Element name of the parent Choice type with the choiceName column in the datasource. This will define the parent name with what ever I have defined. Here is what the individual elements look like

I am driving the other 2 types of behavior here

  • Defining the Name and Value of Children Elements
    The Element Name and Values will come from the datasource using parameterization

  • Indicating whether the elements will be excluded
    Notice how I have checked Data Source Exclude with empty String and defined a governing column? This means that the element will not be present (Excluded) from a request if that column is empty.

Here is an example of row 2
<?xml version="1.0" encoding="UTF-8"?> <root> <type> <person> <name>John</name> <age>100</age> </person> </type> </root>

Here is Row 4
<?xml version="1.0" encoding="UTF-8"?> <root> <type> <animal> <type>mammal</type> <age>200</age> <gender>female</gender> </animal> </type> </root>

Notice how the Choice (person/ animal) is being modified as well as the number of children, their structure and value? I have extended this to show nested complexity and attached the .tst and data Source

Comments

Sign In or Register to comment.