[zb4osgi-changeset] [scm] ZigBee 4 OSGi repository change: r570 - in /projects/zb4osgi/trunk/zigbee.tester/src: main/java/org/persona/zigbee/tester/gui/HADeviceTreeNode.java test/java/org/persona/zigbee/tester/gui/HADeviceTreeNodeTest.java
scm-notify at zb4osgi.aaloa.org
scm-notify at zb4osgi.aaloa.org
Thu Oct 25 10:22:39 CEST 2012
Author: stefano.lenzi
Date: Thu Oct 25 10:22:39 2012
New Revision: 570
Log:
Added Test Unit for checking the method that are identified as command from the tester
Changed again policy for identifying the command among the methods of a cluster object ( refs #150 )
Added:
projects/zb4osgi/trunk/zigbee.tester/src/test/java/org/persona/zigbee/tester/gui/HADeviceTreeNodeTest.java (with props)
Modified:
projects/zb4osgi/trunk/zigbee.tester/src/main/java/org/persona/zigbee/tester/gui/HADeviceTreeNode.java
Modified: projects/zb4osgi/trunk/zigbee.tester/src/main/java/org/persona/zigbee/tester/gui/HADeviceTreeNode.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.tester/src/main/java/org/persona/zigbee/tester/gui/HADeviceTreeNode.java (original)
+++ projects/zb4osgi/trunk/zigbee.tester/src/main/java/org/persona/zigbee/tester/gui/HADeviceTreeNode.java Thu Oct 25 10:22:39 2012
@@ -139,12 +139,11 @@
public HADeviceTreeNode(HADevice device, Cluster obj) {
super(obj);
- this.device = device;
- category = SERVICE;
+ category = SERVICE;
Attribute[] variables = obj.getAttributes();
if (variables != null) {
for (int i=0;i<variables.length;i++)
- this.add(new HADeviceTreeNode(device,variables[i]));
+ this.add(new HADeviceTreeNode(device, variables[i]));
}
Method[] methods = obj.getClass().getMethods();
for (int i = 0; i < methods.length; i++) {
@@ -157,12 +156,12 @@
if ( methodName.equals("subscribe") || methodName.equals("unsubscribe") ){
//We skip method that are only a way to access method available at level of attribute
continue;
- } else if ( methodName.startsWith("get") && ( !( returnType == void.class || Response.class.isAssignableFrom( returnType ) ) ) ) {
+ } else if ( methodName.startsWith("get") && ( ! ( Response.class.isAssignableFrom(returnType) || returnType == void.class ) ) ) {
//We skip method that are only a way to access method available at level of attribute
- continue;
+ continue;
} else if ( methodName.startsWith("add") || methodName.startsWith("remove") ) {
Class<?>[] args = methods[i].getParameterTypes();
- if( args.length == 1 && args[0].getName().endsWith( "Listener" ) ){
+ if( args.length == 1 && args[0].getName().endsWith( "Listener" ) ){
String pairName = null;
if ( ( pairName = checkForAddRemoveMethodsPair(methods,i) ) == null ) continue;
int childCount = this.getChildCount();
@@ -174,16 +173,15 @@
isDuplicate = event.getName().equals(pairName);
}
if( isDuplicate ) continue;
+ //TODO Add support for Specific Cluster Eventing
this.add(new HADeviceTreeNode(new HAEvent(obj, pairName)));
- //TODO Add support for Specific Cluster Eventing
continue;
}
- this.add(new HADeviceTreeNode(new Command(obj, methods[i])));
- }
-
- }
-
- }
+ }
+ this.add(new HADeviceTreeNode(new Command(obj, methods[i])));
+ }
+
+ }
private String checkForAddRemoveMethodsPair(Method[] methods, int i) {
String name = methods[i].getName();
Added: projects/zb4osgi/trunk/zigbee.tester/src/test/java/org/persona/zigbee/tester/gui/HADeviceTreeNodeTest.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.tester/src/test/java/org/persona/zigbee/tester/gui/HADeviceTreeNodeTest.java (added)
+++ projects/zb4osgi/trunk/zigbee.tester/src/test/java/org/persona/zigbee/tester/gui/HADeviceTreeNodeTest.java Thu Oct 25 10:22:39 2012
@@ -1,0 +1,85 @@
+/*
+ Copyright 2008-2010 CNR-ISTI, http://isti.cnr.it
+ Institute of Information Science and Technologies
+ of the Italian National Research Council
+
+
+ See the NOTICE file distributed with this work for additional
+ information regarding copyright ownership
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+package org.persona.zigbee.tester.gui;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import it.cnr.isti.zigbee.ha.cluster.glue.Cluster;
+import it.cnr.isti.zigbee.ha.cluster.impl.AlarmsImpl;
+import it.cnr.isti.zigbee.ha.cluster.impl.GroupsImpl;
+import it.cnr.isti.zigbee.ha.cluster.impl.IdentifyImpl;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Test;
+
+/**
+ *
+ * @author <a href="mailto:stefano.lenzi at isti.cnr.it">Stefano "Kismet" Lenzi</a>
+ * @version $LastChangedRevision$ ($LastChangedDate$)
+ * @since 0.4.0
+ *
+ */
+public class HADeviceTreeNodeTest {
+
+
+ private void testSingleCluster(Cluster c, String[] methods){
+ final HADeviceTreeNode node = new HADeviceTreeNode( null, c);
+ Arrays.sort(methods);
+ ArrayList<String> list = new ArrayList<String>(Arrays.asList(methods));
+ int n = node.getChildCount();
+ int cmd = 0;
+ for (int j = 0; j < n; j++) {
+ HADeviceTreeNode child = (HADeviceTreeNode) node.getChildAt(j);
+ if ( child.category == HADeviceTreeNode.ZCL_COMMAND ) {
+ cmd++;
+ assertTrue(
+ "Command "+child.toString()+" is not part of the expected command "+Arrays.toString(methods),
+ Arrays.binarySearch(methods, child.toString()) >= 0
+ );
+ list.remove(child.toString());
+ }
+ }
+ assertTrue("The following methods were expected " + list, list.isEmpty() );
+ //assertEquals("Expected "+methods.length+" but found only "+cmd+" command for the cluster "+c.getName(), methods.length, cmd);
+
+ }
+
+ @Test
+ public void testHADeviceTreeNodeHADeviceCluster() {
+ testSingleCluster(
+ new GroupsImpl(null),
+ new String[]{ "addGroup", "addGroupIfIdentifying", "getGroupMembership", "removeAllGroup", "removeGroup", "viewGroup" }
+ );
+ testSingleCluster(
+ new IdentifyImpl(null),
+ new String[]{ "identify", "IdentifyQuery" }
+ );
+ testSingleCluster(
+ new AlarmsImpl(null),
+ new String[]{ "getAlarm", "resetAlarm", "resetAlarmLog", "resetAllAlarms" }
+ );
+ }
+}
Propchange: projects/zb4osgi/trunk/zigbee.tester/src/test/java/org/persona/zigbee/tester/gui/HADeviceTreeNodeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: projects/zb4osgi/trunk/zigbee.tester/src/test/java/org/persona/zigbee/tester/gui/HADeviceTreeNodeTest.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: projects/zb4osgi/trunk/zigbee.tester/src/test/java/org/persona/zigbee/tester/gui/HADeviceTreeNodeTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: projects/zb4osgi/trunk/zigbee.tester/src/test/java/org/persona/zigbee/tester/gui/HADeviceTreeNodeTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the Commit
mailing list