javajavapos

How to test and emulate the peripherals with JPOS library


We are new to JPos Library, and we wanted to automate testcases which needs peripheral interactions.

To automate the tests with multiple scenarios, we wanted to bypass the connected peripherals and give mock values to our application.

For e.g. We have a connected 'Scale' to measure the weight, and we wanted to mock the value read from the scale, so that this method,

scale.getWeightUnit()

returns our mock value.

Is it possible in JPos with some configurations?


Solution

  • Jpos library uses the service class mentioned in jpos.xml These service class can be in an external pos.jar ( should be in classpath) and created during runtime. e.g IBM gives a ibmpos.jar file, which has service implemnetation to talk to the peripherals.

    So to mock the services, edit the jpos.xml file, create your own service implementation to return the mock values and add the implementation classes in classpath.

    and also you need to fire the dataOccured event in the service implementation class to mock the hardware event (e.g. to mock scanned event for a scanner)