use of org.apache.plc4x.java.mock.connection.MockConnection in project plc4x by apache.
the class PlcConnectionAdapterTest method testCtor1.
/*
* Test the PlcConnectionAdapter(PlcConnection) ctor, getConnection() and close()
*/
@Test
@Category(FastTests.class)
public void testCtor1() throws Exception {
MockConnection mockConnection = getMockConnection();
PlcConnectionAdapter adapter = new PlcConnectionAdapter(mockConnection);
assertThat(mockConnection, sameInstance(adapter.getConnection()));
// and again... multiple adapter.getConnection() returns the same
assertThat(mockConnection, sameInstance(adapter.getConnection()));
adapter.close();
}
use of org.apache.plc4x.java.mock.connection.MockConnection in project plc4x by apache.
the class PlcConnectionAdapterTest method testNewPlcWriteRequest.
/*
* Verify the adapter yields the appropriate PlcWriteRequest for each type and that it works.
*/
@Test
@Category(FastTests.class)
public void testNewPlcWriteRequest() throws Exception {
String addressStr = "MyReadWriteAddress/0";
MockField address = new MockField(addressStr);
PlcConnectionAdapter adapter = new PlcConnectionAdapter(getMockConnection());
MockConnection connection = (MockConnection) adapter.getConnection();
/*{
TypeSafePlcWriteRequest<Boolean> request = PlcConnectionAdapter.newPlcWriteRequest(address, true);
PlcWriteRequestItem<Boolean> requestItem = request.getCheckedRequestItems().get(0);
Class<Boolean> dataType = requestItem.getDatatype();
assertThat(dataType, typeCompatibleWith(Boolean.class));
assertThat(address, sameInstance(requestItem.getField()));
checkWrite(connection, request, true);
}
{
TypeSafePlcWriteRequest<Byte> request = PlcConnectionAdapter.newPlcWriteRequest(address, (byte) 0x113);
PlcWriteRequestItem<Byte> requestItem = request.getCheckedRequestItems().get(0);
Class<Byte> dataType = requestItem.getDatatype();
assertThat(dataType, typeCompatibleWith(Byte.class));
assertThat(address, sameInstance(requestItem.getField()));
checkWrite(connection, request, (byte) 0x113);
}
{
TypeSafePlcWriteRequest<Short> request = PlcConnectionAdapter.newPlcWriteRequest(address, (short) 113);
PlcWriteRequestItem<Short> requestItem = request.getCheckedRequestItems().get(0);
Class<Short> dataType = requestItem.getDatatype();
assertThat(dataType, typeCompatibleWith(Short.class));
assertThat(address, sameInstance(requestItem.getField()));
checkWrite(connection, request, (short) 113);
}
{
TypeSafePlcWriteRequest<Integer> request = PlcConnectionAdapter.newPlcWriteRequest(address, 1033);
PlcWriteRequestItem<Integer> requestItem = request.getCheckedRequestItems().get(0);
Class<Integer> dataType = requestItem.getDatatype();
assertThat(dataType, typeCompatibleWith(Integer.class));
assertThat(address, sameInstance(requestItem.getField()));
checkWrite(connection, request, 1033);
}
{
TypeSafePlcWriteRequest<Float> request = PlcConnectionAdapter.newPlcWriteRequest(address, 1043.5f);
PlcWriteRequestItem<Float> requestItem = request.getCheckedRequestItems().get(0);
Class<Float> dataType = requestItem.getDatatype();
assertThat(dataType, typeCompatibleWith(Float.class));
assertThat(address, sameInstance(requestItem.getField()));
checkWrite(connection, request, 1043.5f);
}
{
TypeSafePlcWriteRequest<String> request = PlcConnectionAdapter.newPlcWriteRequest(address, "A written value");
PlcWriteRequestItem<String> requestItem = request.getCheckedRequestItems().get(0);
Class<String> dataType = requestItem.getDatatype();
assertThat(dataType, typeCompatibleWith(String.class));
assertThat(address, sameInstance(requestItem.getField()));
checkWrite(connection, request, "A written value");
}
{
Calendar calValue = Calendar.getInstance();
TypeSafePlcWriteRequest<Calendar> request = PlcConnectionAdapter.newPlcWriteRequest(address, calValue);
PlcWriteRequestItem<Calendar> requestItem = request.getCheckedRequestItems().get(0);
Class<Calendar> dataType = requestItem.getDatatype();
assertThat(dataType, typeCompatibleWith(Calendar.class));
assertThat(address, sameInstance(requestItem.getField()));
checkWrite(connection, request, calValue);
}*/
adapter.close();
}
use of org.apache.plc4x.java.mock.connection.MockConnection in project plc4x by apache.
the class PlcConnectionAdapterTest method testNewConsumer1Neg.
/*
* test PlcConnectionAdapter.newJsonConsumer(address) with write exception
*/
@Test
@Category(FastTests.class)
public void testNewConsumer1Neg() throws Exception {
String addressStr = "MyReadWriteAddress/0";
MockField address = new MockField(addressStr);
PlcConnectionAdapter adapter = new PlcConnectionAdapter(getMockConnection());
MockConnection connection = (MockConnection) adapter.getConnection();
Consumer<?> consumer;
/*consumer = adapter.newConsumer(String.class, addressStr);
checkConsumer(2, connection, address, consumer, "one", "two", "three");*/
adapter.close();
}
use of org.apache.plc4x.java.mock.connection.MockConnection in project plc4x by apache.
the class PlcConnectionAdapterTest method testNewConsumer1.
/*
* test PlcConnectionAdapter.newJsonConsumer(address)
*/
@Test
@Category(FastTests.class)
public void testNewConsumer1() throws Exception {
String addressStr = "MyReadWriteAddress/0";
MockField address = new MockField(addressStr);
PlcConnectionAdapter adapter = new PlcConnectionAdapter(getMockConnection());
MockConnection connection = (MockConnection) adapter.getConnection();
Consumer<?> consumer;
/*consumer = adapter.newConsumer(Boolean.class, addressStr);
assertThat(consumer, not(sameInstance(adapter.newConsumer(Boolean.class, addressStr))));
checkConsumer(connection, address, consumer, true, false);
consumer = adapter.newConsumer(Byte.class, addressStr);
checkConsumer(connection, address, consumer, (byte) 0x1, (byte) 0x2, (byte) 0x3);
consumer = adapter.newConsumer(Short.class, addressStr);
checkConsumer(connection, address, consumer, (short) 1, (short) 2, (short) 3);
consumer = adapter.newConsumer(Integer.class, addressStr);
checkConsumer(connection, address, consumer, 1000, 1001, 1002);
consumer = adapter.newConsumer(Float.class, addressStr);
checkConsumer(connection, address, consumer, 1000.5f, 1001.5f, 1002.5f);
consumer = adapter.newConsumer(String.class, addressStr);
checkConsumer(connection, address, consumer, "one", "two", "three");*/
adapter.close();
}
use of org.apache.plc4x.java.mock.connection.MockConnection in project plc4x by apache.
the class PlcFunctionsTest method testSupplier.
/*
* test PlcConnectionAdapter.newSupplier
*/
@SuppressWarnings("unchecked")
@Test
@Category(FastTests.class)
public void testSupplier() throws Exception {
String addressStr = "MyReadWriteAddress/0";
MockField address = new MockField(addressStr);
PlcConnectionAdapter adapter = new PlcConnectionAdapter(getMockConnection());
MockConnection connection = (MockConnection) adapter.getConnection();
Supplier<?> supplier;
supplier = PlcFunctions.booleanSupplier(adapter, addressStr);
PlcConnectionAdapterTest.checkSupplier(connection, address, supplier, true, false);
supplier = PlcFunctions.byteSupplier(adapter, addressStr);
PlcConnectionAdapterTest.checkSupplier(connection, address, supplier, (byte) 0x1, (byte) 0x2, (byte) 0x3);
supplier = PlcFunctions.shortSupplier(adapter, addressStr);
PlcConnectionAdapterTest.checkSupplier(connection, address, supplier, (short) 1, (short) 2, (short) 3);
supplier = PlcFunctions.integerSupplier(adapter, addressStr);
PlcConnectionAdapterTest.checkSupplier(connection, address, supplier, 1000, 1001, 1002);
supplier = PlcFunctions.floatSupplier(adapter, addressStr);
PlcConnectionAdapterTest.checkSupplier(connection, address, supplier, 1000.5f, 1001.5f, 1002.5f);
supplier = PlcFunctions.stringSupplier(adapter, addressStr);
PlcConnectionAdapterTest.checkSupplier(connection, address, supplier, "one", "two", "three");
adapter.close();
}
Aggregations