2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.transform.jinja.internal;
15 import static org.junit.jupiter.api.Assertions.*;
17 import org.junit.jupiter.api.BeforeEach;
18 import org.junit.jupiter.api.Test;
19 import org.openhab.core.transform.TransformationException;
22 * @author Jochen Klein - Initial contribution
24 public class JinjaTransformationServiceTest {
26 private JinjaTransformationService processor;
30 processor = new JinjaTransformationService();
34 public void testTransformByJSon() throws TransformationException {
35 String json = "{\"Time\":\"2019-01-05T22:45:12\",\"AM2301\":{\"Temperature\":4.7,\"Humidity\":99.9},\"TempUnit\":\"C\"}";
37 String transformedResponse = processor.transform("{{value_json['AM2301'].Temperature}}", json);
40 assertEquals("4.7", transformedResponse);
44 public void testStringOnly() throws TransformationException {
45 String value = "world";
47 String transformedResponse = processor.transform("Hello {{ value }}!", value);
50 assertEquals("Hello world!", transformedResponse);
54 public void testQuotedStringOnly() throws TransformationException {
55 String value = "\"world\"";
57 String transformedResponse = processor.transform("Hello {{ value_json }}!", value);
60 assertEquals("Hello world!", transformedResponse);