org.easetech.easytest.loader
Class XMLDataLoader

java.lang.Object
  extended by org.easetech.easytest.loader.XMLDataLoader
All Implemented Interfaces:
Loader

public class XMLDataLoader
extends Object
implements Loader

An implementation of Loader for the XML based files. This Loader is responsible for reading a list of XML Files based on the testDataSchema.xsd file of EasyTest and converting them into a data structure which is understandable by the EasyTest framework. The Loader is also responsible for writing the output data back to the file.
The XML data can be provided by the user in the following format :

<easytest:InputTestData xmlns:easytest="urn:org:easetech:easytest:1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:org:easetech:easytest:1.0 testDataSchema.xsd">
<TestMethod name="getSimpleData">
  <TestRecord id="1">
  <InputData>
   <Entry key="libraryId" value="91475" />
   <Entry key="itemId" value="12" />
   <Entry key="itemType" value="book" />
  </InputData>
  </TestRecord>
  <TestRecord id="2">
  <InputData>
   <Entry key="libraryId" value="234" />
   <Entry key="itemId" value="1452" />
   <Entry key="itemType" value="journal" />
  </InputData>
  </TestRecord>
</TestMethod>
<TestMethod name="getAnotherData">
  <TestRecord id="3">
  <InputData>
   <Entry key="picId" value="1111" />
   <Entry key="picNum" value="12" />
   <Entry key="picFormat" value="jpeg" />
  </InputData>
  </TestRecord>
  <TestRecord id="4">
  <InputData>
   <Entry key="picId" value="1561" />
   <Entry key="picNum" value="178" />
   <Entry key="picFormat" value="raw" />
  </InputData>
  </TestRecord>
</TestMethod>
</easytest:InputTestData>

As you can guess, the root element is InputTestData that can have multiple TestMethod elements in it.
Each TestMethod element identifies a method to test with its name attribute.
Each TestMethod can have many TestRecords. Each Record identifies data for a single test execution.
Each TestRecord element has an id attribute. This id attribute has to be unique in the entire XML file. So you should not have the id = 1 for more than one test record. If you do, then the behavior is undefined in such a scenario.
TestRecord contains InputData element as well as OutputData element. A user never specifies an OutputData element. If it is specified, it will be ignored by the Loader. OutputData is used internally by the XMLDataLoader to write output data back to the file. Each Entry element identifies a method parameter.

Author:
Anuj Kumar

Field Summary
protected static org.slf4j.Logger LOG
          An instance of logger associated with the test framework.
 
Fields inherited from interface org.easetech.easytest.loader.Loader
ACTUAL_RESULT, AMPERSAND, COMMA, DOUBLE_QUOTE, DURATION, EMPTY_STRING, EXPECTED_RESULT, SINGLE_QUOTE, TEST_FAILED, TEST_PASSED, TEST_STATUS
 
Constructor Summary
XMLDataLoader()
           
 
Method Summary
 Map<String,List<Map<String,Object>>> loadData(Resource resource)
          Load the data from the given resource
 void writeData(Resource resource, Map<String,List<Map<String,Object>>> actualData, String... methodNames)
          Write Data to the existing XML File.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static final org.slf4j.Logger LOG
An instance of logger associated with the test framework.

Constructor Detail

XMLDataLoader

public XMLDataLoader()
Method Detail

loadData

public Map<String,List<Map<String,Object>>> loadData(Resource resource)
Load the data from the given resource

Specified by:
loadData in interface Loader
Parameters:
resource - the instance of the resource from which to load the data
Returns:
the loaded data

writeData

public void writeData(Resource resource,
                      Map<String,List<Map<String,Object>>> actualData,
                      String... methodNames)
Write Data to the existing XML File.

Specified by:
writeData in interface Loader
Parameters:
resource - to which the data needs to be written
methodNames - the name of the methods to write data for
actualData - the actual data that needs to be written to the file.


Copyright © 2013. All Rights Reserved.