001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.config;
017:
018: import junit.framework.TestCase;
019: import org.apache.openejb.assembler.classic.StatelessSessionContainerInfo;
020: import org.apache.openejb.assembler.classic.ContainerInfo;
021: import org.apache.openejb.assembler.classic.ResourceInfo;
022: import org.apache.openejb.config.sys.Container;
023: import org.apache.openejb.config.sys.Resource;
024:
025: import java.net.URI;
026:
027: /**
028: * @version $Rev: 607303 $ $Date: 2007-12-28 10:02:56 -0800 $
029: */
030: public class ConfigureServiceTest extends TestCase {
031:
032: public void testConfigureService() throws Exception {
033: ConfigurationFactory factory = new ConfigurationFactory();
034:
035: // We should be able to create a default definition
036: StatelessSessionContainerInfo defaultStatelessContainer = factory
037: .configureService(StatelessSessionContainerInfo.class);
038: assertNotNull(defaultStatelessContainer);
039: assertNotNull(defaultStatelessContainer.id);
040: assertNotNull(defaultStatelessContainer.className);
041: assertNotNull(defaultStatelessContainer.constructorArgs);
042: assertNotNull(defaultStatelessContainer.properties);
043:
044: // We should be able to create one of these with a different name
045: Container container = new Container("My Stateless Container");
046: StatelessSessionContainerInfo myStatelessContainer = factory
047: .configureService(container,
048: StatelessSessionContainerInfo.class);
049:
050: assertNotNull(myStatelessContainer);
051: assertEquals("My Stateless Container", myStatelessContainer.id);
052: assertEquals(defaultStatelessContainer.className,
053: myStatelessContainer.className);
054: assertNotNull(myStatelessContainer.constructorArgs);
055: assertNotNull(myStatelessContainer.properties);
056:
057: }
058:
059: public void testConfigureService2() throws Exception {
060: ConfigurationFactory factory = new ConfigurationFactory();
061:
062: // We should be able to create one of these with a different name
063:
064: Container container = new Container("MyContainer", "STATELESS",
065: "org.acme#CheddarContainer");
066: StatelessSessionContainerInfo myStatelessContainer = factory
067: .configureService(container,
068: StatelessSessionContainerInfo.class);
069:
070: assertNotNull(myStatelessContainer);
071: assertEquals("MyContainer", myStatelessContainer.id);
072: assertEquals("org.acme.SuperContainer",
073: myStatelessContainer.className);
074: assertNotNull(myStatelessContainer.constructorArgs);
075: assertNotNull(myStatelessContainer.properties);
076: assertNotNull(myStatelessContainer.properties
077: .getProperty("myProperty"));
078: assertEquals("Yummy Cheese", myStatelessContainer.properties
079: .getProperty("myProperty"));
080: }
081:
082: public void testConfigureServiceOverriddenProperty()
083: throws Exception {
084: ConfigurationFactory factory = new ConfigurationFactory();
085:
086: Container container = new Container("MyContainer", "STATELESS",
087: "org.acme#CheddarContainer");
088: container.getProperties().setProperty("myProperty",
089: "Cheese is good");
090:
091: StatelessSessionContainerInfo myStatelessContainer = factory
092: .configureService(container,
093: StatelessSessionContainerInfo.class);
094:
095: assertNotNull(myStatelessContainer);
096: assertEquals("MyContainer", myStatelessContainer.id);
097: assertEquals("org.acme.SuperContainer",
098: myStatelessContainer.className);
099: assertNotNull(myStatelessContainer.constructorArgs);
100: assertNotNull(myStatelessContainer.properties);
101: assertNotNull(myStatelessContainer.properties
102: .getProperty("myProperty"));
103: assertEquals("Cheese is good", myStatelessContainer.properties
104: .getProperty("myProperty"));
105: }
106:
107: public void testConfigureServiceAddedProperty() throws Exception {
108: ConfigurationFactory factory = new ConfigurationFactory();
109:
110: Container container = new Container("MyContainer", "STATELESS",
111: "org.acme#CheddarContainer");
112: container.getProperties().setProperty("anotherProperty",
113: "Cheese is good");
114: StatelessSessionContainerInfo myStatelessContainer = factory
115: .configureService(container,
116: StatelessSessionContainerInfo.class);
117:
118: assertNotNull(myStatelessContainer);
119: assertEquals("MyContainer", myStatelessContainer.id);
120: assertEquals("org.acme.SuperContainer",
121: myStatelessContainer.className);
122: assertNotNull(myStatelessContainer.constructorArgs);
123: assertNotNull(myStatelessContainer.properties);
124: assertNotNull(myStatelessContainer.properties
125: .getProperty("myProperty"));
126: assertEquals("Yummy Cheese", myStatelessContainer.properties
127: .getProperty("myProperty"));
128: assertNotNull(myStatelessContainer.properties
129: .getProperty("anotherProperty"));
130: assertEquals("Cheese is good", myStatelessContainer.properties
131: .getProperty("anotherProperty"));
132: }
133:
134: public void testConfigureByType() throws Exception {
135: ConfigurationFactory factory = new ConfigurationFactory();
136:
137: Container container = new Container("MyContainer", "STATELESS",
138: null);
139: container.getProperties().setProperty("anotherProperty",
140: "Cheese is good");
141: ContainerInfo myStatelessContainer = factory.configureService(
142: container, ContainerInfo.class);
143:
144: assertNotNull(myStatelessContainer);
145: assertEquals(
146: "org.apache.openejb.core.stateless.StatelessContainer",
147: myStatelessContainer.className);
148: }
149:
150: public void testConfigureServiceAddedPropertyViaURI()
151: throws Exception {
152: ConfigurationFactory factory = new ConfigurationFactory();
153:
154: URI uri = new URI(
155: "new://Container?type=STATELESS&provider=org.acme%23CheddarContainer");
156:
157: Container container = (Container) factory.toConfigDeclaration(
158: "MyContainer", uri);
159:
160: container.getProperties().setProperty("anotherProperty",
161: "Cheese is good");
162: StatelessSessionContainerInfo myStatelessContainer = factory
163: .configureService(container,
164: StatelessSessionContainerInfo.class);
165:
166: assertNotNull(myStatelessContainer);
167: assertEquals("MyContainer", myStatelessContainer.id);
168: assertEquals("org.acme.SuperContainer",
169: myStatelessContainer.className);
170: assertNotNull(myStatelessContainer.constructorArgs);
171: assertNotNull(myStatelessContainer.properties);
172: assertNotNull(myStatelessContainer.properties
173: .getProperty("myProperty"));
174: assertEquals("Yummy Cheese", myStatelessContainer.properties
175: .getProperty("myProperty"));
176: assertNotNull(myStatelessContainer.properties
177: .getProperty("anotherProperty"));
178: assertEquals("Cheese is good", myStatelessContainer.properties
179: .getProperty("anotherProperty"));
180: }
181:
182: public void testQueue() throws Exception {
183: ConfigurationFactory factory = new ConfigurationFactory();
184:
185: ResourceInfo resourceInfo = factory.configureService(
186: new Resource("myQueue", "Queue"), ResourceInfo.class);
187:
188: assertNotNull(resourceInfo);
189: assertEquals("myQueue", resourceInfo.id);
190: assertNotNull(resourceInfo.constructorArgs);
191: assertNotNull(resourceInfo.properties);
192: assertEquals("myQueue", resourceInfo.properties
193: .getProperty("destination"));
194: }
195:
196: }
|