001/* $Id: URLTestCase.java 1127949 2011-05-26 14:57:52Z simonetripodi $ 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one or more 004 * contributor license agreements. See the NOTICE file distributed with 005 * this work for additional information regarding copyright ownership. 006 * The ASF licenses this file to You under the Apache License, Version 2.0 007 * (the "License"); you may not use this file except in compliance with 008 * the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019package org.apache.commons.digester3; 020 021import static org.junit.Assert.*; 022 023import java.net.URL; 024 025import org.apache.commons.digester3.Digester; 026import org.junit.After; 027import org.junit.Before; 028import org.junit.Test; 029 030/** 031 * <p> 032 * Unit tests that exercise the new (in 1.8) methods for passing in <code>URL</code> arguments instead of strings. 033 * </p> 034 */ 035public class URLTestCase 036{ 037 038 // ----------------------------------------------------- Overall Test Methods 039 040 /** 041 * Set up instance variables required by this test case. 042 */ 043 @Before 044 public void setUp() 045 { 046 047 digester = new Digester(); 048 049 } 050 051 /** 052 * Tear down instance variables required by this test case. 053 */ 054 @After 055 public void tearDown() 056 { 057 058 digester = null; 059 060 } 061 062 // ------------------------------------------------------ Manifest Constants 063 064 /** 065 * <p> 066 * Public identifier of the Digester Rules DTD. 067 * </p> 068 */ 069 private static final String DIGESTER_RULES_PUBLIC_ID = "-//Apache Commons //DTD digester-rules XML V1.0//EN"; 070 071 /** 072 * <p> 073 * System identifier of the Digester Rules DTD. 074 * </p> 075 */ 076 private static final String DIGESTER_RULES_SYSTEM_ID = "/org/apache/commons/digester3/xmlrules/digester-rules.dtd"; 077 078 /** 079 * <p> 080 * System identifier for the Digester Rules file that we will parse. 081 * </p> 082 */ 083 private static final String TEST_INPUT_SYSTEM_ID = 084 "/org/apache/commons/digester3/xmlrules/test-call-param-rules.xml"; 085 086 // ------------------------------------------------------ Instance Variables 087 088 /** 089 * <p> 090 * The <code>Digester</code> instance under test. 091 * </p> 092 */ 093 private Digester digester = null; 094 095 // ------------------------------------------------------------ Test Methods 096 097 // Test a pristine instance 098 @Test 099 public void testPristine() 100 { 101 102 assertNotNull( digester ); 103 104 } 105 106 // Test parsing a resource, using a registered DTD, both passed with URLs 107 @Test 108 public void testResource() 109 throws Exception 110 { 111 112 // Register the Digester Rules DTD 113 URL dtd = URLTestCase.class.getResource( DIGESTER_RULES_SYSTEM_ID ); 114 assertNotNull( dtd ); 115 digester.register( DIGESTER_RULES_PUBLIC_ID, dtd ); 116 117 // Parse one of the existing test resources twice with 118 // the same Digester instance 119 URL xml = URLTestCase.class.getResource( TEST_INPUT_SYSTEM_ID ); 120 assertNotNull( xml ); 121 digester.parse( xml ); 122 digester.parse( xml ); 123 124 } 125 126}