1 20 package org.apache.cactus.integration.ant.deployment.webapp; 21 22 23 import javax.xml.parsers.DocumentBuilderFactory ; 24 import javax.xml.parsers.ParserConfigurationException ; 25 26 import junit.framework.TestCase; 27 28 import org.w3c.dom.DOMImplementation ; 29 import org.w3c.dom.DocumentType ; 30 31 36 public final class TestWebXmlVersion extends TestCase 37 { 38 41 private DOMImplementation domImpl; 42 43 46 public void setUp() throws ParserConfigurationException 47 { 48 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 49 factory.setValidating(false); 50 factory.setNamespaceAware(false); 51 52 this.domImpl = factory.newDocumentBuilder().getDOMImplementation(); 53 } 54 55 60 public void testCompare22To22() throws Exception 61 { 62 assertTrue(WebXmlVersion.V2_2.compareTo(WebXmlVersion.V2_2) == 0); 63 } 64 65 71 public void testCompare22To23() throws Exception 72 { 73 assertTrue(WebXmlVersion.V2_2.compareTo(WebXmlVersion.V2_3) < 0); 74 } 75 76 81 public void testCompare23To23() throws Exception 82 { 83 assertTrue(WebXmlVersion.V2_3.compareTo(WebXmlVersion.V2_3) == 0); 84 } 85 86 92 public void testCompare23To22() throws Exception 93 { 94 assertTrue(WebXmlVersion.V2_3.compareTo(WebXmlVersion.V2_2) > 0); 95 } 96 97 103 public void testValueOfNull() throws Exception 104 { 105 try 106 { 107 WebXmlVersion.valueOf((DocumentType ) null); 108 fail("Expected NullPointerException"); 109 } 110 catch (NullPointerException expected) 111 { 112 } 114 } 115 116 122 public void testValueOfUnknownDocType() throws Exception 123 { 124 DocumentType docType = domImpl.createDocumentType("web-app", 125 "foo", "bar"); 126 assertNull(WebXmlVersion.valueOf(docType)); 127 } 128 129 135 public void testValueOfDocType22() throws Exception 136 { 137 DocumentType docType = domImpl.createDocumentType("web-app", 138 WebXmlVersion.V2_2.getPublicId(), WebXmlVersion.V2_2.getSystemId()); 139 assertEquals(WebXmlVersion.V2_2, WebXmlVersion.valueOf(docType)); 140 } 141 142 148 public void testValueOfDocType23() throws Exception 149 { 150 DocumentType docType = domImpl.createDocumentType("web-app", 151 WebXmlVersion.V2_3.getPublicId(), WebXmlVersion.V2_3.getSystemId()); 152 assertEquals(WebXmlVersion.V2_3, WebXmlVersion.valueOf(docType)); 153 } 154 155 } 156 | Popular Tags |