You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2015/07/07 13:48:33 UTC
[1/3] git commit: updated refs/heads/master to 4ad178e
Repository: cloudstack
Updated Branches:
refs/heads/master 4bba49941 -> 4ad178e4b
findbugs: equals unit tests
Signed-off-by: Daan Hoogland <da...@onecht.net>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/d8ab5f3a
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/d8ab5f3a
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/d8ab5f3a
Branch: refs/heads/master
Commit: d8ab5f3ab815579c651150ad273facd0854ea51f
Parents: 3462944
Author: Daan Hoogland <da...@gmail.com>
Authored: Mon Jul 6 16:07:02 2015 +0200
Committer: Daan Hoogland <da...@onecht.net>
Committed: Tue Jul 7 13:48:19 2015 +0200
----------------------------------------------------------------------
.../org/apache/cloudstack/storage/BaseType.java | 11 +++++--
.../apache/cloudstack/storage/BaseTypeTest.java | 32 ++++++++++++++++++
.../framework/config/ConfigKeyTest.java | 34 ++++++++++++++++++++
pom.xml | 1 +
utils/pom.xml | 5 +++
utils/src/com/cloud/utils/net/Ip4Address.java | 11 ++++---
.../com/cloud/utils/net/Ip4AddressTest.java | 24 ++++++++++++++
utils/test/com/cloud/utils/net/IpTest.java | 17 ++++++++++
8 files changed, 127 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d8ab5f3a/engine/storage/src/org/apache/cloudstack/storage/BaseType.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/BaseType.java b/engine/storage/src/org/apache/cloudstack/storage/BaseType.java
index 6d27772..1df02ba 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/BaseType.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/BaseType.java
@@ -25,19 +25,24 @@ public abstract class BaseType {
return true;
} else if (that instanceof BaseType) {
BaseType th = (BaseType)that;
- if (this.toString().equalsIgnoreCase(th.toString())) {
+ if (toString().equalsIgnoreCase(th.toString())) {
return true;
}
}
return false;
}
+ @Override
+ public int hashCode() {
+ return toString().toLowerCase().hashCode();
+ }
+
public boolean isSameTypeAs(Object that) {
- if (this.equals(that)){
+ if (equals(that)){
return true;
}
if (that instanceof String) {
- if (this.toString().equalsIgnoreCase((String)that)) {
+ if (toString().equalsIgnoreCase((String)that)) {
return true;
}
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d8ab5f3a/engine/storage/test/org/apache/cloudstack/storage/BaseTypeTest.java
----------------------------------------------------------------------
diff --git a/engine/storage/test/org/apache/cloudstack/storage/BaseTypeTest.java b/engine/storage/test/org/apache/cloudstack/storage/BaseTypeTest.java
new file mode 100644
index 0000000..5cce015
--- /dev/null
+++ b/engine/storage/test/org/apache/cloudstack/storage/BaseTypeTest.java
@@ -0,0 +1,32 @@
+package org.apache.cloudstack.storage;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.google.common.testing.EqualsTester;
+
+public class BaseTypeTest {
+ @Test
+ public void testEquals() {
+ new EqualsTester()
+ .addEqualityGroup(new TestType("a"), new TestType("A"))
+ .addEqualityGroup(new TestType("Bd"), new TestType("bD"))
+ .testEquals();
+ }
+
+ @Test
+ public void testIsSameTypeAs() {
+ Assert.assertTrue("'a' and 'A' should be considdered the same type", new TestType("a").isSameTypeAs("A"));
+ Assert.assertTrue("'B' and 'b' should be considdered the same address", new TestType("B").isSameTypeAs(new TestType("b")));
+ }
+ class TestType extends BaseType {
+ String content;
+ public TestType(String t) {
+ content = t;
+ }
+ @Override
+ public String toString() {
+ return content;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d8ab5f3a/framework/config/test/org/apache/cloudstack/framework/config/ConfigKeyTest.java
----------------------------------------------------------------------
diff --git a/framework/config/test/org/apache/cloudstack/framework/config/ConfigKeyTest.java b/framework/config/test/org/apache/cloudstack/framework/config/ConfigKeyTest.java
new file mode 100644
index 0000000..b02ac1f
--- /dev/null
+++ b/framework/config/test/org/apache/cloudstack/framework/config/ConfigKeyTest.java
@@ -0,0 +1,34 @@
+package org.apache.cloudstack.framework.config;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.google.common.testing.EqualsTester;
+
+import org.apache.cloudstack.framework.config.ConfigKey.Scope;
+
+import com.cloud.utils.exception.CloudRuntimeException;
+
+public class ConfigKeyTest {
+ @Test
+ public void testEquals() {
+ new EqualsTester()
+ .addEqualityGroup(new ConfigKey("cat", String.class, "naam", "nick", "bijnaam", true, Scope.Cluster),
+ new ConfigKey("hond", Boolean.class, "naam", "truus", "thrown name", false),
+ new ConfigKey(Long.class, "naam", "vis", "goud", "zwemt", true, Scope.Account, 3L)
+ )
+ .testEquals();
+ }
+
+ @Test
+ public void testIsSameKeyAs() {
+ ConfigKey key = new ConfigKey("cat", String.class, "naam", "nick", "bijnaam", true, Scope.Cluster);
+ Assert.assertTrue("1 and one should be considdered the same address", key.isSameKeyAs("naam"));
+ }
+
+ @Test(expected = CloudRuntimeException.class)
+ public void testIsSameKeyAsThrowingCloudRuntimeException() {
+ ConfigKey key = new ConfigKey("hond", Boolean.class, "naam", "truus", "thrown name", false);
+ Assert.assertFalse("zero and 0L should be considdered the same address", key.isSameKeyAs(0L));
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d8ab5f3a/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 900f2e4..e76d747 100644
--- a/pom.xml
+++ b/pom.xml
@@ -63,6 +63,7 @@
<cs.trilead.version>1.0.0-build217</cs.trilead.version>
<cs.ehcache.version>2.6.9</cs.ehcache.version>
<cs.gson.version>1.7.2</cs.gson.version>
+ <cs.guava-testlib.version>18.0</cs.guava-testlib.version>
<cs.guava.version>18.0</cs.guava.version>
<cs.xapi.version>6.2.0-3.1</cs.xapi.version>
<cs.httpclient.version>4.3.6</cs.httpclient.version>
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d8ab5f3a/utils/pom.xml
----------------------------------------------------------------------
diff --git a/utils/pom.xml b/utils/pom.xml
index c1a5610..937dc08 100755
--- a/utils/pom.xml
+++ b/utils/pom.xml
@@ -162,6 +162,11 @@
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava-testlib</artifactId>
+ <version>${cs.guava-testlib.version}</version>
+ </dependency>
</dependencies>
<build>
<plugins>
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d8ab5f3a/utils/src/com/cloud/utils/net/Ip4Address.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/net/Ip4Address.java b/utils/src/com/cloud/utils/net/Ip4Address.java
index 9712a1f..0bd814d 100644
--- a/utils/src/com/cloud/utils/net/Ip4Address.java
+++ b/utils/src/com/cloud/utils/net/Ip4Address.java
@@ -22,6 +22,7 @@ package com.cloud.utils.net;
public class Ip4Address {
String _addr;
String _mac;
+ static final String s_empty_mac = "00:00:00:00:00:00";
public Ip4Address(String addr, String mac) {
_addr = addr;
@@ -34,11 +35,11 @@ public class Ip4Address {
}
public Ip4Address(String addr) {
- this(addr, null);
+ this(addr, s_empty_mac);
}
public Ip4Address(long addr) {
- this(NetUtils.long2Ip(addr), null);
+ this(NetUtils.long2Ip(addr), s_empty_mac);
}
public String ip4() {
@@ -58,7 +59,7 @@ public class Ip4Address {
if (that instanceof Ip4Address) {
Ip4Address ip4 = (Ip4Address)that;
- return this._addr.equals(ip4._addr) && (this._mac == ip4._mac || this._mac.equals(ip4._mac));
+ return _addr.equals(ip4._addr) && (_mac == ip4._mac || _mac.equals(ip4._mac));
} else {
return false;
}
@@ -68,12 +69,12 @@ public class Ip4Address {
if (other instanceof String) { // Assume that is an ip4 address in String form
return _addr.equals(other);
} else {
- return this.equals(other);
+ return equals(other);
}
}
@Override
public int hashCode(){
- return (int)(_mac.hashCode()*_addr.hashCode());
+ return _mac.hashCode()*_addr.hashCode();
}
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d8ab5f3a/utils/test/com/cloud/utils/net/Ip4AddressTest.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/net/Ip4AddressTest.java b/utils/test/com/cloud/utils/net/Ip4AddressTest.java
new file mode 100644
index 0000000..d4e24d3
--- /dev/null
+++ b/utils/test/com/cloud/utils/net/Ip4AddressTest.java
@@ -0,0 +1,24 @@
+package com.cloud.utils.net;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.google.common.testing.EqualsTester;
+
+public class Ip4AddressTest {
+
+ @Test
+ public void testEquals() throws Exception {
+ new EqualsTester()
+ .addEqualityGroup(new Ip4Address("0.0.0.1", "00:00:00:00:00:02"), new Ip4Address(1L, 2L))
+ .addEqualityGroup(new Ip4Address("0.0.0.1", "00:00:00:00:00:00"), new Ip4Address(1L, 0L), new Ip4Address(1L, 0L), new Ip4Address(1L), new Ip4Address("0.0.0.1"))
+ .testEquals();
+ }
+
+ @Test
+ public void testIsSameAddressAs() {
+ Assert.assertTrue("1 and one should be considdered the same address", new Ip4Address(1L, 5L).isSameAddressAs("0.0.0.1"));
+ Assert.assertFalse("zero and 0L should be considdered the same address but a Long won't be accepted", new Ip4Address("0.0.0.0", "00:00:00:00:00:08").isSameAddressAs(0L));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d8ab5f3a/utils/test/com/cloud/utils/net/IpTest.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/net/IpTest.java b/utils/test/com/cloud/utils/net/IpTest.java
index d11b779..89608f1 100644
--- a/utils/test/com/cloud/utils/net/IpTest.java
+++ b/utils/test/com/cloud/utils/net/IpTest.java
@@ -21,8 +21,11 @@ package com.cloud.utils.net;
import static org.junit.Assert.assertEquals;
+import org.junit.Assert;
import org.junit.Test;
+import com.google.common.testing.EqualsTester;
+
public class IpTest {
@Test
@@ -43,4 +46,18 @@ public class IpTest {
assertEquals("Minimal address not created", "0.0.0.0", min.addr());
}
+ @Test
+ public void testEquals() {
+ new EqualsTester()
+ .addEqualityGroup(new Ip("0.0.0.1"), new Ip(1L))
+ .addEqualityGroup(new Ip("0.0.0.0"), new Ip(0L))
+ .testEquals();
+ }
+
+ @Test
+ public void testIsSameAddressAs() {
+ Assert.assertTrue("1 and one should be considdered the same address", new Ip(1L).isSameAddressAs("0.0.0.1"));
+ Assert.assertTrue("zero and 0L should be considdered the same address", new Ip("0.0.0.0").isSameAddressAs(0L));
+ }
+
}
[2/3] git commit: updated refs/heads/master to 4ad178e
Posted by da...@apache.org.
findbugs equals(obj) implementations go against the contract these are removed from the call into separate calls
Signed-off-by: Daan Hoogland <da...@onecht.net>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/34629446
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/34629446
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/34629446
Branch: refs/heads/master
Commit: 34629446b6db162f6b358c2bb042b7c3844003fd
Parents: 4bba499
Author: Daan Hoogland <da...@onecht.net>
Authored: Fri Jun 26 16:06:17 2015 +0200
Committer: Daan Hoogland <da...@onecht.net>
Committed: Tue Jul 7 13:48:19 2015 +0200
----------------------------------------------------------------------
.../org/apache/cloudstack/storage/BaseType.java | 19 ++++++++++++-------
.../cloudstack/framework/config/ConfigKey.java | 7 +++++++
utils/src/com/cloud/utils/net/Ip.java | 7 +++++++
utils/src/com/cloud/utils/net/Ip4Address.java | 14 +++++++++++---
4 files changed, 37 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/34629446/engine/storage/src/org/apache/cloudstack/storage/BaseType.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/BaseType.java b/engine/storage/src/org/apache/cloudstack/storage/BaseType.java
index d92dd8d..6d27772 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/BaseType.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/BaseType.java
@@ -23,18 +23,23 @@ public abstract class BaseType {
public boolean equals(Object that) {
if (this == that) {
return true;
- }
- if (that instanceof String) {
- if (this.toString().equalsIgnoreCase((String)that)) {
- return true;
- }
} else if (that instanceof BaseType) {
BaseType th = (BaseType)that;
if (this.toString().equalsIgnoreCase(th.toString())) {
return true;
}
- } else {
- return false;
+ }
+ return false;
+ }
+
+ public boolean isSameTypeAs(Object that) {
+ if (this.equals(that)){
+ return true;
+ }
+ if (that instanceof String) {
+ if (this.toString().equalsIgnoreCase((String)that)) {
+ return true;
+ }
}
return false;
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/34629446/framework/config/src/org/apache/cloudstack/framework/config/ConfigKey.java
----------------------------------------------------------------------
diff --git a/framework/config/src/org/apache/cloudstack/framework/config/ConfigKey.java b/framework/config/src/org/apache/cloudstack/framework/config/ConfigKey.java
index d39bb5d..09e143e 100644
--- a/framework/config/src/org/apache/cloudstack/framework/config/ConfigKey.java
+++ b/framework/config/src/org/apache/cloudstack/framework/config/ConfigKey.java
@@ -122,6 +122,13 @@ public class ConfigKey<T> {
if (obj instanceof ConfigKey) {
ConfigKey<?> that = (ConfigKey<?>)obj;
return this._name.equals(that._name);
+ }
+ return false;
+ }
+
+ public boolean isSameKeyAs(Object obj) {
+ if(this.equals(obj)) {
+ return true;
} else if (obj instanceof String) {
String key = (String)obj;
return key.equals(_name);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/34629446/utils/src/com/cloud/utils/net/Ip.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/net/Ip.java b/utils/src/com/cloud/utils/net/Ip.java
index e479e21..09312bc 100644
--- a/utils/src/com/cloud/utils/net/Ip.java
+++ b/utils/src/com/cloud/utils/net/Ip.java
@@ -75,6 +75,13 @@ public class Ip implements Serializable, Comparable<Ip> {
public boolean equals(Object obj) {
if (obj instanceof Ip) {
return ip == ((Ip)obj).ip;
+ }
+ return false;
+ }
+
+ public boolean isSameAddressAs(Object obj) {
+ if (this.equals(obj)) {
+ return true;
} else if (obj instanceof String) {
return ip == NetUtils.ip2Long((String)obj);
} else if (obj instanceof Long) {
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/34629446/utils/src/com/cloud/utils/net/Ip4Address.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/net/Ip4Address.java b/utils/src/com/cloud/utils/net/Ip4Address.java
index 67fe6da..9712a1f 100644
--- a/utils/src/com/cloud/utils/net/Ip4Address.java
+++ b/utils/src/com/cloud/utils/net/Ip4Address.java
@@ -55,15 +55,23 @@ public class Ip4Address {
@Override
public boolean equals(Object that) {
- if (that instanceof String) { // Assume that is an ip4 address in String form
- return _addr.equals(that);
- } else if (that instanceof Ip4Address) {
+
+ if (that instanceof Ip4Address) {
Ip4Address ip4 = (Ip4Address)that;
return this._addr.equals(ip4._addr) && (this._mac == ip4._mac || this._mac.equals(ip4._mac));
} else {
return false;
}
}
+
+ public boolean isSameAddressAs(Object other) {
+ if (other instanceof String) { // Assume that is an ip4 address in String form
+ return _addr.equals(other);
+ } else {
+ return this.equals(other);
+ }
+ }
+
@Override
public int hashCode(){
return (int)(_mac.hashCode()*_addr.hashCode());
[3/3] git commit: updated refs/heads/master to 4ad178e
Posted by da...@apache.org.
rats: licenses added
Signed-off-by: Daan Hoogland <da...@onecht.net>
This closes #535
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4ad178e4
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4ad178e4
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4ad178e4
Branch: refs/heads/master
Commit: 4ad178e4b17c9c0b61a0135d92557b623375f253
Parents: d8ab5f3
Author: Daan Hoogland <da...@gmail.com>
Authored: Mon Jul 6 17:10:41 2015 +0200
Committer: Daan Hoogland <da...@onecht.net>
Committed: Tue Jul 7 13:48:20 2015 +0200
----------------------------------------------------------------------
.../org/apache/cloudstack/storage/BaseTypeTest.java | 16 ++++++++++++++++
.../cloudstack/framework/config/ConfigKeyTest.java | 16 ++++++++++++++++
utils/test/com/cloud/utils/net/Ip4AddressTest.java | 16 ++++++++++++++++
3 files changed, 48 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4ad178e4/engine/storage/test/org/apache/cloudstack/storage/BaseTypeTest.java
----------------------------------------------------------------------
diff --git a/engine/storage/test/org/apache/cloudstack/storage/BaseTypeTest.java b/engine/storage/test/org/apache/cloudstack/storage/BaseTypeTest.java
index 5cce015..48759da 100644
--- a/engine/storage/test/org/apache/cloudstack/storage/BaseTypeTest.java
+++ b/engine/storage/test/org/apache/cloudstack/storage/BaseTypeTest.java
@@ -1,3 +1,19 @@
+// 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.cloudstack.storage;
import org.junit.Assert;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4ad178e4/framework/config/test/org/apache/cloudstack/framework/config/ConfigKeyTest.java
----------------------------------------------------------------------
diff --git a/framework/config/test/org/apache/cloudstack/framework/config/ConfigKeyTest.java b/framework/config/test/org/apache/cloudstack/framework/config/ConfigKeyTest.java
index b02ac1f..01a3509 100644
--- a/framework/config/test/org/apache/cloudstack/framework/config/ConfigKeyTest.java
+++ b/framework/config/test/org/apache/cloudstack/framework/config/ConfigKeyTest.java
@@ -1,3 +1,19 @@
+// 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.cloudstack.framework.config;
import org.junit.Assert;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4ad178e4/utils/test/com/cloud/utils/net/Ip4AddressTest.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/net/Ip4AddressTest.java b/utils/test/com/cloud/utils/net/Ip4AddressTest.java
index d4e24d3..79ff238 100644
--- a/utils/test/com/cloud/utils/net/Ip4AddressTest.java
+++ b/utils/test/com/cloud/utils/net/Ip4AddressTest.java
@@ -1,3 +1,19 @@
+// 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 com.cloud.utils.net;
import org.junit.Assert;