Search in sources :

Example 1 with SerialDataSourceTestCase

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!;"}));
}
Also used : TestSerialPortProxy(com.infiniteautomation.serial.TestSerialPortProxy) TestSerialPortInputStream(com.infiniteautomation.serial.TestSerialPortInputStream) TestSerialPortOutputStream(com.infiniteautomation.serial.TestSerialPortOutputStream) SerialDataSourceTestCase(com.infiniteautomation.serial.SerialDataSourceTestCase) Before(org.junit.Before)

Example 2 with SerialDataSourceTestCase

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());
    }
}
Also used : PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) SerialDataSourceTestCase(com.infiniteautomation.serial.SerialDataSourceTestCase) SerialPortException(com.infiniteautomation.mango.io.serial.SerialPortException) SerialPortProxyEvent(com.infiniteautomation.mango.io.serial.SerialPortProxyEvent) Test(org.junit.Test)

Aggregations

SerialDataSourceTestCase (com.infiniteautomation.serial.SerialDataSourceTestCase)2 SerialPortException (com.infiniteautomation.mango.io.serial.SerialPortException)1 SerialPortProxyEvent (com.infiniteautomation.mango.io.serial.SerialPortProxyEvent)1 TestSerialPortInputStream (com.infiniteautomation.serial.TestSerialPortInputStream)1 TestSerialPortOutputStream (com.infiniteautomation.serial.TestSerialPortOutputStream)1 TestSerialPortProxy (com.infiniteautomation.serial.TestSerialPortProxy)1 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)1 Before (org.junit.Before)1 Test (org.junit.Test)1