View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.configuration;
19  
20  import static org.junit.Assert.assertNotNull;
21  import static org.junit.Assert.assertTrue;
22  
23  import org.apache.commons.configuration.resolver.CatalogResolver;
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  import org.junit.After;
27  import org.junit.Before;
28  import org.junit.Test;
29  
30  /**
31   * Test class for CatalogResolver.
32   *
33   * @version $Id: TestCatalogResolver.java 1223006 2011-12-24 19:41:41Z oheger $
34   */
35  public class TestCatalogResolver
36  {
37      private static final String CATALOG_FILES = "catalog.xml";
38      private static final String PUBLIC_FILE = "testResolver.xml";
39      private static final String REWRITE_SYSTEM_FILE = "test.properties.xml";
40      private static final String REWRITE_SCHEMA_FILE = "sample.xml";
41  
42      private CatalogResolver resolver;
43      private XMLConfiguration config;
44  
45      @Before
46      public void setUp() throws Exception
47      {
48          resolver = new CatalogResolver();
49          resolver.setCatalogFiles(CATALOG_FILES);
50          // resolver.setDebug(true);
51          config = new XMLConfiguration();
52          config.setEntityResolver(resolver);
53      }
54  
55      @After
56      public void tearDown() throws Exception
57      {
58          resolver = null;
59          config = null;
60      }
61  
62      @Test
63      public void testPublic() throws Exception
64      {
65          config.setFileName(PUBLIC_FILE);
66          config.load();
67      }
68  
69      @Test
70      public void testRewriteSystem() throws Exception
71      {
72          config.setFileName(REWRITE_SYSTEM_FILE);
73          config.load();
74      }
75  
76      /**
77       * Tests that the schema can be resolved and that XMLConfiguration will
78       * validate the file using the schema.
79       * @throws Exception
80       */
81      @Test
82      public void testSchemaResolver() throws Exception
83      {
84          config.setFileName(REWRITE_SCHEMA_FILE);
85          config.setSchemaValidation(true);
86          config.load();
87      }
88  
89      @Test
90      public void testDebug() throws Exception
91      {
92          resolver.setDebug(true);
93          // There is no really good way to check this except to do something
94          // that causes debug output.
95      }
96  
97      @Test
98      public void testLogger() throws Exception
99      {
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 }