diff --git a/addons/binding/org.openhab.binding.max.test/.classpath b/addons/binding/org.openhab.binding.max.test/.classpath new file mode 100644 index 0000000000000..95df5aebb3a5b --- /dev/null +++ b/addons/binding/org.openhab.binding.max.test/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/addons/binding/org.openhab.binding.max.test/.groovy/suggestions.xdsl b/addons/binding/org.openhab.binding.max.test/.groovy/suggestions.xdsl new file mode 100644 index 0000000000000..1ce9852b140c0 --- /dev/null +++ b/addons/binding/org.openhab.binding.max.test/.groovy/suggestions.xdsl @@ -0,0 +1,2 @@ + + diff --git a/addons/binding/org.openhab.binding.max.test/.project b/addons/binding/org.openhab.binding.max.test/.project new file mode 100644 index 0000000000000..fb672a390b611 --- /dev/null +++ b/addons/binding/org.openhab.binding.max.test/.project @@ -0,0 +1,29 @@ + + + org.openhab.binding.max.test + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.jdt.groovy.core.groovyNature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/addons/binding/org.openhab.binding.max.test/.settings/org.eclipse.jdt.core.prefs b/addons/binding/org.openhab.binding.max.test/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000000..443e08599a2e6 --- /dev/null +++ b/addons/binding/org.openhab.binding.max.test/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/addons/binding/org.openhab.binding.max.test/.settings/org.eclipse.jdt.groovy.core.prefs b/addons/binding/org.openhab.binding.max.test/.settings/org.eclipse.jdt.groovy.core.prefs new file mode 100644 index 0000000000000..a68b5bf397081 --- /dev/null +++ b/addons/binding/org.openhab.binding.max.test/.settings/org.eclipse.jdt.groovy.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +groovy.compiler.level=-1 diff --git a/addons/binding/org.openhab.binding.max.test/.settings/org.eclipse.pde.core.prefs b/addons/binding/org.openhab.binding.max.test/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 0000000000000..e313d3c3b6b38 --- /dev/null +++ b/addons/binding/org.openhab.binding.max.test/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +resolve.requirebundle=false diff --git a/addons/binding/org.openhab.binding.max.test/.settings/org.maven.ide.eclipse.prefs b/addons/binding/org.openhab.binding.max.test/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 0000000000000..56e59e829b59a --- /dev/null +++ b/addons/binding/org.openhab.binding.max.test/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,9 @@ +#Fri Feb 18 22:39:16 CET 2011 +activeProfiles= +eclipse.preferences.version=1 +fullBuildGoals=process-test-resources +includeModules=false +resolveWorkspaceProjects=true +resourceFilterGoals=process-resources resources\:testResources +skipCompilerPlugin=true +version=1 diff --git a/addons/binding/org.openhab.binding.max.test/META-INF/MANIFEST.MF b/addons/binding/org.openhab.binding.max.test/META-INF/MANIFEST.MF new file mode 100644 index 0000000000000..d87610f4a8980 --- /dev/null +++ b/addons/binding/org.openhab.binding.max.test/META-INF/MANIFEST.MF @@ -0,0 +1,27 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Openhab Max! Binding Tests +Bundle-SymbolicName: org.openhab.binding.max.test;singleton:=true +Bundle-Version: 2.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.7 +Bundle-Vendor: Openhab +Fragment-Host: org.openhab.binding.max +Import-Package: org.openhab.binding.max, + org.slf4j, + groovy.json, + groovy.lang, + org.codehaus.groovy.reflection, + org.codehaus.groovy.runtime, + org.codehaus.groovy.runtime.callsite, + org.codehaus.groovy.runtime.typehandling, + org.eclipse.smarthome.core.events, + org.eclipse.smarthome.core.thing.setup, + org.eclipse.smarthome.core.thing.util, + org.eclipse.smarthome.test, + org.eclipse.smarthome.test.storage, + org.hamcrest;core=split, + org.osgi.service.device +Require-Bundle: org.junit;bundle-version="4.11.0" +Export-Package: org.openhab.binding.max.internal.message;x-internal:=true, + org.openhab.binding.max.test;uses:="org.eclipse.smarthome.test" + diff --git a/addons/binding/org.openhab.binding.max.test/MaxBindingTests.launch b/addons/binding/org.openhab.binding.max.test/MaxBindingTests.launch new file mode 100644 index 0000000000000..542fab481d331 --- /dev/null +++ b/addons/binding/org.openhab.binding.max.test/MaxBindingTests.launch @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/addons/binding/org.openhab.binding.max.test/build.properties b/addons/binding/org.openhab.binding.max.test/build.properties new file mode 100644 index 0000000000000..2fa4ab96b4e65 --- /dev/null +++ b/addons/binding/org.openhab.binding.max.test/build.properties @@ -0,0 +1,6 @@ +source.. = src/test/groovy,\ + src/test/java/ +output.. = target/classes/ +bin.includes = META-INF/,\ + .,\ + src/ diff --git a/addons/binding/org.openhab.binding.max.test/pom.xml b/addons/binding/org.openhab.binding.max.test/pom.xml new file mode 100644 index 0000000000000..28f87dbb79860 --- /dev/null +++ b/addons/binding/org.openhab.binding.max.test/pom.xml @@ -0,0 +1,115 @@ + + + 4.0.0 + org.openhab.binding + org.openhab.binding.max.test + eclipse-test-plugin + openHAB MAX! Binding Tests + + + org.openhab.binding + pom + 2.0.0-SNAPSHOT + + + + + org.openhab.binding.max.test + org.openhab.binding.max.test + + + + + + org.eclipse.tycho + tycho-surefire-plugin + ${tycho-version} + + + + eclipse-plugin + org.eclipse.equinox.event + 0.0.0 + + + eclipse-plugin + org.eclipse.equinox.ds + 0.0.0 + + + eclipse-plugin + org.eclipse.smarthome.config.xml + 0.0.0 + + + eclipse-plugin + org.eclipse.smarthome.core.thing.xml + 0.0.0 + + + eclipse-plugin + org.eclipse.smarthome.core.binding.xml + 0.0.0 + + + org.slf4j + slf4j-api + 0.0.0 + + + + org.slf4j + slf4j-simple + 0.0.0 + + + + org.slf4j + slf4j-log4j12 + 0.0.0 + + + + + org.eclipse.equinox.ds + 1 + true + + + org.eclipse.equinox.event + 2 + true + + + org.eclipse.smarthome.core + 4 + true + + + org.eclipse.smarthome.core.thing + 4 + true + + + org.eclipse.smarthome.config.xml + 4 + true + + + org.eclipse.smarthome.core.thing.xml + 4 + true + + + org.eclipse.smarthome.core.binding.xml + 4 + true + + + + + + + + diff --git a/addons/binding/org.openhab.binding.max.test/sample/sampleMessage.txt b/addons/binding/org.openhab.binding.max.test/sample/sampleMessage.txt new file mode 100644 index 0000000000000..dfe346ac57615 --- /dev/null +++ b/addons/binding/org.openhab.binding.max.test/sample/sampleMessage.txt @@ -0,0 +1,12 @@ +H:KEQ0565026,0b5951,0113,00000000,4eed6795,01,32,0f0113,0f34,03,0000 +M:00,01,VgIFAQhiYWRrYW1lcgsNowIMU3R1ZGVlcmthbWVyB7bnAwlXb29ua2FtZXIL6aIEDFN6b25qYSBLYW1lcgjDSQUGWm9sZGVyCMHWCAILDaNLRVEwNTQ0MjQyEUJhZGthbWVyIFJhZGlhdG9yAQEHtudLRVEwMTQ1MTcyFVJhZGlhdG9yIFN0dWRlZXJrYW1lcgIDDhXMTEVRMDAxNTM0MBlXYWxsIFRoZXJtb3N0YXQgV29vbmthbWVyAwEL6aJLRVE5MDE1NDMyG1BsdWcgQWRhcHRlciBNdXVydmVyd2FybWluZwMFBDNvSkVRMDM4MDg3OBdFY28gU3dpdGNoIFN0dWRlZXJrYW1lcgAEDnX2S0VRMTEwNDM4MBpXaW5kb3cgU2Vuc29yIFN0dWRlZXJrYW1lcgIBCMNJS0VRMDY0ODk0ORJUaGVybW9z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IEUgRSBFIEUgRSBFIERUVG9U01URSSBJIEkgRSBFIEUgRSBFIEUgRFRUcEjSVRJJIEkgSSBFIEUgRSBFIEUgRSBEVFRwSNJVEkkgSSBJIEUgRSBFIEUgRSBFIA== +L:CwsNowkSGE0kALAACwjB1gkSGGAiAAAABg519gkSEAYEM28JAAALC+miCRIYACIAAAAMDhXMCRIYBCIAAACtCwjDSQkSGGQqAGMACwe25wkSGGQkAAAA diff --git a/addons/binding/org.openhab.binding.max.test/src/test/groovy/org/openhab/binding/max/test/MaxBridgeHandlerOSGiTest.groovy b/addons/binding/org.openhab.binding.max.test/src/test/groovy/org/openhab/binding/max/test/MaxBridgeHandlerOSGiTest.groovy new file mode 100644 index 0000000000000..1974f2e4a550b --- /dev/null +++ b/addons/binding/org.openhab.binding.max.test/src/test/groovy/org/openhab/binding/max/test/MaxBridgeHandlerOSGiTest.groovy @@ -0,0 +1,90 @@ +/** + * Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.openhab.binding.max.test + +import static org.hamcrest.CoreMatchers.* +import static org.junit.Assert.* +import static org.junit.matchers.JUnitMatchers.* + +import org.eclipse.smarthome.config.core.Configuration +import org.eclipse.smarthome.core.thing.Bridge +import org.eclipse.smarthome.core.thing.ManagedThingProvider +import org.eclipse.smarthome.core.thing.ThingProvider +import org.eclipse.smarthome.core.thing.ThingTypeUID +import org.eclipse.smarthome.core.thing.ThingUID +import org.eclipse.smarthome.core.thing.binding.ThingHandler +import org.eclipse.smarthome.test.OSGiTest +import org.eclipse.smarthome.test.storage.VolatileStorageService +import org.junit.Before +import org.junit.Test +import org.openhab.binding.max.MaxBinding +import org.openhab.binding.max.internal.factory.MaxCubeHandlerFactory +import org.openhab.binding.max.internal.handler.MaxCubeBridgeHandler + + + +/** + * Tests for {@link MaxCubeBridgeHandler}. + * + * @author Marcel Verpaalen - Initial version + * @since 2.0 + */ +class MaxBridgeHandlerOSGiTest extends OSGiTest { + + final ThingTypeUID BRIDGE_THING_TYPE_UID = new ThingTypeUID("max", "bridge") + + ManagedThingProvider managedThingProvider + VolatileStorageService volatileStorageService = new VolatileStorageService() + + + @Before + void setUp() { + registerService(volatileStorageService) + managedThingProvider = getService(ThingProvider, ManagedThingProvider) + assertThat managedThingProvider, is(notNullValue()) + } + + @Test + void maxCubeBridgeHandlerRegisteredAndUnregister() { + + MaxCubeBridgeHandler maxBridgeHandler = getService(ThingHandler, MaxCubeBridgeHandler) + assertThat maxBridgeHandler, is(nullValue()) + + Configuration configuration = new Configuration().with { + put(MaxBinding.SERIAL_NUMBER, "KEQ0565026") + put(MaxBinding.IP_ADDRESS, "192.168.3.100") + it + } + + + ThingUID cubeUid = new ThingUID(BRIDGE_THING_TYPE_UID, "testCube"); + + + Bridge maxBridge = managedThingProvider.createThing( + BRIDGE_THING_TYPE_UID, + cubeUid, + null, configuration) + + assertThat maxBridge, is(notNullValue()) + + // wait for MaxCubeBridgeHandler to be registered + waitForAssert({ + maxBridgeHandler = getService(ThingHandler, MaxCubeBridgeHandler) + assertThat maxBridgeHandler, is(notNullValue()) + }, 10000) + + managedThingProvider.remove(maxBridge.getUID()) + + // wait for MaxCubeBridgeHandler to be unregistered + waitForAssert({ + maxBridgeHandler = getService(ThingHandler, MaxCubeBridgeHandler) + assertThat maxBridgeHandler, is(nullValue()) + }, 10000) + } + +} diff --git a/addons/binding/org.openhab.binding.max.test/src/test/java/org/openhab/binding/max/internal/message/C_MessageTest.java b/addons/binding/org.openhab.binding.max.test/src/test/java/org/openhab/binding/max/internal/message/C_MessageTest.java new file mode 100644 index 0000000000000..528ba257e81a7 --- /dev/null +++ b/addons/binding/org.openhab.binding.max.test/src/test/java/org/openhab/binding/max/internal/message/C_MessageTest.java @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.openhab.binding.max.internal.message; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +/** + * Tests cases for {@link C_Message}. + * + * @author Andreas Heil (info@aheil.de) + * @author Marcel Verpaalen - OH2 Version and updates + * @since 1.4.0 + */ +public class C_MessageTest { + + public final String rawData = "C:0b0da3,0gsNowIBEABLRVEwNTQ0MjQyLCQ9CQcYAzAM/wBIYViRSP1ZFE0gTSBNIEUgRSBFIEUgRSBFIEhhWJFQ/VkVUSBRIFEgRSBFIEUgRSBFIEUgSFBYWkj+WRRNIE0gTSBFIEUgRSBFIEUgRSBIUFhaSP5ZFE0gTSBNIEUgRSBFIEUgRSBFIEhQWFpI/lkUTSBNIE0gRSBFIEUgRSBFIEUgSFBYWkj+WRRNIE0gTSBFIEUgRSBFIEUgRSBIUFhaSP5ZFE0gTSBNIEUgRSBFIEUgRSBFIA=="; + + private C_Message message = null; + + @Before + public void Before() { + message = new C_Message(rawData); + } + + @Test + public void getMessageTypeTest() { + + MessageType messageType = ((Message) message).getType(); + + assertEquals(MessageType.C, messageType); + } + + @Test + public void getRFAddressTest() { + + String rfAddress = message.getRFAddress(); + + assertEquals("0b0da3", rfAddress); + } + + @Test + public void getDeviceTypeTest() { + + DeviceType deviceType = message.getDeviceType(); + + assertEquals(DeviceType.HeatingThermostatPlus, deviceType); + } + + @Test + public void getSerialNumberTes() { + String serialNumber = message.getSerialNumber(); + + assertEquals("KEQ0544242", serialNumber); + } +} \ No newline at end of file diff --git a/addons/binding/org.openhab.binding.max.test/src/test/java/org/openhab/binding/max/internal/message/ConfigurationTest.java b/addons/binding/org.openhab.binding.max.test/src/test/java/org/openhab/binding/max/internal/message/ConfigurationTest.java new file mode 100644 index 0000000000000..b012606fb1ba6 --- /dev/null +++ b/addons/binding/org.openhab.binding.max.test/src/test/java/org/openhab/binding/max/internal/message/ConfigurationTest.java @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.openhab.binding.max.internal.message; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +/** + * Tests cases for {@link DeviceConfiguration}. + * + * @author Andreas Heil (info@aheil.de) + * @author Marcel Verpaalen - OH2 Version and updates + * @since 1.4.0 + */ + +public class ConfigurationTest { + + public final String rawData = "C:0b0da3,0gsNowIBEABLRVEwNTQ0MjQyLCQ9CQcYAzAM/wBIYViRSP1ZFE0gTSBNIEUgRSBFIEUgRSBFIEhhWJFQ/VkVUSBRIFEgRSBFIEUgRSBFIEUgSFBYWkj+WRRNIE0gTSBFIEUgRSBFIEUgRSBIUFhaSP5ZFE0gTSBNIEUgRSBFIEUgRSBFIEhQWFpI/lkUTSBNIE0gRSBFIEUgRSBFIEUgSFBYWkj+WRRNIE0gTSBFIEUgRSBFIEUgRSBIUFhaSP5ZFE0gTSBNIEUgRSBFIEUgRSBFIA=="; + + private C_Message c_message = null; + private DeviceConfiguration configuration = null; + + @Before + public void Before() { + c_message = new C_Message(rawData); + configuration = DeviceConfiguration.create(c_message); + } + + @Test + public void createTest() { + assertNotNull(configuration); + } + + @Test + public void getRfAddressTest() { + String rfAddress = configuration.getRFAddress(); + + assertEquals("0b0da3", rfAddress); + } + + @Test + public void getDeviceTypeTest() { + + DeviceType deviceType = configuration.getDeviceType(); + + assertEquals(DeviceType.HeatingThermostatPlus, deviceType); + } + + @Test + public void getSerialNumberTest() { + String serialNumber = configuration.getSerialNumber(); + + assertEquals("KEQ0544242", serialNumber); + } + +} diff --git a/addons/binding/org.openhab.binding.max.test/src/test/java/org/openhab/binding/max/internal/message/M_MessageTest.java b/addons/binding/org.openhab.binding.max.test/src/test/java/org/openhab/binding/max/internal/message/M_MessageTest.java new file mode 100644 index 0000000000000..f92e6ea9b3e6c --- /dev/null +++ b/addons/binding/org.openhab.binding.max.test/src/test/java/org/openhab/binding/max/internal/message/M_MessageTest.java @@ -0,0 +1,101 @@ +/** + * Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.openhab.binding.max.internal.message; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; + +import org.junit.Before; +import org.junit.Test; + +/** + * Tests cases for {@link M_Message}. + * + * @author Marcel Verpaalen - Initial version + * @since 2.0 + */ +public class M_MessageTest { + + public final String rawData = "M:00,01,VgIFAQhiYWRrYW1lcgsNowIMU3R1ZGVlcmthbWVyB7bnAwlXb29ua2FtZXIL6aIEDFN6b25qYSBLYW1lcgjDSQUGWm9sZGVyCMHWCAILDaNLRVEwNTQ0MjQyEUJhZGthbWVyIFJhZGlhdG9yAQEHtudLRVEwMTQ1MTcyFVJhZGlhdG9yIFN0dWRlZXJrYW1lcgIDDhXMTEVRMDAxNTM0MBlXYWxsIFRoZXJtb3N0YXQgV29vbmthbWVyAwEL6aJLRVE5MDE1NDMyG1BsdWcgQWRhcHRlciBNdXVydmVyd2FybWluZwMFBDNvSkVRMDM4MDg3OBdFY28gU3dpdGNoIFN0dWRlZXJrYW1lcgAEDnX2S0VRMTEwNDM4MBpXaW5kb3cgU2Vuc29yIFN0dWRlZXJrYW1lcgIBCMNJS0VRMDY0ODk0ORJUaGVybW9zdGFhdCBTem9uamEEAQjB1ktFUTA2NDkzMTIRU3R1ZGVlcmthbWVyIElybWEFAQ=="; + + private M_Message message = null; + + @Before + public void Before() { + message = new M_Message(rawData); + } + + @Test + public void getMessageTypeTest() { + + MessageType messageType = ((Message) message).getType(); + + assertEquals(MessageType.M, messageType); + } + + @Test + public void deviceInformationTest() { + + ArrayList allDevicesInformation = message.devices; + + assertEquals(8, allDevicesInformation.size()); + + DeviceInformation deviceInformation = allDevicesInformation.get(0); + assertEquals("Badkamer Radiator", deviceInformation.getName()); + assertEquals("0B0DA3", deviceInformation.getRFAddress()); + assertEquals(1, deviceInformation.getRoomId()); + assertEquals("KEQ0544242", deviceInformation.getSerialNumber()); + assertEquals(DeviceType.HeatingThermostatPlus, deviceInformation.getDeviceType()); + + } + + @Test + public void deviceInformationTypeTest1() { + + ArrayList allDevicesInformation = message.devices; + DeviceInformation deviceInformation = allDevicesInformation.get(1); + assertEquals(DeviceType.HeatingThermostat, deviceInformation.getDeviceType()); + } + + @Test + public void deviceInformationTypeTest2() { + + ArrayList allDevicesInformation = message.devices; + DeviceInformation deviceInformation = allDevicesInformation.get(2); + assertEquals(DeviceType.WallMountedThermostat, deviceInformation.getDeviceType()); + } + + @Test + public void deviceInformationTypeTest3() { + + ArrayList allDevicesInformation = message.devices; + DeviceInformation deviceInformation = allDevicesInformation.get(4); + assertEquals(DeviceType.EcoSwitch, deviceInformation.getDeviceType()); + } + + @Test + public void deviceInformationTypeTest4() { + + ArrayList allDevicesInformation = message.devices; + DeviceInformation deviceInformation = allDevicesInformation.get(5); + assertEquals(DeviceType.ShutterContact, deviceInformation.getDeviceType()); + } + + @Test + public void roomInformationTest() { + + ArrayList roomInformation = message.rooms; + + assertEquals(5, roomInformation.size()); + assertEquals("badkamer", roomInformation.get(0).getName()); + + } + +} diff --git a/addons/binding/org.openhab.binding.max.test/src/test/java/org/openhab/binding/max/internal/message/S_CommandTest.java b/addons/binding/org.openhab.binding.max.test/src/test/java/org/openhab/binding/max/internal/message/S_CommandTest.java new file mode 100644 index 0000000000000..c0e7032ffef46 --- /dev/null +++ b/addons/binding/org.openhab.binding.max.test/src/test/java/org/openhab/binding/max/internal/message/S_CommandTest.java @@ -0,0 +1,80 @@ +/** + * Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.openhab.binding.max.internal.message; + +import static org.junit.Assert.*; + +import org.apache.commons.net.util.Base64; +import org.junit.Test; +import org.openhab.binding.max.internal.Utils; + +/** +* Tests cases for {@link S_Command}. +* +* @author Andreas Heil (info@aheil.de) +* @author Marcel Verpaalen - OH2 Version and updates +* @since 1.4.0 +*/ +public class S_CommandTest { + + public final String foo = "s:AARAAAAAAP4wAaiLix8=\r\n"; + + @Test + public void PrefixTest() { + S_Command scmd = new S_Command("0b0da3", 1, ThermostatModeType.MANUAL, 20.0); + + String commandStr = scmd.getCommandString(); + + String prefix = commandStr.substring(0, 2); + + assertEquals("s:", prefix); + + } + + @Test + public void BaseCommandTest() { + S_Command scmd = new S_Command("0b0da3", 1, ThermostatModeType.MANUAL, 20.0); + + String commandStr = scmd.getCommandString(); + + String base64Data = commandStr.substring(3); + byte[] bytes = Base64.decodeBase64(base64Data.getBytes()); + + int[] data = new int[bytes.length]; + + for (int i = 0; i < bytes.length; i++) { + data[i] = bytes[i] & 0xFF; + } + + String decodedString = Utils.toHex(data); + assertEquals("s:AARAAAAACw2jAWg=\r\n", commandStr); + assertEquals("011000000002C368C05A", decodedString); + + } + + @Test + public void boostModeTest() { + S_Command scmd = new S_Command("0b0da3", 1, ThermostatModeType.BOOST, 21.0); + + String commandStr = scmd.getCommandString(); + + assertEquals("s:AARAAAAACw2jAeo=\r\n", commandStr); + + } + + @Test + public void autotModeTest() { + S_Command scmd = new S_Command("0b0da3", 1, ThermostatModeType.AUTOMATIC, 0); + + String commandStr = scmd.getCommandString(); + + assertEquals("s:AARAAAAACw2jAQA=\r\n", commandStr); + + } +} diff --git a/addons/binding/org.openhab.binding.max.test/src/test/java/org/openhab/binding/max/internal/message/UtilsTest.java b/addons/binding/org.openhab.binding.max.test/src/test/java/org/openhab/binding/max/internal/message/UtilsTest.java new file mode 100644 index 0000000000000..6e77ee93b1e67 --- /dev/null +++ b/addons/binding/org.openhab.binding.max.test/src/test/java/org/openhab/binding/max/internal/message/UtilsTest.java @@ -0,0 +1,144 @@ +/** + * Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.openhab.binding.max.internal.message; + +import static org.junit.Assert.*; + +import java.util.Date; + +//import junit.framework.Assert; + + + + +import org.junit.Test; +import org.openhab.binding.max.internal.Utils; + +/** +* Tests cases for {@link Utils}. +* +* @author Andreas Heil (info@aheil.de) +* @author Marcel Verpaalen - OH2 Version and updates +* @since 1.4.0 +*/ +public class UtilsTest { + + @Test + public void fromHexTest() { + + int ar0 = Utils.fromHex("00"); + int ar1 = Utils.fromHex("01"); + int ar31 = Utils.fromHex("1F"); + int ar255 = Utils.fromHex("FF"); + + assertEquals(0, ar0); + assertEquals(1, ar1); + assertEquals(31, ar31); + assertEquals(255, ar255); + } + + @Test + public void fromByteTest() { + + byte b0 = 0; + byte b127 = 127; + byte b128 = (byte) 128; // overflow due to + byte bn128 = -128; // signed bytes + byte bn1 = -1; + + int ar0 = Utils.fromByte(b0); + int ar127 = Utils.fromByte(b127); + int ar128 = Utils.fromByte(b128); + int arn128 = Utils.fromByte(bn128); + int arn1 = Utils.fromByte(bn1); + + assertEquals(0, ar0); + assertEquals(127, ar127); + assertEquals(128, ar128); + assertEquals(128, arn128); + assertEquals(255, arn1); + } + + @Test + public void toHexNoArgTest() { + + String actualResult = Utils.toHex(); + + assertEquals("", actualResult ); + } + + @Test + public void toHexOneArgTest() { + + String actualResult = Utils.toHex(15); + + assertEquals("0F", actualResult ); + } + + @Test + public void toHexMultipleArgTest() { + + String actualResult = Utils.toHex(4863); + + assertEquals("12FF", actualResult ); + } + + @SuppressWarnings("deprecation") + @Test + public void resolveDateTimeTest() { + + int date = Utils.fromHex("858B"); // 05-09-2011 + int time = Utils.fromHex("2E"); // 23:00 + + Date result = Utils.resolveDateTime(date, time); + + assertEquals(5, result.getDate()); + assertEquals(9, result.getMonth()); + assertEquals(2011, result.getYear()); + assertEquals(23, result.getHours()); + assertEquals(00, result.getMinutes()); + } + + @Test + public void getBitsTest() { + boolean b1[] = Utils.getBits(0xFF); + + assertEquals(b1.length, 8); + for (int i = 0; i < 8; i++) + { + assertEquals(true, b1[i]); + } + + boolean b2[] = Utils.getBits(0x5A); + + assertEquals(b2.length, 8); + assertEquals(false, b2[0]); + assertEquals(true, b2[1]); + assertEquals(false, b2[2]); + assertEquals(true, b2[3]); + assertEquals(true, b2[4]); + assertEquals(false, b2[5]); + assertEquals(true, b2[6]); + assertEquals(false, b2[7]); + } + + @Test + public void hexStringToByteArrayTest() { + String s = "000102030AFF"; + + byte[] result = Utils.hexStringToByteArray(s); + + assertEquals(0, result[0] & 0xFF); + assertEquals(1, result[1] & 0xFF); + assertEquals(2, result[2] & 0xFF); + assertEquals(3, result[3] & 0xFF); + assertEquals(10, result[4] & 0xFF); + assertEquals(255, result[5] & 0xFF); + } +} \ No newline at end of file diff --git a/addons/binding/pom.xml b/addons/binding/pom.xml index 05137cfe00006..0af0f2c14243f 100644 --- a/addons/binding/pom.xml +++ b/addons/binding/pom.xml @@ -18,6 +18,7 @@ org.openhab.binding.sonos org.openhab.binding.max + org.openhab.binding.max.test org.openhab.binding.networkhealth diff --git a/targetplatform/openhab.target b/targetplatform/openhab.target index 5e5ef17d0009f..fd319799a9e42 100644 --- a/targetplatform/openhab.target +++ b/targetplatform/openhab.target @@ -1,117 +1,152 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +