You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by dk...@apache.org on 2019/10/31 14:48:56 UTC
[ws-axiom] 19/25: Build test cases for XSQNameType that don't
depend on DOMHelper.
This is an automated email from the ASF dual-hosted git repository.
dkulp pushed a commit to branch datatypes
in repository https://gitbox.apache.org/repos/asf/ws-axiom.git
commit c05cc4ad3628402e77385836226bf8ce1b66bed8
Author: Andreas Veithen <ve...@apache.org>
AuthorDate: Sat Dec 5 00:46:34 2015 +0000
Build test cases for XSQNameType that don't depend on DOMHelper.
---
.../axiom/datatype/helper/dom/DOMHelperTest.java | 33 -----------
.../axiom/datatype/xsd/MapContextAccessor.java | 42 ++++++++++++++
.../apache/axiom/datatype/xsd/XSQNameTypeTest.java | 64 ++++++++++++++++++++++
3 files changed, 106 insertions(+), 33 deletions(-)
diff --git a/datatypes/src/test/java/org/apache/axiom/datatype/helper/dom/DOMHelperTest.java b/datatypes/src/test/java/org/apache/axiom/datatype/helper/dom/DOMHelperTest.java
index 61311e7..ac9455c 100644
--- a/datatypes/src/test/java/org/apache/axiom/datatype/helper/dom/DOMHelperTest.java
+++ b/datatypes/src/test/java/org/apache/axiom/datatype/helper/dom/DOMHelperTest.java
@@ -20,9 +20,6 @@ package org.apache.axiom.datatype.helper.dom;
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);
- }
}
diff --git a/datatypes/src/test/java/org/apache/axiom/datatype/xsd/MapContextAccessor.java b/datatypes/src/test/java/org/apache/axiom/datatype/xsd/MapContextAccessor.java
new file mode 100644
index 0000000..a8c55bc
--- /dev/null
+++ b/datatypes/src/test/java/org/apache/axiom/datatype/xsd/MapContextAccessor.java
@@ -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();
+ }
+}
diff --git a/datatypes/src/test/java/org/apache/axiom/datatype/xsd/XSQNameTypeTest.java b/datatypes/src/test/java/org/apache/axiom/datatype/xsd/XSQNameTypeTest.java
new file mode 100644
index 0000000..eb0ae7c
--- /dev/null
+++ b/datatypes/src/test/java/org/apache/axiom/datatype/xsd/XSQNameTypeTest.java
@@ -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);
+ }
+}