1. Home
  2. Docs
  3. Tips & Tricks
  4. Variables: ANY and Map data type
  5. How to use Map data type

How to use Map data type

A map data type represents an unordered collection of key-value pair elements. To pass map data through transformations, assign map data type to ports. A map element is a key and value pair that maps one thing to another.

The same as voor the ANY type counts for the Map data type. For this to work within the AppTester you will need to add something in the jSon to be able to assert the data of this type. Please check the following table for information.

This table is also available as an Excel download here.

 

Map data IBM BAW AppTester Note
Default template tw.local.inputData = new tw.object.Map();

{

“item”:

{

“key”: “”,
“value”: “”,
“@type”: “String”

}

}

Simple Type
(String, Integer, Boolean,…)
tw.local.inputData = new tw.object.Map();
tw.local.inputData.put(“1”, “Hello”);
tw.local.inputData.put(“2”, 2022);
tw.local.inputData.put(“3”, true);

{

“item”:

{

“key”: “1”,
“value”: “Hello”,
“@type”: “String”

},

“item1”:

{

“key”: “2”,
“value”: “2022”,
“@type”: “Integer”

},

“item2”:

{

“key”: “3”,
“value”: “true”,
“@type”: “Boolean”

},

“item3”:

{

“key”: “4”,
“value”: “0.8”,
“@type”: “Decimal”

},

“item4”:

{

“key”: “5”,
“value”: “T10:00:00.000Z”,
“@type”: “Time”

},

“item5”:

{

“key”: “6”,
“value”: “2020-01-01T00:00:00.000Z”,
“@type”: “Date”

}

}

– Map key in BAW to key in Apptester
– Map value in BAW to value in Apptester
– valueType is the type of value
Complex Object We have the address variable wtih Type Address (refer to the sheet Address)
tw.local.address = {};
tw.local.address.city = ‘HCM’;
tw.local.address.street = ‘NKKN’;
tw.local.address.zipCode = ‘2020’;
and set it to a MAP
tw.local.inputData = new tw.object.Map();
tw.local.inputData.put(“1”, tw.local.address);

{

“item”:

{

“key”: “1”,
“value”:

{

“city”: “HCM”,
“any”:

{

“@type”: “String”,
“value”: “bao test”

},

“map”:

{

“item”:

{

“key”: 1,
“@type”: “String”,
“value”: “bao test”

}

}

},
“@type”: “Address”

}

}

Map Array – Complex

[

{

“item”:

{

“key”: “1”,
“value”:

{

“city”: “HCM”,
“any”:

{

“@type”: “String”,
“value”: “bao test”

},

“map”:

{

“item”:

{

“key”: 1,
“@type”: “String”,
“value”: “bao test”

}

}

},

“@type”: “Address”

}

},
{

“item”:

{

“key”: “1”,
“value”:

{

“age”: 10,
“name”: “employee”

},
“@type”: “ProfileType”

}

}

]

Map Array – Simple

tw.local.arrayMap = new tw.object.listOf.Map();
tw.local.arrayMap[0] = new tw.object.Map();
tw.local.arrayMap[0].put(“1”, “Hello” );
tw.local.arrayMap[0].put(“2”, 0.89 );

tw.local.arrayMap[1] = new tw.object.Map();
tw.local.arrayMap[1].put(“1”, true );
tw.local.arrayMap[1].put(“2”, new TWDate());

[
{

“item”:

{

“key”: “1”,
“value”: “Hello”,
“@type”: “String”

},

“item1”:

{

“key”: “2”,
“value”: “0.89”,
“@type”: “Decimal”

}

},
{

“item”:

{

“key”: “1”,
“value”: “true”,
“@type”: “Boolean”

},

“item1”:

{

“key”: “2”,
“value”: “2022-01-01T00:00:00.000Z”,
“@type”: “Date”

}

}
]

OR

[
{

“item”:

{

“key”: “1”,
“value”: [“Hello”, “Word”],
“@type”: “String[]”

},

“item1”:

{

“key”: “1”,
“value”: [“Good”, “Morning”],
“@type”: “String”

},

“item2”:

{

“key”: “2”,
“value”: [0.89, 1],
“@type”: “Decimal”

}

}
]

– If the type is list of String or Integer,…. we can input the @type = X[] with X is simple type
eg:
“item”: {
“key”: “1”,
“value”: [“Hello”, “Word”],
“@type”: “String[]” // with []
}
or without []
“item”: {
“key”: “1”,
“value”: [“Hello”, “Word”],
“@type”: “String” // without []
}

==> it’s good with [] or without []

Object include Map

{

“city”: “HCM”,
“zipCode”: “70000”,
“street”: “NKKN”,
“any”:

{

},

“date”: “1970-01-01T00:00:00.000Z”,
“map”:

{
“item”:

{

“key”: “1”,
“value”: “hello”,
“@type”: “String”

}

},
“time”: “T00:00:00.000Z”

}

 

Asserting data

For the map type, asserting the data is using the name of the assert to navigate to the variable you want to assert. For example:

This can be asserted in the assert tab as follows:

Was this article helpful to you? Yes No

How can we help?