Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian S committed Jan 20, 2020
1 parent 4d1db03 commit 54e4250
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 104 deletions.
12 changes: 9 additions & 3 deletions src/test/java/de/csdev/ebus/cfg/BuildTelegramTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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) {
Expand All @@ -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)));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 8 additions & 8 deletions src/test/java/de/csdev/ebus/cfg/EBusConfigurationHash.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
Expand All @@ -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() });
}

}
Expand Down
16 changes: 10 additions & 6 deletions src/test/java/de/csdev/ebus/cfg/EBusConsoleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}
}
6 changes: 3 additions & 3 deletions src/test/java/de/csdev/ebus/cfg/EBusNestedTemplatesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
116 changes: 58 additions & 58 deletions src/test/java/de/csdev/ebus/command/datatype/ReplaceValueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> type = types.getType(typeName);
byte[] encodedData = null;
String error = null;
IEBusType<Object> 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<Object> type = types.getType(typeName);
IEBusType<Object> 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()));
}
}
}

}
22 changes: 11 additions & 11 deletions src/test/java/de/csdev/ebus/command/datatype/ext/TimeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,17 @@ public void test_TimeMinutes_Multi_10() throws EBusTypeException {
assertEquals(calendar, decode.getCalendar());
}

public void test_TimeMinutes8BitX() throws EBusTypeException {

IEBusType<EBusDateTime> 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<EBusDateTime> 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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/de/csdev/ebus/core/EBusControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 0 additions & 5 deletions src/test/java/de/csdev/ebus/core/EBusStateMachineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
6 changes: 2 additions & 4 deletions src/test/java/de/csdev/ebus/wip/ClientTest3.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

import java.io.IOException;

import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.io.IOException;
import java.io.InputStream;

import org.junit.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -32,7 +31,7 @@ public class EBusVaillantBAI00TelegramTest {
EBusTypeRegistry types;
EBusCommandRegistry commandRegistry;

@Before
// @Before
public void before() throws IOException, EBusConfigurationReaderException {

types = new EBusTypeRegistry();
Expand Down
Loading

0 comments on commit 54e4250

Please sign in to comment.