View | Details | Raw Unified | Return to bug 50019
Collapse All | Expand All

(-)org/apache/naming/resources/TestJndiLookupName.java (+238 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 * 
9
 *      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
 */
17
package org.apache.naming.resources;
18
19
import java.io.StringReader;
20
21
import org.apache.catalina.deploy.ContextEjb;
22
import org.apache.catalina.deploy.ContextEnvironment;
23
import org.apache.catalina.deploy.ContextLocalEjb;
24
import org.apache.catalina.deploy.ContextResource;
25
import org.apache.catalina.deploy.ContextResourceEnvRef;
26
import org.apache.catalina.deploy.ContextService;
27
import org.apache.catalina.deploy.MessageDestination;
28
import org.apache.catalina.deploy.MessageDestinationRef;
29
import org.apache.catalina.deploy.WebXml;
30
import org.apache.catalina.startup.DigesterFactory;
31
import org.apache.catalina.startup.TomcatBaseTest;
32
import org.apache.catalina.startup.WebRuleSet;
33
import org.apache.tomcat.util.digester.Digester;
34
35
/**
36
 * Unit test for testing lookup name.
37
 * @author Gurkan Erdogdu
38
 * @version $Revision: $
39
 */
40
public class TestJndiLookupName extends TomcatBaseTest {
41
42
    private Digester digester;
43
    
44
    public void setUp() throws Exception{
45
        super.setUp();
46
        this.digester = DigesterFactory.newDigester(false,false,new WebRuleSet(false));
47
    }
48
    
49
    /**
50
     * Context Environment
51
     */
52
    public void testLookupNameForContextEnvironment() throws Exception {
53
        
54
        WebXml webXml = new WebXml();
55
        webXml.setPublicId("web-app_3_0.xsd");
56
        
57
        ContextEnvironment env = new ContextEnvironment();
58
        env.setDescription("My Context Desc");
59
        env.setName("jndiName");
60
        env.setLookupName("java:/my/injection");
61
        
62
        webXml.addEnvEntry(env);
63
        
64
        WebXml parsed = new WebXml();
65
        this.digester.push(parsed);
66
        //Lets do revers
67
        this.digester.parse(new StringReader(webXml.toXml()));
68
        
69
        ContextEnvironment contextEnv = parsed.getEnvEntries().get("jndiName");
70
        assertEquals("java:/my/injection", contextEnv.getLookupName());        
71
    }
72
    
73
    /**
74
     * Context Ejb
75
     */
76
    public void testLookupNameForContextEjb() throws Exception {
77
        
78
        WebXml webXml = new WebXml();
79
        webXml.setPublicId("web-app_3_0.xsd");
80
        
81
        ContextEjb ejbRef = new ContextEjb();
82
        ejbRef.setDescription("My Context Desc");
83
        ejbRef.setName("jndiName");
84
        ejbRef.setLookupName("java:/my/injection");
85
        
86
        webXml.addEjbRef(ejbRef);
87
        
88
        WebXml parsed = new WebXml();
89
        this.digester.push(parsed);
90
        //Lets do revers
91
        this.digester.parse(new StringReader(webXml.toXml()));
92
        
93
        ContextEjb parsedEjb = parsed.getEjbRefs().get("jndiName");
94
        assertEquals("java:/my/injection", parsedEjb.getLookupName());        
95
    }
96
    
97
    /**
98
     * Context Local Ejb
99
     */
100
    public void testLookupNameForContextLocalEjb() throws Exception {
101
        
102
        WebXml webXml = new WebXml();
103
        webXml.setPublicId("web-app_3_0.xsd");
104
        
105
        ContextLocalEjb ejbRef = new ContextLocalEjb();
106
        ejbRef.setDescription("My Context Desc");
107
        ejbRef.setName("jndiName");
108
        ejbRef.setLookupName("java:/my/injection");
109
        
110
        webXml.addEjbLocalRef(ejbRef);
111
        
112
        WebXml parsed = new WebXml();
113
        this.digester.push(parsed);
114
        //Lets do revers
115
        this.digester.parse(new StringReader(webXml.toXml()));
116
        
117
        ContextLocalEjb parsedEjb = parsed.getEjbLocalRefs().get("jndiName");
118
        assertEquals("java:/my/injection", parsedEjb.getLookupName());        
119
    }
120
    
121
    /**
122
     * Context Service
123
     */
124
    public void testLookupNameForContextService() throws Exception {
125
        
126
        WebXml webXml = new WebXml();
127
        webXml.setPublicId("web-app_3_0.xsd");
128
        
129
        ContextService serviceRef = new ContextService();
130
        serviceRef.setDescription("My Context Desc");
131
        serviceRef.setName("jndiName");
132
        serviceRef.setLookupName("java:/my/injection");
133
        
134
        webXml.addServiceRef(serviceRef);
135
        
136
        WebXml parsed = new WebXml();
137
        this.digester.push(parsed);
138
        //Lets do revers
139
        this.digester.parse(new StringReader(webXml.toXml()));
140
        
141
        ContextService parsedRef = parsed.getServiceRefs().get("jndiName");
142
        assertEquals("java:/my/injection", parsedRef.getLookupName());        
143
    }
144
    
145
    /**
146
     * Context Resource
147
     */
148
    public void testLookupNameForContextResource() throws Exception {
149
        
150
        WebXml webXml = new WebXml();
151
        webXml.setPublicId("web-app_3_0.xsd");
152
        
153
        ContextResource serviceRef = new ContextResource();
154
        serviceRef.setDescription("My Context Desc");
155
        serviceRef.setName("jndiName");
156
        serviceRef.setLookupName("java:/my/injection");
157
        
158
        webXml.addResourceRef(serviceRef);        
159
        WebXml parsed = new WebXml();
160
        this.digester.push(parsed);
161
        //Lets do revers
162
        this.digester.parse(new StringReader(webXml.toXml()));
163
        
164
        ContextResource parsedRef = parsed.getResourceRefs().get("jndiName");
165
        assertEquals("java:/my/injection", parsedRef.getLookupName());        
166
    }
167
    
168
    /**
169
     * Context Resource Env
170
     */
171
    public void testLookupNameForContextResourceEnv() throws Exception {
172
        
173
        WebXml webXml = new WebXml();
174
        webXml.setPublicId("web-app_3_0.xsd");
175
        
176
        ContextResourceEnvRef serviceRef = new ContextResourceEnvRef();
177
        serviceRef.setDescription("My Context Desc");
178
        serviceRef.setName("jndiName");
179
        serviceRef.setLookupName("java:/my/injection");
180
        
181
        webXml.addResourceEnvRef(serviceRef);        
182
        WebXml parsed = new WebXml();
183
        this.digester.push(parsed);
184
        //Lets do revers
185
        this.digester.parse(new StringReader(webXml.toXml()));
186
        
187
        ContextResourceEnvRef parsedRef = parsed.getResourceEnvRefs().get("jndiName");
188
        assertEquals("java:/my/injection", parsedRef.getLookupName());        
189
    }
190
    
191
    /**
192
     * Message Destination Ref
193
     */
194
    public void testLookupNameForMessageDestinationRef() throws Exception {
195
        
196
        WebXml webXml = new WebXml();
197
        webXml.setPublicId("web-app_3_0.xsd");
198
        
199
        MessageDestinationRef serviceRef = new MessageDestinationRef();
200
        serviceRef.setDescription("My Context Desc");
201
        serviceRef.setName("jndiName");
202
        serviceRef.setLookupName("java:/my/injection");
203
        
204
        webXml.addMessageDestinationRef(serviceRef);        
205
        WebXml parsed = new WebXml();
206
        this.digester.push(parsed);
207
        //Lets do revers
208
        this.digester.parse(new StringReader(webXml.toXml()));
209
        
210
        MessageDestinationRef parsedRef = parsed.getMessageDestinationRefs().get("jndiName");
211
        assertEquals("java:/my/injection", parsedRef.getLookupName());        
212
    }
213
    
214
    /**
215
     * Message Destination
216
     */
217
    public void testLookupNameForMessageDestination() throws Exception {
218
        
219
        WebXml webXml = new WebXml();
220
        webXml.setPublicId("web-app_3_0.xsd");
221
        
222
        MessageDestination serviceRef = new MessageDestination();
223
        serviceRef.setDescription("My Context Desc");
224
        serviceRef.setName("jndiName");
225
        serviceRef.setLookupName("java:/my/injection");
226
        
227
        webXml.addMessageDestination(serviceRef);        
228
        WebXml parsed = new WebXml();
229
        this.digester.push(parsed);
230
        //Lets do revers
231
        this.digester.parse(new StringReader(webXml.toXml()));
232
        
233
        MessageDestination parsedRef = parsed.getMessageDestinations().get("jndiName");
234
        assertEquals("java:/my/injection", parsedRef.getLookupName());        
235
    }
236
    
237
    
238
}
0
  + native
239
  + native

Return to bug 50019