View Javadoc

1   package org.e2etrace.config;
2   
3   /*
4    * Copyright 2006 Gunther Popp
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.io.IOException;
20  
21  import org.e2etrace.config.PropertiesTraceConfig;
22  import org.e2etrace.trace.SimpleTraceStepId;
23  
24  
25  import junit.framework.TestCase;
26  
27  /**
28   * JUnit testcase for {@link org.e2etrace.config.PropertiesTraceConfig}
29   *
30   * @author Gunther Popp
31   *
32   */
33  public class PropertiesTraceConfigTest extends TestCase {
34  
35    private static String TESTDATA_FILE = "e2etrace/config/PropertiesTraceConfigTest.properties";
36  
37    public static void main(String[] args) {
38      junit.textui.TestRunner.run(PropertiesTraceConfigTest.class);
39    }
40  
41    /**
42     * Test case for <code>loadConfigFile</code>
43     *
44     * @throws IOException Unexpected error while loading the test data
45     */
46    public void testLoadConfigFile() throws IOException {
47      PropertiesTraceConfig tc = new PropertiesTraceConfig();
48  
49      // OK - Test
50      tc.loadConfigFile(TESTDATA_FILE);
51  
52      // NOK-Test
53      boolean ok = false;
54      try {
55        tc.loadConfigFile("NotExistent");
56      } catch (IOException ioe) {
57        ok = true;
58      }
59  
60      if (!ok) {
61        fail("Expected an IOException!");
62      }
63  
64    }
65  
66    /**
67     * Test case for <code>isTraceEnabled</code> and
68     * <code>isTraceEnabledForId</code>
69     *
70     * @throws IOException Unexpected error while loading the test data
71     */
72    public void testIsTraceEnabledEtc() throws IOException {
73      PropertiesTraceConfig tc = new PropertiesTraceConfig();
74  
75      tc.loadConfigFile(TESTDATA_FILE);
76  
77      assertTrue("enabletrace should be true", tc.isTraceEnabled());
78      assertTrue("Trace step id1 should be true", tc
79          .isTraceEnabledForId(new SimpleTraceStepId("id1")));
80      assertFalse("Trace step id2 should be false", tc
81          .isTraceEnabledForId(new SimpleTraceStepId("id2")));
82      assertTrue("Undefined Trace step xxx should be true", tc
83          .isTraceEnabledForId(new SimpleTraceStepId("xxx")));
84    }
85  
86  }