001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.commons.configuration; 019 020 import static org.junit.Assert.assertNotNull; 021 import static org.junit.Assert.assertTrue; 022 023 import org.apache.commons.configuration.resolver.CatalogResolver; 024 import org.apache.commons.logging.Log; 025 import org.apache.commons.logging.LogFactory; 026 import org.junit.After; 027 import org.junit.Before; 028 import org.junit.Test; 029 030 /** 031 * Test class for CatalogResolver. 032 * 033 * @version $Id: TestCatalogResolver.java 1223006 2011-12-24 19:41:41Z oheger $ 034 */ 035 public class TestCatalogResolver 036 { 037 private static final String CATALOG_FILES = "catalog.xml"; 038 private static final String PUBLIC_FILE = "testResolver.xml"; 039 private static final String REWRITE_SYSTEM_FILE = "test.properties.xml"; 040 private static final String REWRITE_SCHEMA_FILE = "sample.xml"; 041 042 private CatalogResolver resolver; 043 private XMLConfiguration config; 044 045 @Before 046 public void setUp() throws Exception 047 { 048 resolver = new CatalogResolver(); 049 resolver.setCatalogFiles(CATALOG_FILES); 050 // resolver.setDebug(true); 051 config = new XMLConfiguration(); 052 config.setEntityResolver(resolver); 053 } 054 055 @After 056 public void tearDown() throws Exception 057 { 058 resolver = null; 059 config = null; 060 } 061 062 @Test 063 public void testPublic() throws Exception 064 { 065 config.setFileName(PUBLIC_FILE); 066 config.load(); 067 } 068 069 @Test 070 public void testRewriteSystem() throws Exception 071 { 072 config.setFileName(REWRITE_SYSTEM_FILE); 073 config.load(); 074 } 075 076 /** 077 * Tests that the schema can be resolved and that XMLConfiguration will 078 * validate the file using the schema. 079 * @throws Exception 080 */ 081 @Test 082 public void testSchemaResolver() throws Exception 083 { 084 config.setFileName(REWRITE_SCHEMA_FILE); 085 config.setSchemaValidation(true); 086 config.load(); 087 } 088 089 @Test 090 public void testDebug() throws Exception 091 { 092 resolver.setDebug(true); 093 // There is no really good way to check this except to do something 094 // that causes debug output. 095 } 096 097 @Test 098 public void testLogger() throws Exception 099 { 100 Log log = LogFactory.getLog(this.getClass()); 101 resolver.setLogger(log); 102 assertNotNull("No Logger returned", resolver.getLogger()); 103 assertTrue("Incorrect Logger", log == resolver.getLogger()); 104 } 105 106 }