public final class DataProviderHelper extends Object
ExcelDataProviderImpl
and YamlDataProviderImpl
and XmlDataProviderImpl
.Modifier and Type | Method and Description |
---|---|
static Object |
convertJsonStringToObject(String jsonString,
Type typeToMap)
Utility method to convert raw Json strings into a type.
|
static Object[][] |
convertToObjectArray(Object object)
Converts any object into 2 dimensional array representing TestNG DataProvider.
|
static List<Object[]> |
filterToListOfObjects(Object object,
DataProviderFilter dataFilter)
Converts in particular LinkedHashMap of Objects, ArrayList of Objects, Array of Object into ArrayList after
applying the given filter.
|
static Object[][] |
getAllDataMultipleArgs(Object[][]... dataproviders)
Converts multiple data from multiple 2D DataProvider arrays of various types into one DataProvider 2D array.
|
static Object[][] |
getAllDataMultipleArgsFromYAML(List<DataResource> resources)
Gets yaml data for tests that require multiple arguments.
|
static Object[][] |
getDataByKeys(Map<?,?> map,
String[] keys)
Filters a map by keys specified as a list.
|
static int[] |
parseIndexString(String value)
This function will parse the index string into separated individual indexes as needed.
|
static <T> List<T> |
readListByXpath(Object object,
Class<T> cls,
String xpath)
Traverses the object graph by following an XPath expression and returns a list of desired type from object
matched at the XPath.
|
static <T> T |
readObjectByXpath(Object object,
Class<T> cls,
String xpath)
Traverses the object graph by following an XPath expression and returns the desired type from object matched at
the XPath.
|
static String |
serializeObjectToYamlString(Object object)
Use this utility method to print and return a yaml string to help serialize the object passed in.
|
static String |
serializeObjectToYamlStringAsDocuments(Object... objects)
Use this utility method to print and return a yaml string to help serialize the object passed in as a
LinkedHashMap.
|
static String |
serializeObjectToYamlStringAsList(Object... objects)
Use this utility method to print and return a yaml string to help serialize the object passed in as an ArrayList.
|
static String |
serializeObjectToYamlStringAsMap(Object... objects)
Use this utility method to print and return a yaml string to help serialize the object passed in as multiple
documents.
|
public static int[] parseIndexString(String value)
DataProviderException
.value
- the input string represent the indexes to be parse.public static Object[][] convertToObjectArray(Object object)
object
, in the order the object
is
processed:
Object - By default, an object is returned at position [0][0] of Object[1][1].
LinkedHashMap - When
the root type of object is a LinkedHashMap
(with n number of key-value mappings), the value at each
index of the map is returned at position [index][0] of Object[n][1].
ArrayList - When the root type of object is anArrayList
(with n number of items), the item at each index of the list is returned at position [index][0] of Object[n][1]. When the value isLinkedHashMap
having child value as type ofLinkedHashMap
orArrayList
, the child value is returned instead.
Array of primitive types - When
the root type of object is single dimensional Array
(with n number of items), the value at each
index of the array is returned at position [index][0] of Object[n][1].
Array of Object types - When
the root type of object is single dimensional Array
(with n number of objects), the object at each
index of the array is returned at position [index][0] of Object[n][1].
object
- Object of any type.public static List<Object[]> filterToListOfObjects(Object object, DataProviderFilter dataFilter)
object
- Object of any type.public static Object[][] getDataByKeys(Map<?,?> map, String[] keys)
map
- The Map containing keys.keys
- Non-empty array of string keys.IllegalArgumentException
- When the argument to keys
is null, or any keys is not contained by the map
.public static Object[][] getAllDataMultipleArgs(Object[][]... dataproviders)
public static Object[][] dataProviderGetMultipleArguments() throws IOException { Object[][] data = null; FileSystemResource resource1 = new FileSystemResource(pathName, listOfUsersInYaml, User.class); FileSystemResource resource2 = new FileSystemResource(pathName, listOfAddressesInXml, Address.class); Object[][] data1 = YamlDataProvider.getAllData(resource1); Object[][] data2 = XmlDataProvider.getAllData(resource2); data = new DataProviderHelper.getAllDataMultipleArgs(data1, data2); return data; }Test method signature example 1:
public void testExample(User user, Address address)Test method signature example 2:
public void testExample(User fromUser, User toUser)Test method signature example 2:
public void testExample(User user, Address address, CreditCardInfo creditCard)
dataproviders
- An array of multiple 2D DataProvider arrays of various types that are to be clubbed together.public static Object convertJsonStringToObject(String jsonString, Type typeToMap)
public static <T> T readObjectByXpath(Object object, Class<T> cls, String xpath)
readListByXpath(Object, Class, String)
.
Note: Need object
and cls
to have getter and setter properties defined to allow object graph
traversal.object
- An object of any typecls
- Type of the property being evaluated at the given xpath
.xpath
- The XPath expression equivalent to the object graph.public static <T> List<T> readListByXpath(Object object, Class<T> cls, String xpath)
readObjectByXpath(Object, Class, String)
for single object retrieval.
Note: Need object
and cls
to have getter and setter properties defined to allow object graph
traversal.object
- An object of any typecls
- Type of the property being evaluated at the given xpath
.xpath
- The XPath expression equivalent to the object graph.public static String serializeObjectToYamlString(Object object)
object
- The Object that is to be serialised.public static String serializeObjectToYamlStringAsList(Object... objects)
objects
- One or more objects that are to be serialised.public static String serializeObjectToYamlStringAsDocuments(Object... objects)
objects
- One or more objects that are to be serialised.public static String serializeObjectToYamlStringAsMap(Object... objects)
objects
- The objects that are to be serialised.public static Object[][] getAllDataMultipleArgsFromYAML(List<DataResource> resources) throws IOException
public static Object[][] dataProviderGetMultipleArguments() throws IOException { Object[][] data = null; List<YamlResource> yamlResources = new ArrayList<YamlResource>(); yamlResources.add(new YamlResource(pathName, userDocuments, USER.class)); yamlResources.add(new YamlResource(pathName, user2Documents, USER.class)); data = DataProviderHelper.getAllDataMultipleArgsFromYAML(yamlResources); return data; }Test method signature example:
public void testExample(USER user1, USER user2)
IOException
Copyright © 2016 PayPal Open Source. All rights reserved.