1 /*
2 * File: PropertiesConfigMixinTest.java
3 * Date: Nov 12, 2003
4 */
5 package com.rhi.architecture.batch;
6
7 import com.rhi.architecture.resource.InitializationException;
8
9 import java.util.*;
10
11 import junit.framework.*;
12 import junit.textui.*;
13
14 /***
15 * PropertiesConfigMixinTest
16 *
17 * @author <a href="mailto:pete_mckinstry@yahoo.com">Pete McKinstry</a>
18 * @copyright 2003, All rights reserved.
19 */
20 public class PropertiesConfigMixinTest extends TestCase {
21
22 /***
23 * Constructor for PropertiesConfigMixinTest.
24 * @param arg0
25 */
26 public PropertiesConfigMixinTest(String arg0) {
27 super(arg0);
28 }
29
30 /*
31 * @see TestCase#setUp()
32 */
33 protected void setUp() throws Exception {
34 super.setUp();
35 System.out.println(super.getName() + " - start");
36 }
37
38 /*
39 * @see TestCase#tearDown()
40 */
41 protected void tearDown() throws Exception {
42 super.tearDown();
43 System.out.println(super.getName() + " - stop");
44 }
45
46 /***
47 * valid test. expect mixin to load properties.
48 */
49 public void testLoadConfiguration() {
50 Properties p = new Properties();
51 // no prog name given.
52 p.setProperty(ApplicationConfig.PROG_NAME, "testapp");
53
54 Properties expectedResult = new Properties();
55 expectedResult.setProperty(ApplicationConfig.PROG_NAME, "testapp");
56 expectedResult.setProperty("name", "value");
57
58 ConfigMixin mixin = new PropertiesConfigMixin();
59 try {
60 mixin.loadConfiguration(p);
61 if (!p.equals(expectedResult)) {
62 p.list(System.err);
63 fail("loaded properties not as expected");
64 }
65 }
66 catch (InitializationException e) {
67 System.err.println("InitializationException: " +e);
68 e.printStackTrace(System.err);
69 fail("prog name given. no exception expected.");
70 }
71
72 }
73
74 /***
75 * if no program name is provided, this config mixin should fail.
76 */
77 public void testGetPropetyFileName() {
78 ConfigMixin mixin = new PropertiesConfigMixin();
79 try {
80 mixin.loadConfiguration(new Properties());
81 }
82 catch (InitializationException e) {
83 System.out.println("exception caught (as expected): " + e);
84 return; // expected
85 }
86 fail("no prog name given & no fatal exception given.");
87 }
88
89 /***
90 * suite()
91 * @return Test suite of all tests for this class.
92 */
93 public static Test suite() {
94 return new TestSuite(PropertiesConfigMixinTest.class);
95 }
96
97 /***
98 * main()
99 * @param args
100 */
101 public static void main(String[] args) {
102 TestRunner.run(suite());
103 }
104
105 }
This page was automatically generated by Maven