From 54e42502cdd1cc9048dd3243433d783557e9196e Mon Sep 17 00:00:00 2001 From: Christian S Date: Mon, 20 Jan 2020 20:31:21 +0100 Subject: [PATCH] Update unit tests --- .../de/csdev/ebus/cfg/BuildTelegramTest.java | 12 +- .../ebus/cfg/EBusCommonTelegramTest.java | 2 +- .../csdev/ebus/cfg/EBusConfigurationHash.java | 16 +-- .../de/csdev/ebus/cfg/EBusConsoleTest.java | 16 ++- .../ebus/cfg/EBusNestedTemplatesTest.java | 6 +- .../command/datatype/ReplaceValueTest.java | 116 +++++++++--------- .../ebus/command/datatype/ext/TimeTest.java | 22 ++-- .../csdev/ebus/core/EBusControllerTest.java | 2 +- .../csdev/ebus/core/EBusStateMachineTest.java | 5 - .../java/de/csdev/ebus/wip/ClientTest3.java | 6 +- .../wip/EBusVaillantBAI00TelegramTest.java | 3 +- .../ebus/wip/EBusWolfSM1TelegramTest2XXX.java | 3 +- .../nested-templates/ThirdCommand.json | 3 + 13 files changed, 108 insertions(+), 104 deletions(-) diff --git a/src/test/java/de/csdev/ebus/cfg/BuildTelegramTest.java b/src/test/java/de/csdev/ebus/cfg/BuildTelegramTest.java index 8427a2b..f1dc23e 100644 --- a/src/test/java/de/csdev/ebus/cfg/BuildTelegramTest.java +++ b/src/test/java/de/csdev/ebus/cfg/BuildTelegramTest.java @@ -23,7 +23,9 @@ import de.csdev.ebus.command.IEBusCommand; import de.csdev.ebus.command.IEBusCommandCollection; import de.csdev.ebus.command.IEBusCommandMethod; +import de.csdev.ebus.command.IEBusCommandMethod.Type; import de.csdev.ebus.command.datatypes.EBusTypeException; +import de.csdev.ebus.core.EBusConsts; import de.csdev.ebus.utils.EBusUtils; /** @@ -45,10 +47,14 @@ public void test_BuildMasterTelegram() { for (IEBusCommandMethod commandChannel : command.getCommandMethods()) { try { + byte targetAddress = commandChannel.getType() == Type.MASTER_MASTER ? (byte) 0xFF + : commandChannel.getType() == Type.BROADCAST ? EBusConsts.BROADCAST_ADDRESS + : (byte) 0x04; + ByteBuffer masterTelegram = EBusCommandUtils.buildMasterTelegram(commandChannel, (byte) 0xFF, - (byte) 0xFF, null); + targetAddress, null); - logger.info(String.format("%-9s| %-40s| %-8s| %s", commandChannel.getMethod(), command.getId(), + logger.debug(String.format("%-9s| %-40s| %-8s| %s", commandChannel.getMethod(), command.getId(), collection.getId(), EBusUtils.toHexDumpString(masterTelegram))); } catch (EBusTypeException e) { @@ -73,7 +79,7 @@ public void test_BuildMasterTelegramMask() { ByteBuffer mask = commandChannel.getMasterTelegramMask(); - logger.info(String.format("%-9s| %-40s| %-8s| %s", commandChannel.getMethod(), command.getId(), + logger.debug(String.format("%-9s| %-40s| %-8s| %s", commandChannel.getMethod(), command.getId(), collection.getId(), EBusUtils.toHexDumpString(mask))); } diff --git a/src/test/java/de/csdev/ebus/cfg/EBusCommonTelegramTest.java b/src/test/java/de/csdev/ebus/cfg/EBusCommonTelegramTest.java index 30b6059..de6e87f 100644 --- a/src/test/java/de/csdev/ebus/cfg/EBusCommonTelegramTest.java +++ b/src/test/java/de/csdev/ebus/cfg/EBusCommonTelegramTest.java @@ -49,7 +49,7 @@ public void testIdentification() { assertNotNull("Command common.identification not found!", commandMethod); try { - ByteBuffer buffer = EBusCommandUtils.buildMasterTelegram(commandMethod, (byte) 0x00, (byte) 0xFF, null); + ByteBuffer buffer = EBusCommandUtils.buildMasterTelegram(commandMethod, (byte) 0x00, (byte) 0x04, null); assertNotNull("Unable to compose byte buffer for command", buffer); } catch (EBusTypeException e) { diff --git a/src/test/java/de/csdev/ebus/cfg/EBusConfigurationHash.java b/src/test/java/de/csdev/ebus/cfg/EBusConfigurationHash.java index bfdbb95..2d8ce4a 100644 --- a/src/test/java/de/csdev/ebus/cfg/EBusConfigurationHash.java +++ b/src/test/java/de/csdev/ebus/cfg/EBusConfigurationHash.java @@ -31,7 +31,7 @@ public class EBusConfigurationHash { private static final Logger logger = LoggerFactory.getLogger(EBusConfigurationHash.class); - private EBusCommandRegistry xx() throws IOException, EBusConfigurationReaderException { + private EBusCommandRegistry initCommandRegistry() throws IOException, EBusConfigurationReaderException { EBusTypeRegistry types = new EBusTypeRegistry(); @@ -45,10 +45,10 @@ private EBusCommandRegistry xx() throws IOException, EBusConfigurationReaderExce } @Test - public void testIdentification() throws IOException, EBusConfigurationReaderException { + public void testMethodHashs() throws IOException, EBusConfigurationReaderException { - EBusCommandRegistry reg1 = xx(); - EBusCommandRegistry reg2 = xx(); + EBusCommandRegistry reg1 = initCommandRegistry(); + EBusCommandRegistry reg2 = initCommandRegistry(); IEBusCommandCollection collection1 = reg1.getCommandCollection(EBusConsts.COLLECTION_STD); IEBusCommandCollection collection2 = reg2.getCommandCollection(EBusConsts.COLLECTION_STD); @@ -59,14 +59,14 @@ public void testIdentification() throws IOException, EBusConfigurationReaderExce for (IEBusCommandMethod method1 : command1.getCommandMethods()) { IEBusCommandMethod method2 = command2.getCommandMethod(method1.getMethod()); - logger.debug("Check command {}, H1:{}, H2:{}", new Object[] {method2.getMethod(), method2.hashCode(), - method2.hashCode()}); + logger.debug("Check command {}, H1:{}, H2:{}", + new Object[] { method2.getMethod(), method2.hashCode(), method2.hashCode() }); Assert.assertEquals(method2.hashCode(), method2.hashCode()); } - logger.debug("Check command {}, H1:{}, H2:{}", new Object[] {command1.getId(), command1.hashCode(), command2.hashCode()}); - // Assert.assertEquals(command1.hashCode(), command2.hashCode()); + logger.debug("Check command {}, H1:{}, H2:{}", + new Object[] { command1.getId(), command1.hashCode(), command2.hashCode() }); } } diff --git a/src/test/java/de/csdev/ebus/cfg/EBusConsoleTest.java b/src/test/java/de/csdev/ebus/cfg/EBusConsoleTest.java index d34f361..7c41d01 100644 --- a/src/test/java/de/csdev/ebus/cfg/EBusConsoleTest.java +++ b/src/test/java/de/csdev/ebus/cfg/EBusConsoleTest.java @@ -10,6 +10,8 @@ import org.junit.Before; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import de.csdev.ebus.cfg.std.EBusConfigurationReader; import de.csdev.ebus.command.EBusCommandRegistry; @@ -18,27 +20,29 @@ public class EBusConsoleTest { + private static final Logger logger = LoggerFactory.getLogger(EBusConsoleTest.class); + private EBusCommandRegistry commandRegistry; @Before - public void xx() { + public void before() { commandRegistry = new EBusCommandRegistry(EBusConfigurationReader.class, true); } @Test - public void x() { + public void testConsoleCommand() { byte[] data = EBusUtils.toByteArray("31 08 07 04 00 d1 00 0a b5 42 41 49 30 30 05 18 74 01 2f 00"); - System.out.print(EBusConsoleUtils.analyzeTelegram(commandRegistry, data)); + logger.debug(EBusConsoleUtils.analyzeTelegram(commandRegistry, data)); data = EBusUtils.toByteArray("71 FE 50 18 0E 00 00 D0 01 05 00 E2 03 0F 01 01 00 00 00 18"); - System.out.print(EBusConsoleUtils.analyzeTelegram(commandRegistry, data)); + logger.debug(EBusConsoleUtils.analyzeTelegram(commandRegistry, data)); data = EBusUtils.toByteArray("30 76 50 22 03 CC 2B 0A BF 00 02 11 01 84 00"); - System.out.print(EBusConsoleUtils.analyzeTelegram(commandRegistry, data)); + logger.debug(EBusConsoleUtils.analyzeTelegram(commandRegistry, data)); data = EBusUtils.toByteArray("FF 50 B5 09 03 0D 15 00 26 00 02 28 00 51 00"); - System.out.print(EBusConsoleUtils.analyzeTelegram(commandRegistry, data)); + logger.debug(EBusConsoleUtils.analyzeTelegram(commandRegistry, data)); } } diff --git a/src/test/java/de/csdev/ebus/cfg/EBusNestedTemplatesTest.java b/src/test/java/de/csdev/ebus/cfg/EBusNestedTemplatesTest.java index dd5ddbc..f7ec5d1 100644 --- a/src/test/java/de/csdev/ebus/cfg/EBusNestedTemplatesTest.java +++ b/src/test/java/de/csdev/ebus/cfg/EBusNestedTemplatesTest.java @@ -63,7 +63,7 @@ public void testIdentification() { ByteBuffer buffer = EBusCommandUtils.buildMasterTelegram(commandMethod, (byte) 0x00, (byte) 0xFF, null); assertNotNull("Unable to compose byte buffer for command", buffer); - logger.info(EBusUtils.toHexDumpString(buffer).toString()); + logger.debug(EBusUtils.toHexDumpString(buffer).toString()); } catch (EBusTypeException e) { logger.error("error!", e); @@ -92,7 +92,7 @@ public void testX() throws EBusTypeException { ByteBuffer buffer = EBusCommandUtils.buildMasterTelegram(commandMethod, (byte) 0x00, (byte) 0xFF, values); assertNotNull("Unable to compose byte buffer for command", buffer); - logger.info(EBusUtils.toHexDumpString(buffer).toString()); + logger.debug(EBusUtils.toHexDumpString(buffer).toString()); } catch (EBusTypeException e) { logger.error("error!", e); @@ -121,7 +121,7 @@ public void testY() throws EBusTypeException { ByteBuffer buffer = EBusCommandUtils.buildMasterTelegram(commandMethod, (byte) 0x00, (byte) 0xFF, values); assertNotNull("Unable to compose byte buffer for command", buffer); - logger.info(EBusUtils.toHexDumpString(buffer).toString()); + logger.debug(EBusUtils.toHexDumpString(buffer).toString()); } catch (EBusTypeException e) { logger.error("error!", e); diff --git a/src/test/java/de/csdev/ebus/command/datatype/ReplaceValueTest.java b/src/test/java/de/csdev/ebus/command/datatype/ReplaceValueTest.java index c9b3863..4ff1ca8 100644 --- a/src/test/java/de/csdev/ebus/command/datatype/ReplaceValueTest.java +++ b/src/test/java/de/csdev/ebus/command/datatype/ReplaceValueTest.java @@ -29,84 +29,84 @@ */ public class ReplaceValueTest { - private final Logger logger = LoggerFactory.getLogger(ReplaceValueTest.class); + private final Logger logger = LoggerFactory.getLogger(ReplaceValueTest.class); - EBusTypeRegistry types; - private byte[] encode; + EBusTypeRegistry types; + private byte[] encode; - @Before - public void before() { - types = new EBusTypeRegistry(); - } + @Before + public void before() { + types = new EBusTypeRegistry(); + } - @Test - public void test_CheckReplaceValues() { + @Test + public void test_CheckReplaceValues() { - for (String typeName : types.getTypesNames()) { + for (String typeName : types.getTypesNames()) { - if (!typeName.equals(EBusTypeBit.TYPE_BIT)) { + if (!typeName.equals(EBusTypeBit.TYPE_BIT)) { - IEBusType type = types.getType(typeName); - byte[] encodedData = null; - String error = null; + IEBusType type = types.getType(typeName); + byte[] encodedData = null; + String error = null; - try { - encodedData = type.encode(null); - } catch (RuntimeException e) { - error = "Exception: " + e.getMessage(); - } catch (EBusTypeException e) { - error = "Exception: " + e.getMessage(); - } + try { + encodedData = type.encode(null); + } catch (RuntimeException e) { + error = "Exception: " + e.getMessage(); + } catch (EBusTypeException e) { + error = "Exception: " + e.getMessage(); + } - if (error != null) { - logger.warn(String.format("%-10s | %s", typeName, error)); - fail(String.format("Data type '%s' returns with error %s", typeName, error)); + if (error != null) { + logger.warn(String.format("%-10s | %s", typeName, error)); + fail(String.format("Data type '%s' returns with error %s", typeName, error)); - } else if (encodedData == null) { + } else if (encodedData == null) { - } else if (encodedData.length > 0) { - logger.info(String.format("%-10s | %s", typeName, EBusUtils.toHexDumpString(encodedData))); + } else if (encodedData.length > 0) { + logger.debug(String.format("%-10s | %s", typeName, EBusUtils.toHexDumpString(encodedData))); - } else { - fail(String.format("Encoded data invalid for data type '%s' !", typeName)); - } + } else { + fail(String.format("Encoded data invalid for data type '%s' !", typeName)); + } - try { - Object decode = type.decode(encodedData); - assertNull("Datatype " + typeName + ": ", decode); + try { + Object decode = type.decode(encodedData); + assertNull("Datatype " + typeName + ": ", decode); - } catch (EBusTypeException e) { - logger.error("error!", e); - } + } catch (EBusTypeException e) { + logger.error("error!", e); + } - } - } - } + } + } + } - @Test - public void x() throws EBusTypeException { + @Test + public void test_EncodeDecodeEqualsTest() throws EBusTypeException { - for (String typeName : types.getTypesNames()) { + for (String typeName : types.getTypesNames()) { - IEBusType type = types.getType(typeName); + IEBusType type = types.getType(typeName); - byte[] bs = new byte[type.getTypeLength()]; - logger.info(type.toString()); + byte[] bs = new byte[type.getTypeLength()]; + logger.debug(type.toString()); - try { - Object decode = type.decode(bs); - encode = type.encode(decode); + try { + Object decode = type.decode(bs); + encode = type.encode(decode); - if (Arrays.equals(bs, encode)) { - logger.info(String.format("%-10s | %s", typeName, "OK")); - } else { - logger.warn(String.format("%-10s | %s - %s", typeName, EBusUtils.toHexDumpString(encode), decode)); - } + if (Arrays.equals(bs, encode)) { + logger.debug(String.format("%-10s | %s", typeName, "OK")); + } else { + logger.warn(String.format("%-10s | %s - %s", typeName, EBusUtils.toHexDumpString(encode), decode)); + } - } catch (Exception e) { - logger.warn(String.format("%-10s | %s", typeName, e.getMessage())); - } - } - } + } catch (Exception e) { + logger.warn(String.format("%-10s | %s", typeName, e.getMessage())); + } + } + } } diff --git a/src/test/java/de/csdev/ebus/command/datatype/ext/TimeTest.java b/src/test/java/de/csdev/ebus/command/datatype/ext/TimeTest.java index 5be5886..7b0ce38 100644 --- a/src/test/java/de/csdev/ebus/command/datatype/ext/TimeTest.java +++ b/src/test/java/de/csdev/ebus/command/datatype/ext/TimeTest.java @@ -287,17 +287,17 @@ public void test_TimeMinutes_Multi_10() throws EBusTypeException { assertEquals(calendar, decode.getCalendar()); } - public void test_TimeMinutes8BitX() throws EBusTypeException { - - IEBusType type = types.getType(EBusTypeTime.TYPE_TIME, IEBusType.VARIANT, - EBusTypeTime.MINUTES_SHORT, EBusTypeTime.MINUTE_MULTIPLIER, 15, "replaceValue", - new byte[] { (byte) 0x90 }); - - EBusDateTime decode = type.decode(new byte[] { (byte) 0x90 }); - - System.out.println("TimeTest.test_TimeMinutes8BitX()" + decode.getCalendar().getTime()); - - } + // public void test_TimeMinutes8BitX() throws EBusTypeException { + // + // IEBusType type = types.getType(EBusTypeTime.TYPE_TIME, IEBusType.VARIANT, + // EBusTypeTime.MINUTES_SHORT, EBusTypeTime.MINUTE_MULTIPLIER, 15, "replaceValue", + // new byte[] { (byte) 0x90 }); + // + // EBusDateTime decode = type.decode(new byte[] { (byte) 0x90 }); + // + // System.out.println("TimeTest.test_TimeMinutes8BitX()" + decode.getCalendar().getTime()); + // + // } @Test public void test_TimeMinutes8Bit() throws EBusTypeException { diff --git a/src/test/java/de/csdev/ebus/core/EBusControllerTest.java b/src/test/java/de/csdev/ebus/core/EBusControllerTest.java index 01ce725..681fd9e 100644 --- a/src/test/java/de/csdev/ebus/core/EBusControllerTest.java +++ b/src/test/java/de/csdev/ebus/core/EBusControllerTest.java @@ -86,7 +86,7 @@ public void testInterruptTCPRaw() throws InterruptedException, IOException, EBus Assert.assertFalse(controller.isInterrupted()); } - @Test + // @Test public void testInterruptEbusd() throws InterruptedException, IOException, EBusControllerException { EBusEbusdController controller = new EBusEbusdController("localhost", 1); diff --git a/src/test/java/de/csdev/ebus/core/EBusStateMachineTest.java b/src/test/java/de/csdev/ebus/core/EBusStateMachineTest.java index 915c712..e9a7e2e 100644 --- a/src/test/java/de/csdev/ebus/core/EBusStateMachineTest.java +++ b/src/test/java/de/csdev/ebus/core/EBusStateMachineTest.java @@ -374,12 +374,7 @@ public void testB() { ByteBuffer masterTelegramPart = EBusCommandUtils.buildCompleteTelegram((byte) 0xFF, (byte) 0x08, command, data, data); - // ByteBuffer slaveTelegramPart = EBusCommandUtils.buildSlaveTelegramPart(data); - bb.put(masterTelegramPart); - // bb.put(slaveTelegramPart); - // bb.put(EBusConsts.ACK_OK); - // bb.put(EBusConsts.SYN); runMachine(EBusUtils.toByteArray(masterTelegramPart)); diff --git a/src/test/java/de/csdev/ebus/wip/ClientTest3.java b/src/test/java/de/csdev/ebus/wip/ClientTest3.java index 1407de3..39a8625 100644 --- a/src/test/java/de/csdev/ebus/wip/ClientTest3.java +++ b/src/test/java/de/csdev/ebus/wip/ClientTest3.java @@ -10,8 +10,6 @@ import java.io.IOException; -import org.junit.Before; -import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,13 +34,13 @@ public class ClientTest3 { private IEBusConnection connection; - @Before + // @Before public void before() throws IOException, EBusConfigurationReaderException { connection = new EBusTCPConnection("openhab", 8881); // connection = new EBusUDPConnection("localhost", 8881); } - @Test + // @Test public void testNoSlaveResponse() throws EBusTypeException, IOException, InterruptedException, EBusControllerException { diff --git a/src/test/java/de/csdev/ebus/wip/EBusVaillantBAI00TelegramTest.java b/src/test/java/de/csdev/ebus/wip/EBusVaillantBAI00TelegramTest.java index 4f9d56a..76bcff0 100644 --- a/src/test/java/de/csdev/ebus/wip/EBusVaillantBAI00TelegramTest.java +++ b/src/test/java/de/csdev/ebus/wip/EBusVaillantBAI00TelegramTest.java @@ -11,7 +11,6 @@ import java.io.IOException; import java.io.InputStream; -import org.junit.Before; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,7 +31,7 @@ public class EBusVaillantBAI00TelegramTest { EBusTypeRegistry types; EBusCommandRegistry commandRegistry; - @Before + // @Before public void before() throws IOException, EBusConfigurationReaderException { types = new EBusTypeRegistry(); diff --git a/src/test/java/de/csdev/ebus/wip/EBusWolfSM1TelegramTest2XXX.java b/src/test/java/de/csdev/ebus/wip/EBusWolfSM1TelegramTest2XXX.java index c49f516..4105057 100644 --- a/src/test/java/de/csdev/ebus/wip/EBusWolfSM1TelegramTest2XXX.java +++ b/src/test/java/de/csdev/ebus/wip/EBusWolfSM1TelegramTest2XXX.java @@ -12,7 +12,6 @@ import java.nio.ByteBuffer; import org.junit.Before; -import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,7 +43,7 @@ public void before() throws IOException, EBusConfigurationReaderException { client.getDeviceTable().setOwnAddress((byte) 0xFF); } - @Test + // @Test public void testSolarCommands2() { IEBusCommand command = client.getConfigurationProvider().getCommandById("vrc430", "controller.date"); diff --git a/src/test/resources/nested-templates/ThirdCommand.json b/src/test/resources/nested-templates/ThirdCommand.json index e18edb8..1d97c4c 100644 --- a/src/test/resources/nested-templates/ThirdCommand.json +++ b/src/test/resources/nested-templates/ThirdCommand.json @@ -15,6 +15,7 @@ "id": "test.nextest-block", "command": "FC FC", "set": { + "type": "master-master", "master": [ {"type": "template-block", "id":"b5.slot1-3"} ] @@ -26,6 +27,7 @@ "id": "test.tth", "command": "FC FC", "set": { + "type": "master-master", "master": [ {"type": "template", "name": "tth", "id":"vaillant.templ.tth"} ] @@ -37,6 +39,7 @@ "id": "test.to", "command": "FC FC", "set": { + "type": "master-master", "master": [ {"type": "template-block", "id":"vaillant.to"} ]