KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > lib > impl > TestMethodInterceptorFactory


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.hivemind.lib.impl;
16
17 import org.apache.hivemind.ApplicationRuntimeException;
18 import org.apache.hivemind.Registry;
19 import org.apache.hivemind.xml.XmlTestCase;
20
21 /**
22  * Tests for {@link MethodInterceptorFactory}.
23  *
24  * @author James Carman
25  * @since 1.1
26  */

27 public class TestMethodInterceptorFactory extends XmlTestCase
28 {
29
30     public void testWithInstanceMethodInterceptor() throws Exception JavaDoc
31     {
32         Registry registry = buildFrameworkRegistry("InstanceMethodInterceptor.xml");
33         final FortuneCookie cookie = (FortuneCookie) registry.getService(FortuneCookie.class);
34         assertEquals( FortuneCookieImpl.FORTUNE + SuffixMethodInterceptor.SUFFIX, cookie.generateFortune());
35     }
36     
37     public void testWithServiceMethodInterceptor() throws Exception JavaDoc
38     {
39         Registry registry = buildFrameworkRegistry("ServiceMethodInterceptor.xml");
40         final FortuneCookie cookie = (FortuneCookie) registry.getService(FortuneCookie.class);
41         assertEquals( FortuneCookieImpl.FORTUNE + SuffixMethodInterceptor.SUFFIX, cookie.generateFortune());
42     }
43     
44     public void testWithMultipleMethodInterceptors() throws Exception JavaDoc
45     {
46         Registry registry = buildFrameworkRegistry("MultipleMethodInterceptors.xml");
47         final FortuneCookie cookie = (FortuneCookie) registry.getService(FortuneCookie.class);
48         final String JavaDoc fortune = cookie.generateFortune();
49         assertEquals( FortuneCookieImpl.FORTUNE + SuffixMethodInterceptor.SUFFIX + SuffixMethodInterceptor.SUFFIX, fortune);
50     }
51     public void testWithNonMethodInterceptor() throws Exception JavaDoc
52     {
53         Registry registry = buildFrameworkRegistry("NonMethodInterceptor.xml");
54         try
55         {
56             final FortuneCookie cookie = (FortuneCookie) registry.getService(FortuneCookie.class);
57             cookie.generateFortune();
58             fail( "Should not be able to construct service interceptor using non-MethodInterceptor instance." );
59         }
60         catch( ApplicationRuntimeException e )
61         {
62         }
63         
64     }
65 }
66
Popular Tags