Skip to content

Commit

Permalink
Initial addition of tests
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Jackson <[email protected]>
  • Loading branch information
cdjackson committed Mar 18, 2017
1 parent a5a03de commit 452bc14
Show file tree
Hide file tree
Showing 79 changed files with 846 additions and 267 deletions.
61 changes: 61 additions & 0 deletions com.zsmartsystems.zwave.test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.zsmartsystems.zwave</groupId>
<artifactId>com.zsmartsystems.zwave.test</artifactId>

<parent>
<groupId>com.zsmartsystems</groupId>
<artifactId>zwave</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<dependencies>
<dependency>
<groupId>com.zsmartsystems.zwave</groupId>
<artifactId>com.zsmartsystems.zwave</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
<plugins>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.8</version>
<executions>
<execution>
<id>jacoco-report-aggregate</id>
<phase>verify</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>com.gavinmogan</groupId>
<artifactId>codacy-maven-plugin</artifactId>
<version>1.0.3</version>
<configuration>
<coverageReportFile>${basedir}/target/site/jacoco-aggregate/jacoco.xml</coverageReportFile>
</configuration>
<executions>
<execution>
<id>codacy-upload-coverage</id>
<phase>verify</phase>
<goals>
<goal>coverage</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.zsmartsystems.zwave;


/**
* Representation of a single association - stores a node and option endpoint
*
Expand Down Expand Up @@ -32,9 +31,6 @@ public int getEndpoint() {
@Override
public boolean equals(Object checker) {
ZWaveAssociation assoc = (ZWaveAssociation) checker;
if (this.node == assoc.node && this.endpoint == assoc.endpoint) {
return true;
}
return false;
return (this.node == assoc.node && this.endpoint == assoc.endpoint);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import com.zsmartsystems.zwave.commandclass.ZWaveCommandClassEnum;


/**
* This class provides a storage class for zwave association groups
* within the node class. This is then serialised to XML.
Expand All @@ -27,7 +26,7 @@ public class ZWaveAssociationGroup {
private Integer profile2;
private Set<ZWaveCommandClassEnum> commands;

List<ZWaveAssociation> associations = new ArrayList<ZWaveAssociation>();
private List<ZWaveAssociation> associations = new ArrayList<ZWaveAssociation>();

public ZWaveAssociationGroup(int index) {
this.index = index;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.zsmartsystems.zwave;

public class ZWaveEvent {

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public interface ZWaveEventListener {
*
* @param event the incoming Z-Wave event.
*/
void ZWaveIncomingEvent();
void zwaveIncomingEvent();
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,13 @@ public int getSendQueueLength(int nodeId) {
return transactionManager.getSendQueueLength(nodeId);
}

