]> git.basschouten.com Git - openhab-addons.git/blob
b1744b40ab13bb55f2f694569a516b49e9f69b43
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.Test;
19 import org.mockito.Mockito;
20 import org.osgi.framework.BundleContext;
21
22 /**
23  * @author Sami Salonen - Initial contribution
24  */
25 @NonNullByDefault
26 public class SingleValueTransformationTest {
27
28     @Test
29     public void testTransformationOldStyle() {
30         SingleValueTransformation transformation = new SingleValueTransformation("REGEX(myregex:foo(.*))");
31         assertEquals("REGEX", transformation.transformationServiceName);
32         assertEquals("myregex:foo(.*)", transformation.transformationServiceParam);
33     }
34
35     @Test
36     public void testTransformationOldStyle2() {
37         SingleValueTransformation transformation = new SingleValueTransformation("REG_(EX(myregex:foo(.*))");
38         assertEquals("REG_", transformation.transformationServiceName);
39         assertEquals("EX(myregex:foo(.*)", transformation.transformationServiceParam);
40     }
41
42     @Test
43     public void testTransformationNewStyle() {
44         SingleValueTransformation transformation = new SingleValueTransformation("REGEX:myregex(.*)");
45         assertEquals("REGEX", transformation.transformationServiceName);
46         assertEquals("myregex(.*)", transformation.transformationServiceParam);
47     }
48
49     @Test
50     public void testTransformationNewStyle2() {
51         SingleValueTransformation transformation = new SingleValueTransformation("REGEX::myregex(.*)");
52         assertEquals("REGEX", transformation.transformationServiceName);
53         assertEquals(":myregex(.*)", transformation.transformationServiceParam);
54     }
55
56     @Test
57     public void testTransformationEmpty() {
58         SingleValueTransformation transformation = new SingleValueTransformation("");
59         assertFalse(transformation.isIdentityTransform());
60         assertEquals("", transformation.transform(Mockito.mock(BundleContext.class), "xx"));
61     }
62
63     @Test
64     public void testTransformationNull() {
65         SingleValueTransformation transformation = new SingleValueTransformation(null);
66         assertFalse(transformation.isIdentityTransform());
67         assertEquals("", transformation.transform(Mockito.mock(BundleContext.class), "xx"));
68     }
69
70     @Test
71     public void testTransformationDefault() {
72         SingleValueTransformation transformation = new SingleValueTransformation("deFault");
73         assertTrue(transformation.isIdentityTransform());
74         assertEquals("xx", transformation.transform(Mockito.mock(BundleContext.class), "xx"));
75     }
76
77     @Test
78     public void testTransformationDefaultChainedWithStatic() {
79         SingleValueTransformation transformation = new SingleValueTransformation("static");
80         assertFalse(transformation.isIdentityTransform());
81         assertEquals("static", transformation.transform(Mockito.mock(BundleContext.class), "xx"));
82     }
83 }