]> git.basschouten.com Git - openhab-addons.git/blob
504f7dd10042918c65f8d92945a84ffaf9c1023a
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.modbus.internal;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import org.junit.jupiter.api.Test;
18 import org.mockito.Mockito;
19 import org.osgi.framework.BundleContext;
20
21 /**
22  * @author Sami Salonen - Initial contribution
23  */
24 public class SingleValueTransformationTest {
25
26     @Test
27     public void testTransformationOldStyle() {
28         SingleValueTransformation transformation = new SingleValueTransformation("REGEX(myregex:foo(.*))");
29         assertEquals("REGEX", transformation.transformationServiceName);
30         assertEquals("myregex:foo(.*)", transformation.transformationServiceParam);
31     }
32
33     @Test
34     public void testTransformationOldStyle2() {
35         SingleValueTransformation transformation = new SingleValueTransformation("REG_(EX(myregex:foo(.*))");
36         assertEquals("REG_", transformation.transformationServiceName);
37         assertEquals("EX(myregex:foo(.*)", transformation.transformationServiceParam);
38     }
39
40     @Test
41     public void testTransformationNewStyle() {
42         SingleValueTransformation transformation = new SingleValueTransformation("REGEX:myregex(.*)");
43         assertEquals("REGEX", transformation.transformationServiceName);
44         assertEquals("myregex(.*)", transformation.transformationServiceParam);
45     }
46
47     @Test
48     public void testTransformationNewStyle2() {
49         SingleValueTransformation transformation = new SingleValueTransformation("REGEX::myregex(.*)");
50         assertEquals("REGEX", transformation.transformationServiceName);
51         assertEquals(":myregex(.*)", transformation.transformationServiceParam);
52     }
53
54     @Test
55     public void testTransformationEmpty() {
56         SingleValueTransformation transformation = new SingleValueTransformation("");
57         assertFalse(transformation.isIdentityTransform());
58         assertEquals("", transformation.transform(Mockito.mock(BundleContext.class), "xx"));
59     }
60
61     @Test
62     public void testTransformationNull() {
63         SingleValueTransformation transformation = new SingleValueTransformation(null);
64         assertFalse(transformation.isIdentityTransform());
65         assertEquals("", transformation.transform(Mockito.mock(BundleContext.class), "xx"));
66     }
67
68     @Test
69     public void testTransformationDefault() {
70         SingleValueTransformation transformation = new SingleValueTransformation("deFault");
71         assertTrue(transformation.isIdentityTransform());
72         assertEquals("xx", transformation.transform(Mockito.mock(BundleContext.class), "xx"));
73     }
74
75     @Test
76     public void testTransformationDefaultChainedWithStatic() {
77         SingleValueTransformation transformation = new SingleValueTransformation("static");
78         assertFalse(transformation.isIdentityTransform());
79         assertEquals("static", transformation.transform(Mockito.mock(BundleContext.class), "xx"));
80     }
81 }