brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [1/4] brooklyn-server git commit: Adds tests for out-of-the-box ExternalConfigSuppliers
Date Mon, 14 Mar 2016 22:04:02 GMT
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 <aled.sage@gmail.com>
Authored: Fri Mar 11 19:34:29 2016 +0000
Committer: Aled Sage <aled.sage@gmail.com>
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"));
+    }
+}


Mime
View raw message