01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.openejb.config.rules;
17:
18: import junit.framework.TestCase;
19: import org.apache.openejb.config.EjbModule;
20: import org.apache.openejb.config.ValidationWarning;
21: import org.apache.openejb.jee.EjbJar;
22: import org.apache.openejb.jee.EnvEntry;
23: import org.apache.openejb.jee.InjectionTarget;
24: import org.apache.openejb.jee.StatelessBean;
25:
26: /**
27: * @version $Rev: 602704 $ $Date: 2007-12-09 09:58:22 -0800 $
28: */
29: public class CheckInjectionTargetsTest extends TestCase {
30:
31: public void test() throws Exception {
32:
33: EjbModule module = new EjbModule(new EjbJar());
34: StatelessBean bean = module.getEjbJar().addEnterpriseBean(
35: new StatelessBean("CheeseEjb", "org.acme.CheeseEjb"));
36:
37: // Valid
38: EnvEntry envEntry = new EnvEntry("count", Integer.class
39: .getName(), "10");
40: envEntry.getInjectionTarget().add(
41: new InjectionTarget("org.acme.CheeseEjb",
42: "org.acme.CheeseEjb/count"));
43: bean.getEnvEntry().add(envEntry);
44:
45: // Invalid
46: EnvEntry envEntry2 = new EnvEntry("color", String.class
47: .getName(), "yellow");
48: envEntry2.getInjectionTarget().add(
49: new InjectionTarget("org.acme.CheeseEjb",
50: "org.acme.CheeseEjb/setColor"));
51: bean.getEnvEntry().add(envEntry2);
52:
53: // Invalid
54: EnvEntry envEntry3 = new EnvEntry("age", Integer.class
55: .getName(), "5");
56: envEntry3.getInjectionTarget().add(
57: new InjectionTarget("org.acme.CheeseEjb", "setAge"));
58: bean.getEnvEntry().add(envEntry3);
59:
60: CheckInjectionTargets rule = new CheckInjectionTargets();
61: rule.module = module;
62: rule.validate(module);
63:
64: ValidationWarning[] warnings = module.getValidation()
65: .getWarnings();
66: assertEquals(warnings.length, 2);
67:
68: }
69:
70: }
|