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 C4D05195E6 for ; Mon, 14 Mar 2016 22:04:02 +0000 (UTC) Received: (qmail 67087 invoked by uid 500); 14 Mar 2016 22:04:02 -0000 Delivered-To: apmail-brooklyn-commits-archive@brooklyn.apache.org Received: (qmail 67022 invoked by uid 500); 14 Mar 2016 22:04:02 -0000 Mailing-List: contact commits-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list commits@brooklyn.apache.org Received: (qmail 66984 invoked by uid 99); 14 Mar 2016 22:04:02 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Mar 2016 22:04:02 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6F123DFA40; Mon, 14 Mar 2016 22:04:02 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aledsage@apache.org To: commits@brooklyn.apache.org Date: Mon, 14 Mar 2016 22:04:02 -0000 Message-Id: <07821ca3365b4df0a335897dde4686f1@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/4] brooklyn-server git commit: Adds tests for out-of-the-box ExternalConfigSuppliers Repository: brooklyn-server Updated Branches: refs/heads/master 1465b040b -> 1f6d5d987 Adds tests for out-of-the-box ExternalConfigSuppliers Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/ec3684d4 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/ec3684d4 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/ec3684d4 Branch: refs/heads/master Commit: ec3684d4ce33dc338a73c4f4c149565aac0da019 Parents: f20bf0e Author: Aled Sage Authored: Fri Mar 11 19:34:29 2016 +0000 Committer: Aled Sage Committed: Fri Mar 11 19:34:29 2016 +0000 ---------------------------------------------------------------------- .../InPlaceExternalConfigSupplierTest.java | 60 +++++++++++++++ ...ropertiesFileExternalConfigSupplierTest.java | 81 ++++++++++++++++++++ 2 files changed, 141 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ec3684d4/core/src/test/java/org/apache/brooklyn/core/config/external/InPlaceExternalConfigSupplierTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/core/config/external/InPlaceExternalConfigSupplierTest.java b/core/src/test/java/org/apache/brooklyn/core/config/external/InPlaceExternalConfigSupplierTest.java new file mode 100644 index 0000000..2746d31 --- /dev/null +++ b/core/src/test/java/org/apache/brooklyn/core/config/external/InPlaceExternalConfigSupplierTest.java @@ -0,0 +1,60 @@ +/* + * 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 org.apache.brooklyn.core.config.external; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; + +import org.apache.brooklyn.core.entity.Entities; +import org.apache.brooklyn.core.internal.BrooklynProperties; +import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal; +import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.Test; + +public class InPlaceExternalConfigSupplierTest { + + @SuppressWarnings("unused") + private static final Logger LOG = LoggerFactory.getLogger(InPlaceExternalConfigSupplierTest.class); + + protected ManagementContextInternal mgmt; + + @AfterMethod(alwaysRun=true) + public void tearDown() throws Exception { + try { + if (mgmt != null) Entities.destroyAll(mgmt); + } finally { + mgmt = null; + } + } + + @Test + public void testInPlace() throws Exception { + BrooklynProperties props = BrooklynProperties.Factory.newEmpty(); + props.put("brooklyn.external.foo", InPlaceExternalConfigSupplier.class.getName()); + props.put("brooklyn.external.foo.mykey", "myval"); + + mgmt = LocalManagementContextForTests.newInstance(props); + + assertEquals(mgmt.getExternalConfigProviderRegistry().getConfig("foo", "mykey"), "myval"); + assertNull(mgmt.getExternalConfigProviderRegistry().getConfig("foo", "wrongkey")); + } +} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ec3684d4/core/src/test/java/org/apache/brooklyn/core/config/external/PropertiesFileExternalConfigSupplierTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/core/config/external/PropertiesFileExternalConfigSupplierTest.java b/core/src/test/java/org/apache/brooklyn/core/config/external/PropertiesFileExternalConfigSupplierTest.java new file mode 100644 index 0000000..329ddcc --- /dev/null +++ b/core/src/test/java/org/apache/brooklyn/core/config/external/PropertiesFileExternalConfigSupplierTest.java @@ -0,0 +1,81 @@ +/* + * 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 org.apache.brooklyn.core.config.external; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; + +import java.io.File; + +import org.apache.brooklyn.core.entity.Entities; +import org.apache.brooklyn.core.internal.BrooklynProperties; +import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal; +import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import com.google.common.base.Charsets; +import com.google.common.io.Files; + +public class PropertiesFileExternalConfigSupplierTest { + + // TODO I (Aled) thought that the ExternalConfigSuppliers were re-initialised when + // mgmt.reloadBrooklynProperties was called, but that doesn't seem to be the case. + + @SuppressWarnings("unused") + private static final Logger LOG = LoggerFactory.getLogger(PropertiesFileExternalConfigSupplierTest.class); + + protected File propsFile; + protected ManagementContextInternal mgmt; + + @BeforeMethod(alwaysRun=true) + public void setUp() throws Exception { + propsFile = File.createTempFile("PropertiesFileExternalConfigSupplierTest", ".properties"); + } + + @AfterMethod(alwaysRun=true) + public void tearDown() throws Exception { + try { + if (mgmt != null) Entities.destroyAll(mgmt); + } finally { + mgmt = null; + if (propsFile != null) propsFile.delete(); + } + } + + @Test + public void testFromProperties() throws Exception { + String contents = + "mykey=myval"+"\n"+ + "mykey2=myval2"; + Files.write(contents, propsFile, Charsets.UTF_8); + BrooklynProperties props = BrooklynProperties.Factory.newEmpty(); + props.put("brooklyn.external.foo", PropertiesFileExternalConfigSupplier.class.getName()); + props.put("brooklyn.external.foo.propertiesUrl", propsFile.toURI().toString()); + + mgmt = LocalManagementContextForTests.newInstance(props); + + assertEquals(mgmt.getExternalConfigProviderRegistry().getConfig("foo", "mykey"), "myval"); + assertEquals(mgmt.getExternalConfigProviderRegistry().getConfig("foo", "mykey2"), "myval2"); + assertNull(mgmt.getExternalConfigProviderRegistry().getConfig("foo", "wrongkey")); + } +}