use of org.apache.edgent.function.Consumer in project plc4x by apache.
the class PlcConnectionAdapterTest method testNewConsumer2.
/*
* test PlcConnectionAdapter.newJsonConsumer(addressFn, valueFn)
*/
@Test
@Category(FastTests.class)
public void testNewConsumer2() throws Exception {
String addressStr = "MyReadWriteAddress/0";
MockField address = new MockField(addressStr);
PlcConnectionAdapter adapter = new PlcConnectionAdapter(getMockConnection());
MockConnection connection = (MockConnection) adapter.getConnection();
Consumer<JsonObject> consumer;
Function<JsonObject, String> addressFn = t -> t.get("address").getAsString();
/*consumer = adapter.newJsonConsumer(Boolean.class, addressFn, t -> t.get("value").getAsBoolean());
checkConsumerJson(connection, address, consumer, true, false);
consumer = adapter.newJsonConsumer(Byte.class, addressFn, t -> t.get("value").getAsByte());
checkConsumerJson(connection, address, consumer, (byte) 0x1, (byte) 0x2, (byte) 0x3);
consumer = adapter.newJsonConsumer(Short.class, addressFn, t -> t.get("value").getAsShort());
checkConsumerJson(connection, address, consumer, (short) 1, (short) 2, (short) 3);
consumer = adapter.newJsonConsumer(Integer.class, addressFn, t -> t.get("value").getAsInt());
checkConsumerJson(connection, address, consumer, 1000, 1001, 1002);
consumer = adapter.newJsonConsumer(Float.class, addressFn, t -> t.get("value").getAsFloat());
checkConsumerJson(connection, address, consumer, 1000.5f, 1001.5f, 1002.5f);
consumer = adapter.newJsonConsumer(String.class, addressFn, t -> t.get("value").getAsString());
checkConsumerJson(connection, address, consumer, "one", "two", "three");*/
adapter.close();
}
use of org.apache.edgent.function.Consumer in project plc4x by apache.
the class PlcConnectionAdapterTest method testNewConsumer2Neg.
/*
* test PlcConnectionAdapter.newJsonConsumer(addressFn, valueFn) with write failure
*/
@Test
@Category(FastTests.class)
public void testNewConsumer2Neg() throws Exception {
String addressStr = "MyReadWriteAddress/0";
MockField address = new MockField(addressStr);
PlcConnectionAdapter adapter = new PlcConnectionAdapter(getMockConnection());
MockConnection connection = (MockConnection) adapter.getConnection();
Consumer<JsonObject> consumer;
Function<JsonObject, String> addressFn = t -> t.get("address").getAsString();
/*consumer = adapter.newJsonConsumer(String.class, addressFn, t -> t.get("value").getAsString());
checkConsumerJson(2, connection, address, consumer, "one", "two", "three");*/
adapter.close();
}
use of org.apache.edgent.function.Consumer in project plc4x by apache.
the class PlcFunctionsTest method testNewConsumer2.
/*
* test PlcConnectionAdapter.newJsonConsumer(addressFn, valueFn)
*/
@Test
@Category(FastTests.class)
public void testNewConsumer2() throws Exception {
String addressStr = "MyReadWriteAddress/0";
MockField address = new MockField(addressStr);
PlcConnectionAdapter adapter = new PlcConnectionAdapter(getMockConnection());
MockConnection connection = (MockConnection) adapter.getConnection();
Consumer<JsonObject> consumer;
Function<JsonObject, String> addressFn = t -> t.get("address").getAsString();
consumer = PlcFunctions.booleanConsumer(adapter, addressFn, t -> t.get("value").getAsBoolean());
PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, true, false);
consumer = PlcFunctions.byteConsumer(adapter, addressFn, t -> t.get("value").getAsByte());
PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, (byte) 0x1, (byte) 0x2, (byte) 0x3);
consumer = PlcFunctions.shortConsumer(adapter, addressFn, t -> t.get("value").getAsShort());
PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, (short) 1, (short) 2, (short) 3);
consumer = PlcFunctions.integerConsumer(adapter, addressFn, t -> t.get("value").getAsInt());
PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, 1000, 1001, 1002);
consumer = PlcFunctions.floatConsumer(adapter, addressFn, t -> t.get("value").getAsFloat());
PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, 1000.5f, 1001.5f, 1002.5f);
consumer = PlcFunctions.stringConsumer(adapter, addressFn, t -> t.get("value").getAsString());
PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, "one", "two", "three");
adapter.close();
}
Aggregations