001: /*
002: * Copyright (C) The DNA Group. All rights reserved.
003: *
004: * This software is published under the terms of the DNA
005: * Software License version 1.1, a copy of which has been included
006: * with this distribution in the LICENSE.txt file.
007: */
008: package org.codehaus.dna.impl;
009:
010: import junit.framework.TestCase;
011:
012: import org.codehaus.dna.ResourceLocator;
013: import org.codehaus.dna.impl.ConsoleLogger;
014: import org.codehaus.dna.impl.ContainerUtil;
015: import org.codehaus.dna.impl.DefaultConfiguration;
016: import org.codehaus.dna.impl.DefaultResourceLocator;
017:
018: public class ContainerUtilTestCase extends TestCase {
019: public void testEnableLoggingOnComponentNotImplementingStage()
020: throws Exception {
021: final Object object = new Object();
022: ContainerUtil.enableLogging(object, null);
023: }
024:
025: public void testEnableLoggingOnComponentImplementingStage()
026: throws Exception {
027: final MockComponent object = new MockComponent();
028: final ConsoleLogger logger = new ConsoleLogger();
029:
030: ContainerUtil.enableLogging(object, logger);
031:
032: assertEquals(logger, object.getLogger());
033: }
034:
035: public void testEnableLoggingOnComponentImplementingStageButNullLogger()
036: throws Exception {
037: final MockComponent object = new MockComponent();
038: final ConsoleLogger logger = null;
039:
040: try {
041: ContainerUtil.enableLogging(object, logger);
042: } catch (IllegalArgumentException iae) {
043: return;
044: }
045: fail("Expected stage to fail as passing in null "
046: + "resource but object implements stage.");
047: }
048:
049: public void testComposeOnComponentNotImplementingStage()
050: throws Exception {
051: final Object object = new Object();
052: ContainerUtil.compose(object, null);
053: }
054:
055: public void testComposeOnComponentImplementingStage()
056: throws Exception {
057: final MockComponent object = new MockComponent();
058: final ResourceLocator resource = new DefaultResourceLocator();
059:
060: ContainerUtil.compose(object, resource);
061:
062: assertEquals(resource, object.getServices());
063: }
064:
065: public void testComposeOnComponentImplementingStageButNullLogger()
066: throws Exception {
067: final MockComponent object = new MockComponent();
068: final ResourceLocator resource = null;
069:
070: try {
071: ContainerUtil.compose(object, resource);
072: } catch (IllegalArgumentException iae) {
073: return;
074: }
075: fail("Expected stage to fail as passing in null "
076: + "resource but object implements stage.");
077: }
078:
079: public void testConfigureOnComponentNotImplementingStage()
080: throws Exception {
081: final Object object = new Object();
082: ContainerUtil.configure(object, null);
083: }
084:
085: public void testConfigureOnComponentImplementingStage()
086: throws Exception {
087: final MockComponent object = new MockComponent();
088: final DefaultConfiguration resource = new DefaultConfiguration(
089: "s", "", "");
090:
091: ContainerUtil.configure(object, resource);
092:
093: assertEquals(resource, object.getConfiguration());
094: }
095:
096: public void testConfigureOnComponentImplementingStageButNullLogger()
097: throws Exception {
098: final MockComponent object = new MockComponent();
099: final DefaultConfiguration resource = null;
100:
101: try {
102: ContainerUtil.configure(object, resource);
103: } catch (IllegalArgumentException iae) {
104: return;
105: }
106: fail("Expected stage to fail as passing in null "
107: + "resource but object implements stage.");
108: }
109:
110: public void testInitializeOnComponentNotImplementingStage()
111: throws Exception {
112: final Object object = new Object();
113: ContainerUtil.initialize(object);
114: }
115:
116: public void testInitializeOnComponentImplementingStage()
117: throws Exception {
118: final MockComponent object = new MockComponent();
119: ContainerUtil.initialize(object);
120: assertEquals(true, object.isInitialized());
121: }
122:
123: public void testDisposeOnComponentNotImplementingStage()
124: throws Exception {
125: final Object object = new Object();
126: ContainerUtil.dispose(object);
127: }
128:
129: public void testDisposeOnComponentImplementingStage()
130: throws Exception {
131: final MockComponent object = new MockComponent();
132: ContainerUtil.dispose(object);
133: assertEquals(true, object.isDisposed());
134: }
135: }
|