forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[miio] add support for BT Gateway switch on chuangmi.plug.212a01 (ope…
…nhab#11657) * [miio] add support for BT Gateway switch on chuangmi.plug.212a01 Signed-off-by: Marcel Verpaalen <[email protected]> * [miio] improve conversion & add test for it Signed-off-by: Marcel Verpaalen <[email protected]> * [miio] add one empty string test Signed-off-by: Marcel Verpaalen <[email protected]> * [miio] remove unnessesary exceptions Signed-off-by: Marcel Verpaalen <[email protected]> * [miio] add one more test for different inputs Signed-off-by: Marcel Verpaalen <[email protected]> * [miio] typo Signed-off-by: Marcel Verpaalen <[email protected]> Signed-off-by: Nick Waterton <[email protected]>
- Loading branch information
1 parent
36af57c
commit a2f11ce
Showing
4 changed files
with
205 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
...openhab.binding.miio/src/test/java/org/openhab/binding/miio/internal/ConversionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/** | ||
* Copyright (c) 2010-2021 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.miio.internal; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.junit.jupiter.api.Test; | ||
import org.openhab.binding.miio.internal.basic.Conversions; | ||
|
||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonParser; | ||
import com.google.gson.JsonPrimitive; | ||
|
||
/** | ||
* Test case for {@link ConversionsTest} | ||
* | ||
* @author Marcel Verpaalen - Initial contribution | ||
* | ||
*/ | ||
@NonNullByDefault | ||
public class ConversionsTest { | ||
|
||
@Test | ||
public void getJsonElementTest() { | ||
|
||
Map<String, Object> deviceVariables = Collections.emptyMap(); | ||
|
||
// test invalid missing element | ||
String transformation = "getJsonElement"; | ||
JsonElement value = new JsonPrimitive(""); | ||
JsonElement resp = Conversions.execute(transformation, value, deviceVariables); | ||
assertNotNull(resp); | ||
assertEquals(value, resp); | ||
|
||
// test invalid missing element | ||
value = new JsonPrimitive("{\"test\": \"testresponse\"}"); | ||
resp = Conversions.execute(transformation, value, deviceVariables); | ||
assertNotNull(resp); | ||
assertEquals(value, resp); | ||
|
||
transformation = "getJsonElement-test"; | ||
|
||
// test without deviceVariables | ||
resp = Conversions.execute(transformation, value, null); | ||
assertNotNull(resp); | ||
assertEquals(new JsonPrimitive("testresponse"), resp); | ||
|
||
// test non json | ||
value = new JsonPrimitive("some non json value"); | ||
resp = Conversions.execute(transformation, value, deviceVariables); | ||
assertNotNull(resp); | ||
assertEquals(value, resp); | ||
|
||
// test non json empty string | ||
value = new JsonPrimitive(""); | ||
resp = Conversions.execute(transformation, value, deviceVariables); | ||
assertNotNull(resp); | ||
assertEquals(value, resp); | ||
|
||
// test input as jsonString | ||
value = new JsonPrimitive("{\"test\": \"testresponse\"}"); | ||
resp = Conversions.execute(transformation, value, deviceVariables); | ||
assertNotNull(resp); | ||
assertEquals(new JsonPrimitive("testresponse"), resp); | ||
|
||
// test input as jsonObject | ||
value = JsonParser.parseString("{\"test\": \"testresponse\"}"); | ||
resp = Conversions.execute(transformation, value, deviceVariables); | ||
assertNotNull(resp); | ||
assertEquals(new JsonPrimitive("testresponse"), resp); | ||
|
||
// test input as jsonString for a number | ||
value = new JsonPrimitive("{\"test\": 3}"); | ||
resp = Conversions.execute(transformation, value, deviceVariables); | ||
assertNotNull(resp); | ||
assertEquals(new JsonPrimitive(3), resp); | ||
|
||
// test input as jsonString for a array | ||
value = new JsonPrimitive("{\"test\": []}"); | ||
resp = Conversions.execute(transformation, value, deviceVariables); | ||
assertNotNull(resp); | ||
assertEquals(new JsonArray(), resp); | ||
|
||
// test input as jsonString for a boolean | ||
value = new JsonPrimitive("{\"test\": false}"); | ||
resp = Conversions.execute(transformation, value, deviceVariables); | ||
assertNotNull(resp); | ||
assertEquals(new JsonPrimitive(false), resp); | ||
|
||
// test input as jsonObject for a number | ||
value = JsonParser.parseString("{\"test\": 3}"); | ||
resp = Conversions.execute(transformation, value, deviceVariables); | ||
assertNotNull(resp); | ||
assertEquals(new JsonPrimitive(3), resp); | ||
|
||
// test input as jsonString for non-existing element | ||
value = new JsonPrimitive("{\"nottest\": \"testresponse\"}"); | ||
resp = Conversions.execute(transformation, value, deviceVariables); | ||
assertNotNull(resp); | ||
assertEquals(value, resp); | ||
|
||
// test input as jsonString for non-existing element | ||
value = JsonParser.parseString("{\"nottest\": \"testresponse\"}"); | ||
resp = Conversions.execute(transformation, value, deviceVariables); | ||
assertNotNull(resp); | ||
assertEquals(value, resp); | ||
} | ||
} |