You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by sc...@apache.org on 2006/06/21 18:25:28 UTC

svn commit: r416024 - in /webservices/commons/trunk/modules/axiom: src/org/apache/axiom/om/impl/llom/OMNamespaceImpl.java test/org/apache/axiom/om/impl/llom/OMNamespaceImplTest.java

Author: scheu
Date: Wed Jun 21 09:25:28 2006
New Revision: 416024

URL: http://svn.apache.org/viewvc?rev=416024&view=rev
Log:
Issue WSCOMMONS-44

Four tests plus the OMNamespace equals() code fix are contributed.
 - a simple test for namespace access
 - a simple test for prefix access.
 - a test the pushes the corners on the equals implementation
 - a test that makes sure that OMNamespace remains an immutable object.

Added:
    webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/impl/llom/OMNamespaceImplTest.java
Modified:
    webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMNamespaceImpl.java

Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMNamespaceImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMNamespaceImpl.java?rev=416024&r1=416023&r2=416024&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMNamespaceImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMNamespaceImpl.java Wed Jun 21 09:25:28 2006
@@ -51,7 +51,9 @@
     public boolean equals(String uri, String prefix) {
         return (((prefix == null) && (this.prefix == null)) ||
                 ((prefix != null) && prefix.equals(this.prefix))) &&
-                uri.equals(uri);
+               ((uri == null) && (this.uri == null) ||
+                (uri != null) && uri.equals(this.uri));
+
     }
 
     /**

Added: webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/impl/llom/OMNamespaceImplTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/impl/llom/OMNamespaceImplTest.java?rev=416024&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/impl/llom/OMNamespaceImplTest.java (added)
+++ webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/impl/llom/OMNamespaceImplTest.java Wed Jun 21 09:25:28 2006
@@ -0,0 +1,162 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed 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.axiom.om.impl.llom;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.textui.TestRunner;            
+            
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.axiom.om.impl.llom.OMNamespaceImpl;
+
+/**
+ * This class will test the methods and fields of
+ * the OMNamespaceImpl class. 
+ */
+public class OMNamespaceImplTest extends TestCase {
+
+    /**
+     * The main method.
+     *
+     * @param args The command line arguments
+     */
+    public static void main(String[] args) {
+        TestRunner.run(suite());
+    }
+
+    /**
+     * A one arg constructor to allow specifying
+     * a single test method to run.
+     *
+     * @param name The name of the test to run
+     */
+    public OMNamespaceImplTest(String name) {
+        super(name);
+    }
+
+    /**
+     * This method returns a test suite of tests to
+     * run.
+     *
+     * @return A test suite to be run
+     */
+    public static Test suite() {
+        return new TestSuite(OMNamespaceImplTest.class);
+    }
+
+    /**
+     * This method will test the getPrefix method.
+     */
+    public void testGetPrefix() {
+        OMNamespaceImpl omNsImpl =
+            new OMNamespaceImpl("http://www.w3.org/XML/1998/namespace",
+                                "xml");
+        assertEquals("http://www.w3.org/XML/1998/namespace",
+                     omNsImpl.getName());
+        omNsImpl = new OMNamespaceImpl(null, null);
+        assertNull(omNsImpl.getName());
+    }
+
+    /**
+     * This method will test the getName method.
+     */
+    public void testGetName() {
+        OMNamespaceImpl omNsImpl =
+            new OMNamespaceImpl("http://www.w3.org/XML/1998/namespace",
+                                "xml");
+        assertEquals("xml", omNsImpl.getPrefix());
+        omNsImpl = new OMNamespaceImpl(null, null);
+        assertNull(omNsImpl.getPrefix());
+    }
+
+    /**
+     * This method wil test the equals method.
+     */
+    public void testEquals() {
+        OMNamespaceImpl omNsImpl =
+            new OMNamespaceImpl("http://www.w3.org/XML/1998/namespace",
+                                null);
+        assertTrue(omNsImpl.equals("http://www.w3.org/XML/1998/namespace",
+                                   null));
+
+        omNsImpl =
+            new OMNamespaceImpl("http://www.w3.org/XML/1998/namespace",
+                                "xml");
+        assertTrue(omNsImpl.equals("http://www.w3.org/XML/1998/namespace",
+                                   "xml"));
+        assertTrue(!omNsImpl.equals("http://www.w3.org/XML/1998/namespace",
+                                    "xml2"));
+        assertTrue(!omNsImpl.equals("http://www.w3.org/XML/1998/namespace",
+                                    null));
+        assertTrue(!omNsImpl.equals("http://www.w3.org/XML/2001/namespace",
+                                    "xml"));
+        assertTrue(!omNsImpl.equals(null,
+                                    "xml"));
+
+        omNsImpl = new OMNamespaceImpl(null, null);
+        assertTrue(!omNsImpl.equals("http://www.w3.org/XML/1998/namespace",
+                                   "xml"));
+        assertTrue(!omNsImpl.equals("http://www.w3.org/XML/1998/namespace",
+                                    null));
+        assertTrue(!omNsImpl.equals(null,
+                                    "xml"));
+        assertTrue(omNsImpl.equals(null, null));
+        
+    }
+
+    /**
+     * This method will insure that the OMNamespaceImpl
+     * class remains immutable.
+     *
+     * @throws Exception Any kind of exception
+     */
+    public void testImmutable() throws Exception {
+
+        Field[] clsField = OMNamespaceImpl.class.getDeclaredFields();
+        for (int i = 0; i < clsField.length; i++) {
+            String fieldData = clsField[i].toString();
+            if ((fieldData.indexOf("prefix") != -1) 
+                || (fieldData.indexOf("uri") != -1)) {
+                assertTrue("The field should have been private, "
+                           + " but instead contained: " + fieldData + ".",
+                           fieldData.indexOf("private") != -1);
+            }
+        }
+
+        String[] method = new String[] {"setPrefix", "setUri", "setName"};
+        for (int i = 0; i < method.length; i++) {
+            try {
+                Method m =
+                    OMNamespaceImpl.class.getMethod(method[i],
+                                                  new Class[] {String.class});
+                fail("A NoSuchMethodException should have been thrown"
+                     + " when trying to get method \"" + method[i]
+                     + "\".");
+            } catch (NoSuchMethodException e) {
+                // These methods should not exist, so this is
+                // expected.
+            }
+        }
+
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org