]> git.basschouten.com Git - openhab-addons.git/blob
d668ac047ea7255d006d27a23e03b21e5c468071
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.transform.jinja.internal;
14
15 import org.junit.Assert;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.openhab.core.transform.TransformationException;
19
20 /**
21  * @author Jochen Klein - Initial contribution
22  */
23 public class JinjaTransformationServiceTest {
24
25     private JinjaTransformationService processor;
26
27     @Before
28     public void init() {
29         processor = new JinjaTransformationService();
30     }
31
32     @Test
33     public void testTransformByJSon() throws TransformationException {
34         String json = "{\"Time\":\"2019-01-05T22:45:12\",\"AM2301\":{\"Temperature\":4.7,\"Humidity\":99.9},\"TempUnit\":\"C\"}";
35         // method under test
36         String transformedResponse = processor.transform("{{value_json['AM2301'].Temperature}}", json);
37
38         // Asserts
39         Assert.assertEquals("4.7", transformedResponse);
40     }
41
42     @Test
43     public void testStringOnly() throws TransformationException {
44         String value = "world";
45         // method under test
46         String transformedResponse = processor.transform("Hello {{ value }}!", value);
47
48         // Asserts
49         Assert.assertEquals("Hello world!", transformedResponse);
50     }
51
52     @Test
53     public void testQuotedStringOnly() throws TransformationException {
54         String value = "\"world\"";
55         // method under test
56         String transformedResponse = processor.transform("Hello {{ value_json }}!", value);
57
58         // Asserts
59         Assert.assertEquals("Hello world!", transformedResponse);
60     }
61 }