/**
* Notifies event listeners of network level events
*
* @param event
*/
public void notifyEventListeners(ZWaveEvent event) {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class ZWaveNode {
* Provides the manufacturer ID for this device. This contains the manufacturer reference, the device type and
* device ID.
*/
ZWaveManufacturerId manufacturerId;
private ZWaveManufacturerId manufacturerId;

/**
* Provides the list of command classes reported in the NIF (Node Information Frame)
Expand Down Expand Up @@ -359,7 +359,7 @@ public boolean doesMessageRequireSecurityEncapsulation(int endpoint, ZWaveComman
*/
public void setAwake(boolean awake) {
// Don't do anything if this node is listening
if (listening == true || frequentlyListening == true) {
if (listening || frequentlyListening) {
logger.debug("NODE {}: Node is listening - ignore wakeup", getNodeId());
return;
}
Expand All @@ -374,7 +374,7 @@ public void setAwake(boolean awake) {
this.awake = awake;

// Start the timer
if (awake == true) {
if (awake) {
logger.debug("NODE {}: Is awake with {} messages in the queue", getNodeId(),
network.getSendQueueLength(getNodeId()));

Expand All @@ -398,7 +398,7 @@ public void setAwake(boolean awake) {
public boolean isAwake() {
logger.debug("NODE {}: listening == {}, frequentlyListening == {}, awake == {}", getNodeId(), listening,
frequentlyListening, awake);
return (listening == true || frequentlyListening == true || awake == true);
return (listening || frequentlyListening || awake);
}

/**
Expand Down Expand Up @@ -426,7 +426,7 @@ private class WakeupTimerTask extends TimerTask {

@Override
public void run() {
if (isAwake() == false) {
if (!isAwake()) {
logger.debug("NODE {}: WakeupTimerTask Already asleep", getNodeId());
return;
}
Expand All @@ -438,7 +438,7 @@ public void run() {
return;
}

if (triggered == false) {
if (!triggered) {
logger.debug("NODE {}: WakeupTimerTask First iteration", getNodeId());
triggered = true;
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@
public abstract class ZWaveCommandClass {
private static final Logger logger = LoggerFactory.getLogger(ZWaveCommandClass.class);

private class ZWaveResponseHandlerMethod {
int id;
String name;
Method method;

ZWaveResponseHandlerMethod(int id, String name, Method method) {
this.id = id;
this.name = name;
this.method = method;
}
};

protected ZWaveCommandClassEnum commandClass;

/**
Expand All @@ -48,6 +36,18 @@ private class ZWaveResponseHandlerMethod {
private int version = 0;
private int instances = 0;

private class ZWaveResponseHandlerMethod {
private int id;
private String name;
private Method method;

ZWaveResponseHandlerMethod(int id, String name, Method method) {
this.id = id;
this.name = name;
this.method = method;
}
};

protected ZWaveCommandClass(ZWaveEndpoint endpoint, ZWaveCommandClassEnum commandClass) {
// Create the map of response command handlers
commands = new HashMap<Integer, ZWaveResponseHandlerMethod>();
Expand All @@ -68,47 +68,6 @@ protected ZWaveCommandClass(ZWaveEndpoint endpoint, ZWaveCommandClassEnum comman
endpoint == null ? 0 : endpoint.getEndpointId());
}

/**
* Gets an instance of the right command class.
* Returns null if the command class is not found.
*
* @param classId the code to instantiate
* @param endpoint the endpoint this Command class belongs to
* @return the ZWaveCommandClass instance that was instantiated, null otherwise
*/
public static ZWaveCommandClass getInstance(int classId, ZWaveEndpoint endpoint) {
try {
ZWaveCommandClassEnum commandClass = ZWaveCommandClassEnum.getCommandClass(classId);
// if (commandClass != null
// && commandClass.equals(ZWaveCommandClassEnum.COMMAND_CLASS_MANUFACTURER_PROPRIETARY)) {
// commandClass = ZWaveCommandClassEnum.getCommandClass(node.getManufacturer(), node.getDeviceType());
// }
if (commandClass == null) {
logger.debug(String.format("NODE %d: Unknown command class 0x%02x", endpoint.getNodeId(), classId));
return null;
}
Class<? extends ZWaveCommandClass> commandClassClass = commandClass.getCommandClassClass();

if (commandClassClass == null) {
logger.debug("NODE {}: Unsupported command class {}", endpoint.getNodeId(), commandClass.toString(),
classId);
return null;
}
logger.debug("NODE {}: Creating new instance of command class {}", endpoint.getNodeId(),
commandClass.toString());

Constructor<? extends ZWaveCommandClass> constructor = commandClassClass
.getConstructor(ZWaveEndpoint.class);
return constructor.newInstance(new Object[] { endpoint });
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e) {
logger.debug(
String.format("NODE %d: Error instantiating command class 0x%02x", endpoint.getNodeId(), classId));
e.printStackTrace();
return null;
}
}

/**
* Gets the parent {@link ZWaveEndpoint} in which this class is implemented
*
Expand Down Expand Up @@ -224,4 +183,61 @@ protected String bb2hex(byte[] bb) {
return result.toString();
}

/**
* Gets an instance of the right command class.
* <p>
* Returns null if the command class is not found.
*
* @param classId the code to instantiate
* @param endpoint the {@link ZWaveEndpoint} this Command class belongs to
* @return the ZWaveCommandClass instance that was instantiated, null otherwise
*/
public static ZWaveCommandClass getInstance(int commandClassId, ZWaveEndpoint endpoint) {
ZWaveCommandClassEnum commandClass = ZWaveCommandClassEnum.getCommandClass(commandClassId);
if (commandClass == null) {
logger.debug("NODE {}: Unknown command class ", endpoint.getNodeId(),
String.format("%02X", commandClassId));
return null;
}

return getInstance(commandClass, endpoint);
}

/**
* Gets an instance of the right command class.
* <p>
* Returns null if the command class is not found.
*
* @param commandClass the {@link ZWaveCommandClassEnum} to instantiate
* @param endpoint the {@link ZWaveEndpoint} this Command class belongs to
* @return the ZWaveCommandClass instance that was instantiated, null otherwise
*/
public static ZWaveCommandClass getInstance(ZWaveCommandClassEnum commandClass, ZWaveEndpoint endpoint) {
try {
// ZWaveCommandClassEnum commandClass = ZWaveCommandClassEnum.getCommandClass(classId);
// if (commandClass == null) {
// logger.debug(String.format("NODE %d: Unknown command class 0x%02x", node.getNodeId(), classId));
// return null;
// }
Class<? extends ZWaveCommandClass> commandClassClass = commandClass.getCommandClassClass();

if (commandClassClass == null) {
logger.debug("NODE {}: Unsupported command class {}", endpoint.getNodeId(), commandClass.toString(),
commandClass);
return null;
}
logger.debug("NODE {}: Creating new instance of command class {}", endpoint.getNodeId(),
commandClass.toString());

Constructor<? extends ZWaveCommandClass> constructor = commandClassClass
.getConstructor(ZWaveEndpoint.class);
return constructor.newInstance(new Object[] { endpoint });
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e) {
logger.debug("NODE {}: Error instantiating command class {}", endpoint.getNodeId(), commandClass);
e.printStackTrace();
return null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public byte[] getSecurityMessageDecapsulation(byte[] ciphertextBytes) { // Check
}

// Make sure we sent a NONCE
if (ourNonce == null || ourNonce.isValid() == false) {
if (ourNonce == null || !ourNonce.isValid()) {
logger.debug("NODE {}: SECURITY_ERR No valid NONCE! {}", getEndpoint().getNodeId(), ourNonce);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static Map<String, Object> handleAlarmGet(byte[] payload) {
response.put("ALARM_TYPE", Integer.valueOf(payload[2]));

// Process 'ZWave Alarm Type'
constantZwaveAlarmType.get((int) payload[3]);
response.put("ZWAVE_ALARM_TYPE", constantZwaveAlarmType.get(payload[3] & 0xff));

// Return the map of processed response data;
return response;
Expand Down Expand Up @@ -254,7 +254,7 @@ public static Map<String, Object> handleAlarmReport(byte[] payload) {
msgOffset += 1;

// Process 'ZWave Alarm Type'
constantZwaveAlarmType.get((int) payload[msgOffset]);
response.put("ZWAVE_ALARM_TYPE", constantZwaveAlarmType.get(payload[msgOffset] & 0xff));
msgOffset += 1;

// Process 'ZWave Alarm Event'
Expand Down Expand Up @@ -328,7 +328,7 @@ public static Map<String, Object> handleAlarmSet(byte[] payload) {
Map<String, Object> response = new HashMap<String, Object>();

// Process 'ZWave Alarm Type'
constantZwaveAlarmType.get((int) payload[2]);
response.put("ZWAVE_ALARM_TYPE", constantZwaveAlarmType.get(payload[2] & 0xff));

// Process 'ZWave Alarm Status'
switch ((int) payload[3]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static Map<String, Object> handleApplicationBusy(byte[] payload) {
Map<String, Object> response = new HashMap<String, Object>();

// Process 'Status'
constantStatus.get((int) payload[2]);
response.put("STATUS", constantStatus.get(payload[2] & 0xff));

// Process 'Wait Time'
response.put("WAIT_TIME", Integer.valueOf(payload[3]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public static Map<String, Object> handleAssociationGroupInfoReport(byte[] payloa
variant.put("MODE", Integer.valueOf(payload[4]));

// Process 'Profile1'
constantProfile1.get((int) payload[5]);
variant.put("PROFILE1", constantProfile1.get(payload[5] & 0xff));

// Process 'Profile2'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public static Map<String, Object> handleAssociationGroupInfoReport(byte[] payloa
variant.put("MODE", Integer.valueOf(payload[4]));

// Process 'Profile1'
constantProfile1.get((int) payload[5]);
variant.put("PROFILE1", constantProfile1.get(payload[5] & 0xff));

// Process 'Profile2'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public static Map<String, Object> handleAssociationGroupInfoReport(byte[] payloa
variant.put("MODE", Integer.valueOf(payload[4]));

// Process 'Profile1'
constantProfile1.get((int) payload[5]);
variant.put("PROFILE1", constantProfile1.get(payload[5] & 0xff));

// Process 'Profile2'

Expand Down
Loading

0 comments on commit 452bc14

Please sign in to comment.