brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [6/8] brooklyn-server git commit: Make sure entity doesn't equal null
Date Fri, 11 Nov 2016 09:50:22 GMT
Make sure entity doesn't equal null


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

Branch: refs/heads/master
Commit: fe2b4b6997c1d48541f100d3fcb02f6f89223426
Parents: b6af270
Author: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Authored: Thu Nov 10 22:24:36 2016 +0200
Committer: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Committed: Thu Nov 10 22:46:46 2016 +0200

----------------------------------------------------------------------
 .../org/apache/brooklyn/core/entity/AbstractEntity.java     | 5 +++--
 .../brooklyn/core/entity/AbstractApplicationLegacyTest.java | 9 +++++++--
 .../apache/brooklyn/core/entity/EntityAutomanagedTest.java  | 7 +++++++
 3 files changed, 17 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/fe2b4b69/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java b/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
index 6c5f73e..fd7a403 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
@@ -429,8 +429,9 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements
E
     
     @Override
     public boolean equals(Object o) {
-        return (o == this || o == selfProxy) || 
-                (o instanceof Entity && Objects.equal(getId(), ((Entity)o).getId()));
+        return o != null &&
+                ((o == this || o == selfProxy) ||
+                (o instanceof Entity && Objects.equal(getId(), ((Entity)o).getId())));
     }
     
     /** internal use only */ @Beta

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/fe2b4b69/core/src/test/java/org/apache/brooklyn/core/entity/AbstractApplicationLegacyTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/entity/AbstractApplicationLegacyTest.java
b/core/src/test/java/org/apache/brooklyn/core/entity/AbstractApplicationLegacyTest.java
index d1d4dc3..68ac612 100644
--- a/core/src/test/java/org/apache/brooklyn/core/entity/AbstractApplicationLegacyTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/entity/AbstractApplicationLegacyTest.java
@@ -20,6 +20,8 @@ package org.apache.brooklyn.core.entity;
 
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotEquals;
+import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertTrue;
 
 import java.util.List;
@@ -92,8 +94,11 @@ public class AbstractApplicationLegacyTest extends BrooklynAppUnitTestSupport
{
         assertTrue(Entities.isManaged(app2));
         assertTrue(Entities.isManaged(child));
         assertEquals(child.getCallHistory(), ImmutableList.of("start"));
-        assertEquals(mgmt.getEntityManager().getEntity(app2.getId()), app2);
-        assertEquals(mgmt.getEntityManager().getEntity(child.getId()), child);
+        assertNull(mgmt.getEntityManager().getEntity(app2.getId()), "app2 shouldn't be managed
by mgmt");
+        assertNull(mgmt.getEntityManager().getEntity(child.getId()), "child shouldn't be
managed by mgmt");
+        assertNotEquals(mgmt, app2.getManagementContext(), "managing app2 creates a new management
context");
+        assertEquals(app2.getManagementContext().getEntityManager().getEntity(app2.getId()),
app2);
+        assertEquals(app2.getManagementContext().getEntityManager().getEntity(child.getId()),
child);
         
         app2.stop();
         assertEquals(child.getCallHistory(), ImmutableList.of("start", "stop"));

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/fe2b4b69/core/src/test/java/org/apache/brooklyn/core/entity/EntityAutomanagedTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/entity/EntityAutomanagedTest.java
b/core/src/test/java/org/apache/brooklyn/core/entity/EntityAutomanagedTest.java
index 741b936..84c7eef 100644
--- a/core/src/test/java/org/apache/brooklyn/core/entity/EntityAutomanagedTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/entity/EntityAutomanagedTest.java
@@ -20,6 +20,7 @@ package org.apache.brooklyn.core.entity;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotEquals;
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
 
@@ -32,6 +33,7 @@ import org.apache.brooklyn.core.entity.EntityAutomanagedTest.RecordingCollection
 import org.apache.brooklyn.core.entity.EntityAutomanagedTest.RecordingCollectionChangeListener.ChangeType;
 import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
 import org.apache.brooklyn.core.test.entity.TestApplication;
+import org.apache.brooklyn.core.test.entity.TestApplicationImpl;
 import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.test.Asserts;
 import org.testng.annotations.BeforeMethod;
@@ -263,6 +265,11 @@ public class EntityAutomanagedTest extends BrooklynAppUnitTestSupport
{
         listener.assertEventsEqualsEventually(ImmutableList.of(new ChangeEvent(ChangeType.ADDED,
e)));
     }
 
+    @Test
+    public void testEntityNotEqualNull() {
+        assertNotEquals(new TestApplicationImpl(), null);
+    }
+
     // TODO Compiler problems - see comment at top of class
     public static class RecordingCollectionChangeListener { // FIXME implements CollectionChangeListener<Entity>
{
         public enum ChangeType {


Mime
View raw message