use of com.infiniteautomation.serial.SerialDataSourceTestCase in project ma-modules-public by infiniteautomation.
the class SerialDataSourceTest method setup.
@Before
public void setup() {
this.proxy = new TestSerialPortProxy(new TestSerialPortInputStream(), new TestSerialPortOutputStream());
Common.serialPortManager = new SerialDataSourceSerialPortManager(proxy);
vo = SerialDataSourceTestData.getStandardDataSourceVO();
rt = (SerialDataSourceRT) vo.createDataSourceRT();
testCases.put("Hello World!;", new SerialDataSourceTestCase(SerialDataSourceTestData.getMatchAllPoint(vo), "terminator", ";", 1, new String[] { "Hello World!;" }));
testCases.put("8812;abcf;", new SerialDataSourceTestCase(SerialDataSourceTestData.getMatchAllPoint(vo), "terminator", ";", 2, new String[] { "8812;", "abcf;" }));
testCases.put("", new SerialDataSourceTestCase(SerialDataSourceTestData.getMatchAllPoint(vo), "terminator", ";", 0, new String[] {}));
testCases.put("testStr\n\nabs", new SerialDataSourceTestCase(SerialDataSourceTestData.getNewlineTerminated(vo), "terminator", "\n", 2, new String[] { "testStr", "" }));
testCases.put("ok;", new SerialDataSourceTestCase(SerialDataSourceTestData.getMatchAllPoint(vo), "terminator", ";", 1, new String[] { "ok;" }));
// Clean out the timer's tasks
time = System.currentTimeMillis() - 1000000;
timer.setStartTime(time);
// TODO requiring more mocks for timers testCases.put("Hello World!;", new SerialTestCase("timeout", ";", 1, new String[]{"Hello World!;"}));
}
use of com.infiniteautomation.serial.SerialDataSourceTestCase in project ma-modules-public by infiniteautomation.
the class SerialDataSourceTest method testReadPointValue.
@Test
public void testReadPointValue() {
// Connect
try {
assertTrue(rt.connect());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
for (String s : testCases.keySet()) {
SerialDataSourceTestCase stc = testCases.get(s);
rt.addDataPoint(stc.getTargetPoint());
if (stc.getCondition().equals("terminator")) {
vo.setMessageTerminator(stc.getTerminator());
vo.setUseTerminator(true);
} else if (stc.getCondition().equals("timeout")) {
vo.setUseTerminator(false);
}
// load a test input
proxy.getTestInputStream().pushToMockStream(s);
// Create an event to force the Data Source to read the port
SerialPortProxyEvent evt = new SerialPortProxyEvent(timer.currentTimeMillis());
rt.serialEvent(evt);
// Fast Forward to fire any events
time = time + 5;
timer.fastForwardTo(time);
List<PointValueTime> pvts = Lists.reverse(stc.getTargetPoint().getLatestPointValues(stc.getNewValueCount()));
boolean found;
for (int k = 0; k < stc.getResults().length; k += 1) {
found = false;
for (int i = 0; i < pvts.size(); i += 1) {
if (stc.getResult(k).equals(pvts.get(i).getStringValue()))
found = true;
}
if (!found)
fail("No value match found for: '" + stc.getResult(k) + "' point value");
}
// Remove the point for the next test
rt.removeDataPoint(stc.getTargetPoint());
}
}
Aggregations