001: /* ====================================================================
002: The Jicarilla Software License
003:
004: Copyright (c) 2003 Leo Simons.
005: All rights reserved.
006:
007: Permission is hereby granted, free of charge, to any person obtaining
008: a copy of this software and associated documentation files (the
009: "Software"), to deal in the Software without restriction, including
010: without limitation the rights to use, copy, modify, merge, publish,
011: distribute, sublicense, and/or sell copies of the Software, and to
012: permit persons to whom the Software is furnished to do so, subject to
013: the following conditions:
014:
015: The above copyright notice and this permission notice shall be
016: included in all copies or substantial portions of the Software.
017:
018: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
019: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
020: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
021: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
022: CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
023: TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
024: SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
025: ==================================================================== */
026: package org.jicarilla.container.test.util;
027:
028: import junit.framework.TestCase;
029: import org.apache.avalon.framework.configuration.Configuration;
030: import org.apache.avalon.framework.configuration.ConfigurationException;
031: import org.apache.avalon.framework.configuration.DefaultConfiguration;
032: import org.easymock.MockControl;
033: import org.jicarilla.container.Resolver;
034: import org.jicarilla.container.util.ConfigurationUtil;
035:
036: /**
037: *
038: *
039: * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
040: * @version $Id: ConfigurationUtilTestCase.java,v 1.1 2004/02/29 18:08:09 lsimons Exp $
041: */
042: public class ConfigurationUtilTestCase extends TestCase {
043: protected Resolver resolver;
044: protected MockControl resolverControl;
045:
046: public void setUp() throws Exception {
047: super .setUp();
048:
049: resolverControl = MockControl.createControl(Resolver.class);
050: resolver = (Resolver) resolverControl.getMock();
051: }
052:
053: public void testGetConfigurationFromContainerUsingXStream()
054: throws Exception {
055: MyComponentConfiguration config = new MyComponentConfiguration(
056: 1);
057: resolver.get(MyComponent.class.getName() + "Configuration");
058: resolverControl.setReturnValue(config);
059: resolverControl.replay();
060:
061: Configuration configuration = ConfigurationUtil
062: .getConfiguration(resolver, MyComponent.class.getName());
063: assertEquals("1", configuration.getChild("something")
064: .getValue());
065:
066: resolverControl.verify();
067: }
068:
069: public void testGetConfigurationFromContainerUsingExistingConfigurationObject()
070: throws Exception {
071: Configuration config = new DefaultConfiguration("blah");
072: resolver.get(MyComponent.class.getName() + "Configuration");
073: resolverControl.setReturnValue(config);
074: resolverControl.replay();
075:
076: Configuration configuration = ConfigurationUtil
077: .getConfiguration(resolver, MyComponent.class.getName());
078: assertEquals(config, configuration);
079:
080: resolverControl.verify();
081: }
082:
083: public void testGetConfigurationFromContainerThatDoesNotExist()
084: throws Exception {
085: resolver.get(MyComponent.class.getName() + "Configuration");
086: resolverControl.setReturnValue(null);
087: resolverControl.replay();
088:
089: try {
090: ConfigurationUtil.getConfiguration(resolver,
091: MyComponent.class.getName());
092: fail("Expected an exception!");
093: } catch (ConfigurationException th) {
094: }
095:
096: resolverControl.verify();
097: }
098:
099: public class MyComponent {
100: }
101:
102: public class MyComponentConfiguration {
103: private int something;
104:
105: public MyComponentConfiguration(int something) {
106: this .something = something;
107: }
108:
109: public int getSomething() {
110: return something;
111: }
112:
113: public void setSomething(int something) {
114: this.something = something;
115: }
116: }
117: }
|