blob: 2bbc3e7dd1bc4fa6a97b0a8c84a820a83931e4e6 [file] [log] [blame]
/**
* Copyright (C) 2015 DataTorrent, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.datatorrent.stram.client;
import java.util.Properties;
import org.apache.hadoop.conf.Configuration;
import org.junit.Assert;
import org.junit.Test;
/**
*
*/
public class EvalPropertiesTest
{
@Test
public void testEvalExpression() throws Exception
{
Configuration conf = new Configuration();
conf.set("a.b.c", "123");
conf.set("d.e.f", "456");
conf.set("x.y.z", "foobar");
Properties prop = new Properties();
prop.put("product.result", "Product result is {% (_prop[\"a.b.c\"] * _prop[\"d.e.f\"]).toFixed(0) %}...");
prop.put("concat.result", "Concat result is {% _prop[\"x.y.z\"] %} ... {% _prop[\"a.b.c\"] %} blah");
StramClientUtils.evalProperties(prop, conf);
Assert.assertEquals("Product result is " + (123 * 456) + "...", prop.get("product.result"));
Assert.assertEquals("Concat result is foobar ... 123 blah", prop.get("concat.result"));
Assert.assertEquals("123", conf.get("a.b.c"));
Assert.assertEquals("456", conf.get("d.e.f"));
Assert.assertEquals("foobar", conf.get("x.y.z"));
}
@Test
public void testVariableSubstitution() throws Exception
{
Configuration conf = new Configuration();
conf.set("a.b.c", "123");
conf.set("x.y.z", "foobar");
Properties prop = new Properties();
prop.put("var.result", "1111 ${a.b.c} xxx ${x.y.z} yyy");
StramClientUtils.evalProperties(prop, conf);
Assert.assertEquals("1111 123 xxx foobar yyy", prop.get("var.result"));
}
}