You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by gr...@apache.org on 2014/11/04 22:13:46 UTC

[5/7] git commit: Convert TestPortSupplierLocation from groovy to java

Convert TestPortSupplierLocation from groovy to java


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/cf762134
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/cf762134
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/cf762134

Branch: refs/heads/master
Commit: cf762134b177d6d3ae816bdd9e679ae7f7a7fc68
Parents: 0826dfc
Author: Aled Sage <al...@gmail.com>
Authored: Tue Nov 4 14:00:04 2014 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Nov 4 14:37:19 2014 +0000

----------------------------------------------------------------------
 .../basic/TestPortSupplierLocation.groovy       | 94 --------------------
 .../basic/TestPortSupplierLocation.java         | 90 +++++++++++++++++++
 2 files changed, 90 insertions(+), 94 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cf762134/core/src/test/java/brooklyn/location/basic/TestPortSupplierLocation.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/location/basic/TestPortSupplierLocation.groovy b/core/src/test/java/brooklyn/location/basic/TestPortSupplierLocation.groovy
deleted file mode 100644
index 51579d6..0000000
--- a/core/src/test/java/brooklyn/location/basic/TestPortSupplierLocation.groovy
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.location.basic
-
-import org.testng.Assert
-import org.testng.annotations.AfterMethod
-import org.testng.annotations.BeforeMethod
-import org.testng.annotations.Test
-
-import brooklyn.entity.basic.Entities
-import brooklyn.entity.proxying.EntitySpec
-import brooklyn.event.basic.PortAttributeSensorAndConfigKey
-import brooklyn.event.feed.ConfigToAttributes
-import brooklyn.test.entity.TestApplication
-import brooklyn.test.entity.TestEntity
-
-public class TestPortSupplierLocation {
-
-    SimulatedLocation l;
-    PortAttributeSensorAndConfigKey ps;
-    TestApplication app;
-    TestEntity e;
-    
-    @BeforeMethod
-    public void setup() {
-        l = new SimulatedLocation();
-        app = TestApplication.Factory.newManagedInstanceForTests();
-        e = app.createAndManageChild(EntitySpec.create(TestEntity.class));
-        app.start([l]);
-        
-        ps = new PortAttributeSensorAndConfigKey("some.port", "for testing", "1234+");
-    }
-
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-
-    @Test
-    public void testObtainsPort() {
-        ConfigToAttributes.apply(e, ps);
-        
-        int p = e.getAttribute(ps);
-        Assert.assertEquals(p, 1234);
-        
-        //sensor access should keep the same value
-        p = e.getAttribute(ps);
-        Assert.assertEquals(p, 1234);
-    }
-    
-    @Test
-    public void testRepeatedConvertAccessIncrements() {
-        int p = ps.getAsSensorValue(e);
-        Assert.assertEquals(p, 1234);
-
-        //but direct access should see it as being reserved (not required behaviour, but it is the current behaviour)
-        int p2 = ps.getAsSensorValue(e);
-        Assert.assertEquals(p2, 1235);
-    }
-
-    @Test
-    public void testNullBeforeSetting() {
-        // currently getting the attribute before explicitly setting return null; i.e. no "auto-set" -- 
-        // but this behaviour may be changed
-        Integer p = e.getAttribute(ps);
-        Assert.assertEquals(p, null);
-    }
-
-    @Test
-    public void testSimulatedRestrictedPermitted() {
-        l.setPermittedPorts(PortRanges.fromString("1240+"));
-        
-        ConfigToAttributes.apply(e, ps);
-        int p = e.getAttribute(ps);
-        Assert.assertEquals((int)p, 1240);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cf762134/core/src/test/java/brooklyn/location/basic/TestPortSupplierLocation.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/location/basic/TestPortSupplierLocation.java b/core/src/test/java/brooklyn/location/basic/TestPortSupplierLocation.java
new file mode 100644
index 0000000..2d3c3bb
--- /dev/null
+++ b/core/src/test/java/brooklyn/location/basic/TestPortSupplierLocation.java
@@ -0,0 +1,90 @@
+/*
+ * 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.location.basic;
+
+import static org.testng.Assert.assertEquals;
+
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import brooklyn.entity.BrooklynAppUnitTestSupport;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.event.basic.PortAttributeSensorAndConfigKey;
+import brooklyn.event.feed.ConfigToAttributes;
+import brooklyn.test.entity.TestEntity;
+
+import com.google.common.collect.ImmutableList;
+
+public class TestPortSupplierLocation extends BrooklynAppUnitTestSupport {
+
+    SimulatedLocation loc;
+    PortAttributeSensorAndConfigKey ps;
+    TestEntity entity;
+    
+    @BeforeMethod(alwaysRun=true)
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        loc = app.newSimulatedLocation();
+        entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
+        app.start(ImmutableList.of(loc));
+        
+        ps = new PortAttributeSensorAndConfigKey("some.port", "for testing", "1234+");
+    }
+
+    @Test
+    public void testObtainsPort() throws Exception {
+        ConfigToAttributes.apply(entity, ps);
+        
+        int p = entity.getAttribute(ps);
+        assertEquals(p, 1234);
+        
+        //sensor access should keep the same value
+        p = entity.getAttribute(ps);
+        assertEquals(p, 1234);
+    }
+    
+    @Test
+    public void testRepeatedConvertAccessIncrements() throws Exception {
+        int p = ps.getAsSensorValue(entity);
+        assertEquals(p, 1234);
+
+        //but direct access should see it as being reserved (not required behaviour, but it is the current behaviour)
+        int p2 = ps.getAsSensorValue(entity);
+        assertEquals(p2, 1235);
+    }
+
+    @Test
+    public void testNullBeforeSetting() throws Exception {
+        // currently getting the attribute before explicitly setting return null; i.e. no "auto-set" -- 
+        // but this behaviour may be changed
+        Integer p = entity.getAttribute(ps);
+        assertEquals(p, null);
+    }
+
+    @Test
+    public void testSimulatedRestrictedPermitted() throws Exception {
+        loc.setPermittedPorts(PortRanges.fromString("1240+"));
+        
+        ConfigToAttributes.apply(entity, ps);
+        int p = entity.getAttribute(ps);
+        assertEquals((int)p, 1240);
+    }
+
+}