Return-Path: X-Original-To: apmail-brooklyn-commits-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 96A67114D7 for ; Mon, 1 Sep 2014 16:55:59 +0000 (UTC) Received: (qmail 26153 invoked by uid 500); 1 Sep 2014 16:55:59 -0000 Delivered-To: apmail-brooklyn-commits-archive@brooklyn.apache.org Received: (qmail 26131 invoked by uid 500); 1 Sep 2014 16:55:59 -0000 Mailing-List: contact commits-help@brooklyn.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.incubator.apache.org Delivered-To: mailing list commits@brooklyn.incubator.apache.org Received: (qmail 26122 invoked by uid 99); 1 Sep 2014 16:55:59 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Sep 2014 16:55:59 +0000 X-ASF-Spam-Status: No, hits=-2001.7 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 01 Sep 2014 16:55:35 +0000 Received: (qmail 25527 invoked by uid 99); 1 Sep 2014 16:55:32 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Sep 2014 16:55:32 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 787AD957DCC; Mon, 1 Sep 2014 16:55:32 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: heneveld@apache.org To: commits@brooklyn.incubator.apache.org Date: Mon, 01 Sep 2014 16:55:37 -0000 Message-Id: In-Reply-To: <0ca4909fc9864f3e85f9dfc5e86bb5df@git.apache.org> References: <0ca4909fc9864f3e85f9dfc5e86bb5df@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [06/11] git commit: Adds TemplateProcessorTest X-Virus-Checked: Checked by ClamAV on apache.org Adds TemplateProcessorTest - includes failing tests for: -- testApplyTemplatedConfigWithAttributeWhenReady -- testManagementContextConfigWithDot Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/35d08efd Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/35d08efd Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/35d08efd Branch: refs/heads/master Commit: 35d08efdab0a457aabddc089f768ef405046e803 Parents: 7eda671 Author: Aled Sage Authored: Wed Aug 20 10:00:52 2014 +0100 Committer: Aled Sage Committed: Wed Aug 20 10:00:52 2014 +0100 ---------------------------------------------------------------------- .../util/text/TemplateProcessorTest.java | 99 ++++++++++++++++++++ 1 file changed, 99 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/35d08efd/core/src/test/java/brooklyn/util/text/TemplateProcessorTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/brooklyn/util/text/TemplateProcessorTest.java b/core/src/test/java/brooklyn/util/text/TemplateProcessorTest.java new file mode 100644 index 0000000..35c1a8e --- /dev/null +++ b/core/src/test/java/brooklyn/util/text/TemplateProcessorTest.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 brooklyn.util.text; + +import static org.testng.Assert.assertEquals; + +import org.testng.annotations.Test; + +import brooklyn.entity.BrooklynAppUnitTestSupport; +import brooklyn.entity.proxying.EntitySpec; +import brooklyn.event.basic.DependentConfiguration; +import brooklyn.test.entity.TestApplication; +import brooklyn.test.entity.TestEntity; + +import com.google.common.collect.ImmutableMap; + +public class TemplateProcessorTest extends BrooklynAppUnitTestSupport { + + @Test + public void testAdditionalArgs() { + TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class) + .configure(TestEntity.CONF_NAME, "myval")); + String templateContents = "${mykey}"; + String result = TemplateProcessor.processTemplateContents(templateContents, entity, ImmutableMap.of("mykey", "myval")); + assertEquals(result, "myval"); + } + + @Test + public void testGetSysProp() { + System.setProperty("testGetSysProp", "myval"); + + String templateContents = "${javaSysProps['testGetSysProp']}"; + String result = TemplateProcessor.processTemplateContents(templateContents, app, ImmutableMap.of()); + assertEquals(result, "myval"); + } + + @Test + public void testEntityGetterMethod() { + String templateContents = "${entity.id}"; + String result = TemplateProcessor.processTemplateContents(templateContents, app, ImmutableMap.of()); + assertEquals(result, app.getId()); + } + + @Test + public void testEntityConfig() { + TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class) + .configure(TestEntity.CONF_NAME, "myval")); + String templateContents = "${config['"+TestEntity.CONF_NAME.getName()+"']}"; + String result = TemplateProcessor.processTemplateContents(templateContents, entity, ImmutableMap.of()); + assertEquals(result, "myval"); + } + + // TODO Should this be under a sub-map (e.g. globalConfig or some such)? + @Test + public void testManagementContextConfig() { + mgmt.getBrooklynProperties().put("globalmykey", "myval"); + String templateContents = "${globalmykey}"; + String result = TemplateProcessor.processTemplateContents(templateContents, app, ImmutableMap.of()); + assertEquals(result, "myval"); + } + + // FIXME Fails because tries to get global, and then call getMyKey() + @Test(groups="WIP") + public void testManagementContextConfigWithDot() { + mgmt.getBrooklynProperties().put("global.mykey", "myval"); + String templateContents = "${global.mykey}"; + String result = TemplateProcessor.processTemplateContents(templateContents, app, ImmutableMap.of()); + assertEquals(result, "myval"); + } + + // FIXME Fails because does not respect attributeWhenReady; just returns its toString + @Test(groups="WIP") + public void testApplyTemplatedConfigWithAttributeWhenReady() { + app.setAttribute(TestApplication.MY_ATTRIBUTE, "myval"); + + TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class) + .configure(TestEntity.CONF_NAME, DependentConfiguration.attributeWhenReady(app, TestApplication.MY_ATTRIBUTE))); + + String templateContents = "${config['"+TestEntity.CONF_NAME.getName()+"']}"; + String result = TemplateProcessor.processTemplateContents(templateContents, entity, ImmutableMap.of()); + assertEquals(result, "myval"); + } +}