cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject svn commit: r1127487 - in /cxf/trunk/rt/core/src: main/java/org/apache/cxf/endpoint/EndpointImpl.java test/java/org/apache/cxf/endpoint/EndpointImplTest.java
Date Wed, 25 May 2011 12:03:48 GMT
Author: ay
Date: Wed May 25 12:03:47 2011
New Revision: 1127487

URL: http://svn.apache.org/viewvc?rev=1127487&view=rev
Log:
[CXF-3548] EndpointImpl's hashCode changed; a unit test added

Added:
    cxf/trunk/rt/core/src/test/java/org/apache/cxf/endpoint/EndpointImplTest.java   (with
props)
Modified:
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/EndpointImpl.java

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/EndpointImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/EndpointImpl.java?rev=1127487&r1=1127486&r2=1127487&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/EndpointImpl.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/EndpointImpl.java Wed May 25 12:03:47
2011
@@ -178,4 +178,13 @@ public class EndpointImpl extends Abstra
     public void initializeActiveFeatures(List<AbstractFeature> features) {
         activeFeatures = features;
     }
+
+    /**
+     * Returns the hashCode bsed on the EndpointInfo so that this object
+     * can be used as a map key.
+     */
+    @Override
+    public int hashCode() {
+        return endpointInfo.hashCode();
+    }
 }

Added: cxf/trunk/rt/core/src/test/java/org/apache/cxf/endpoint/EndpointImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/test/java/org/apache/cxf/endpoint/EndpointImplTest.java?rev=1127487&view=auto
==============================================================================
--- cxf/trunk/rt/core/src/test/java/org/apache/cxf/endpoint/EndpointImplTest.java (added)
+++ cxf/trunk/rt/core/src/test/java/org/apache/cxf/endpoint/EndpointImplTest.java Wed May
25 12:03:47 2011
@@ -0,0 +1,66 @@
+/**
+ * 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.cxf.endpoint;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.bus.CXFBusImpl;
+import org.apache.cxf.service.Service;
+import org.apache.cxf.service.ServiceImpl;
+import org.apache.cxf.service.model.EndpointInfo;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * 
+ */
+public class EndpointImplTest extends Assert {
+    
+    @Test
+    public void testEqualsAndHashCode() throws Exception {
+        Bus bus = new CXFBusImpl();
+        Service svc = new ServiceImpl();
+        EndpointInfo ei = new EndpointInfo();
+        ei.setAddress("http://nowhere.com/bar/foo");
+        EndpointInfo ei2 = new EndpointInfo();
+        ei2.setAddress("http://nowhere.com/foo/bar");
+        
+        Endpoint ep = new EndpointImpl(bus, svc, ei);
+        Endpoint ep1 = new EndpointImpl(bus, svc, ei);
+        Endpoint ep2 = new EndpointImpl(bus, svc, ei2);
+        
+        int hashcode = ep.hashCode();
+        int hashcode1 = ep1.hashCode();
+        int hashcode2 = ep2.hashCode();
+        
+        assertTrue("hashcodes must be equal", hashcode == hashcode1);
+        assertTrue("hashcodes must not be equal", hashcode != hashcode2);
+
+        assertTrue("reflexivity violated", ep.equals(ep));
+        assertFalse("two objects must not be equal", ep.equals(ep1));
+        assertFalse("two objects must not be equal", ep.equals(ep2));
+        
+        ep.put("custom", Boolean.TRUE);
+        
+        assertTrue("hashcode must remain equal", hashcode == ep.hashCode());
+    }
+    
+    //TODO add other tests
+}

Propchange: cxf/trunk/rt/core/src/test/java/org/apache/cxf/endpoint/EndpointImplTest.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message