01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: TestParticipantConfig.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.rep;
09:
10: import com.uwyn.rife.config.Config;
11: import com.uwyn.rife.rep.BlockingRepository;
12: import com.uwyn.rife.rep.participants.ParticipantConfig;
13: import com.uwyn.rife.resources.ResourceFinderClasspath;
14: import junit.framework.TestCase;
15:
16: public class TestParticipantConfig extends TestCase {
17: private Repository mDefaultRep = null;
18:
19: public TestParticipantConfig(String name) {
20: super (name);
21: }
22:
23: public void setUp() {
24: mDefaultRep = Rep.getDefaultRepository();
25: }
26:
27: public void tearDown() {
28: Rep.setDefaultRepository(mDefaultRep);
29: }
30:
31: public void testParticipantNotDefined() throws Exception {
32: BlockingRepository rep = new BlockingRepository();
33: rep.runParticipants(ResourceFinderClasspath.getInstance());
34: Rep.setDefaultRepository(rep);
35: assertFalse(Rep.hasParticipant("ParticipantConfig"));
36: assertNull(Rep.getParticipant("ParticipantConfig"));
37: assertFalse(Config.hasRepInstance());
38: assertNull(Config.getRepInstance());
39: }
40:
41: public void testParticipantMissingParameter() throws Exception {
42: BlockingRepository rep = new BlockingRepository();
43: rep.addParticipant(ParticipantConfig.class.getName(), null,
44: true, null);
45: try {
46: rep.runParticipants(ResourceFinderClasspath.getInstance());
47: fail();
48: } catch (IllegalArgumentException e) {
49: assertTrue(e.getMessage().indexOf("can't be null") != -1);
50: }
51: }
52:
53: public void testParticipantDefined() throws Exception {
54: BlockingRepository rep = new BlockingRepository();
55: rep.addParticipant(ParticipantConfig.class.getName(), null,
56: true, "xml/test_xml2config.xml");
57: rep.runParticipants(ResourceFinderClasspath.getInstance());
58:
59: assertNotSame(Rep.getParticipant("ParticipantConfig"), rep
60: .getParticipant("ParticipantConfig"));
61: assertNotSame(Config.getRepInstance(), rep.getParticipant(
62: "ParticipantConfig").getObject());
63:
64: Rep.setDefaultRepository(rep);
65:
66: assertTrue(Rep.hasParticipant("ParticipantConfig"));
67: assertNotNull(Rep.getParticipant("ParticipantConfig"));
68: assertSame(Rep.getParticipant("ParticipantConfig"), rep
69: .getParticipant("ParticipantConfig"));
70: assertTrue(Config.hasRepInstance());
71: assertNotNull(Config.getRepInstance());
72: assertSame(Config.getRepInstance(), rep.getParticipant(
73: "ParticipantConfig").getObject());
74: assertTrue(Config.getRepInstance() instanceof Config);
75: }
76:
77: public void testParticipantXmlSelectorProperty() throws Exception {
78: BlockingRepository rep = new BlockingRepository();
79: rep.addParticipant(ParticipantConfig.class.getName(), null,
80: true, "XmlSelectorProperty");
81: rep.runParticipants(ResourceFinderClasspath.getInstance());
82: Rep.setDefaultRepository(rep);
83:
84: Config config = Config.getRepInstance();
85: assertNotNull(config);
86:
87: assertEquals(config.getString("TEST_CONFIG_PARAM"),
88: "this value is available in test config");
89: }
90: }
|