001 /* 002 * Copyright 2002 - 2010 JEuclid, http://jeuclid.sf.net 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 /* $Id: DOMNameSpaceTest.java,v 92b6a7c39d7f 2010/08/11 20:23:17 max $ */ 018 019 package net.sourceforge.jeuclid.test; 020 021 import net.sourceforge.jeuclid.DOMBuilder; 022 import net.sourceforge.jeuclid.MathMLParserSupport; 023 import net.sourceforge.jeuclid.elements.AbstractJEuclidElement; 024 025 import org.junit.Assert; 026 import org.junit.Test; 027 import org.w3c.dom.Document; 028 import org.w3c.dom.Node; 029 import org.w3c.dom.mathml.MathMLDocument; 030 031 /** 032 * Tests misc DOM Namespace functionality. 033 * 034 * @version $Revision: 92b6a7c39d7f $ 035 */ 036 public class DOMNameSpaceTest { 037 038 /** 039 * Tests if MathML Namespace is kept. 040 * 041 * @throws Exception 042 * if the test fails. 043 */ 044 @Test 045 public void testNameSpaceKeep() throws Exception { 046 final Document doc = MathMLParserSupport 047 .parseString("<math xmlns='http://www.w3.org/1998/Math/MathML'><mn>1</mn></math>"); 048 Assert.assertEquals(doc.getDocumentElement().getNamespaceURI(), 049 AbstractJEuclidElement.URI); 050 final MathMLDocument jdoc = DOMBuilder.getInstance() 051 .createJeuclidDom(doc); 052 Assert.assertEquals(jdoc.getDocumentElement().getNamespaceURI(), 053 AbstractJEuclidElement.URI); 054 } 055 056 /** 057 * Tests if MathML Namespace is added. 058 * 059 * @throws Exception 060 * if the test fails. 061 */ 062 @Test 063 public void testNameSpaceAdded() throws Exception { 064 final Document doc = MathMLParserSupport 065 .parseString("<math><mn>1</mn></math>"); 066 Assert.assertEquals(doc.getDocumentElement().getNamespaceURI(), null); 067 final MathMLDocument jdoc = DOMBuilder.getInstance() 068 .createJeuclidDom(doc); 069 Assert.assertEquals(jdoc.getDocumentElement().getNamespaceURI(), 070 AbstractJEuclidElement.URI); 071 } 072 073 /** 074 * Tests foreign namespaces. 075 * 076 * @throws Exception 077 * if the test fails. 078 */ 079 @Test 080 public void testForeignNameSpaces() throws Exception { 081 final Document doc = MathMLParserSupport 082 .parseString("<math><f:bla xmlns:f='http://www.atest.org/'>1</f:bla></math>"); 083 Assert.assertEquals(doc.getDocumentElement().getNamespaceURI(), null); 084 final MathMLDocument jdoc = DOMBuilder.getInstance() 085 .createJeuclidDom(doc); 086 Assert.assertEquals(jdoc.getDocumentElement().getNamespaceURI(), 087 AbstractJEuclidElement.URI); 088 final Node n = jdoc.getDocumentElement().getChildNodes().item(0); 089 Assert.assertEquals(n.getNamespaceURI(), "http://www.atest.org/"); 090 } 091 092 }