ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1718056 - in /webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype: helper/dom/DOMHelperTest.java xsd/MapContextAccessor.java xsd/XSQNameTypeTest.java
Date Sat, 05 Dec 2015 00:46:34 GMT
Author: veithen
Date: Sat Dec  5 00:46:34 2015
New Revision: 1718056

URL: http://svn.apache.org/viewvc?rev=1718056&view=rev
Log:
Build test cases for XSQNameType that don't depend on DOMHelper.

Added:
    webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/xsd/MapContextAccessor.java
  (with props)
    webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/xsd/XSQNameTypeTest.java
  (with props)
Modified:
    webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/helper/dom/DOMHelperTest.java

Modified: webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/helper/dom/DOMHelperTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/helper/dom/DOMHelperTest.java?rev=1718056&r1=1718055&r2=1718056&view=diff
==============================================================================
--- webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/helper/dom/DOMHelperTest.java
(original)
+++ webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/helper/dom/DOMHelperTest.java
Sat Dec  5 00:46:34 2015
@@ -20,9 +20,6 @@ package org.apache.axiom.datatype.helper
 
 import static com.google.common.truth.Truth.assertThat;
 
-import java.text.ParseException;
-
-import javax.xml.XMLConstants;
 import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilderFactory;
 
@@ -47,14 +44,6 @@ public class DOMHelperTest {
         assertThat(qname.getPrefix()).isEqualTo("p");
     }
     
-    @Test(expected=ParseException.class)
-    public void testGetQNameFromElementUnboundPrefix() throws Exception {
-        Document document = newDocument();
-        Element element = document.createElementNS(null, "test");
-        element.setTextContent("ns:test");
-        DOMHelper.getValue(element, XSQNameType.INSTANCE);
-    }
-    
     @Test
     public void testGetQNameFromElementNoDefaultNamespace() throws Exception {
         Document document = newDocument();
@@ -65,26 +54,4 @@ public class DOMHelperTest {
         assertThat(qname.getLocalPart()).isEqualTo("value");
         assertThat(qname.getPrefix()).isEmpty();
     }
-    
-    @Test
-    public void testGetQNameFromElementXmlPrefix() throws Exception {
-        Document document = newDocument();
-        Element element = document.createElementNS(null, "test");
-        element.setTextContent("xml:value");
-        QName qname = DOMHelper.getValue(element, XSQNameType.INSTANCE);
-        assertThat(qname.getNamespaceURI()).isEqualTo(XMLConstants.XML_NS_URI);
-        assertThat(qname.getLocalPart()).isEqualTo("value");
-        assertThat(qname.getPrefix()).isEqualTo(XMLConstants.XML_NS_PREFIX);
-    }
-    
-    @Test
-    public void testGetQNameFromElementXmlnsPrefix() throws Exception {
-        Document document = newDocument();
-        Element element = document.createElementNS(null, "test");
-        element.setTextContent("xmlns:value");
-        QName qname = DOMHelper.getValue(element, XSQNameType.INSTANCE);
-        assertThat(qname.getNamespaceURI()).isEqualTo(XMLConstants.XMLNS_ATTRIBUTE_NS_URI);
-        assertThat(qname.getLocalPart()).isEqualTo("value");
-        assertThat(qname.getPrefix()).isEqualTo(XMLConstants.XMLNS_ATTRIBUTE);
-    }
 }

Added: webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/xsd/MapContextAccessor.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/xsd/MapContextAccessor.java?rev=1718056&view=auto
==============================================================================
--- webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/xsd/MapContextAccessor.java
(added)
+++ webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/xsd/MapContextAccessor.java
Sat Dec  5 00:46:34 2015
@@ -0,0 +1,42 @@
+/*
+ * 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.axiom.datatype.xsd;
+
+import java.util.Map;
+
+import org.apache.axiom.datatype.ContextAccessor;
+
+public final class MapContextAccessor implements ContextAccessor<Map<String,String>,Void>
{
+    public static final MapContextAccessor INSTANCE = new MapContextAccessor();
+    
+    private MapContextAccessor() {}
+
+    public String lookupNamespaceURI(Map<String,String> context, Void options, String
prefix) {
+        String namespaceURI = context.get(prefix);
+        if (namespaceURI == null && prefix.isEmpty()) {
+            namespaceURI = "";
+        }
+        return namespaceURI;
+    }
+
+    public String lookupPrefix(Map<String,String> context, Void options, String namespaceURI)
{
+        // TODO
+        throw new UnsupportedOperationException();
+    }
+}

Propchange: webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/xsd/MapContextAccessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/xsd/XSQNameTypeTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/xsd/XSQNameTypeTest.java?rev=1718056&view=auto
==============================================================================
--- webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/xsd/XSQNameTypeTest.java
(added)
+++ webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/xsd/XSQNameTypeTest.java
Sat Dec  5 00:46:34 2015
@@ -0,0 +1,64 @@
+/*
+ * 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.axiom.datatype.xsd;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import java.text.ParseException;
+import java.util.Collections;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.QName;
+
+import org.junit.Test;
+
+public class XSQNameTypeTest {
+    @Test
+    public void testBoundPrefix() throws ParseException {
+        QName qname = XSQNameType.INSTANCE.parse("p:test", MapContextAccessor.INSTANCE,
+                Collections.singletonMap("p", "urn:test"), null);
+        assertThat(qname.getNamespaceURI()).isEqualTo("urn:test");
+        assertThat(qname.getLocalPart()).isEqualTo("test");
+        assertThat(qname.getPrefix()).isEqualTo("p");
+    }
+    
+    @Test(expected=ParseException.class)
+    public void testUnboundPrefix() throws ParseException {
+        XSQNameType.INSTANCE.parse("ns:test", MapContextAccessor.INSTANCE,
+                Collections.<String,String>emptyMap(), null);
+    }
+    
+    @Test
+    public void testXmlPrefix() throws ParseException {
+        QName qname = XSQNameType.INSTANCE.parse("xml:value", MapContextAccessor.INSTANCE,
+                Collections.<String,String>emptyMap(), null);
+        assertThat(qname.getNamespaceURI()).isEqualTo(XMLConstants.XML_NS_URI);
+        assertThat(qname.getLocalPart()).isEqualTo("value");
+        assertThat(qname.getPrefix()).isEqualTo(XMLConstants.XML_NS_PREFIX);
+    }
+    
+    @Test
+    public void testXmlnsPrefix() throws ParseException {
+        QName qname = XSQNameType.INSTANCE.parse("xmlns:value", MapContextAccessor.INSTANCE,
+                Collections.<String,String>emptyMap(), null);
+        assertThat(qname.getNamespaceURI()).isEqualTo(XMLConstants.XMLNS_ATTRIBUTE_NS_URI);
+        assertThat(qname.getLocalPart()).isEqualTo("value");
+        assertThat(qname.getPrefix()).isEqualTo(XMLConstants.XMLNS_ATTRIBUTE);
+    }
+}

Propchange: webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/xsd/XSQNameTypeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message