1 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 27 public class TestMethodInterceptorFactory extends XmlTestCase 28 { 29 30 public void testWithInstanceMethodInterceptor() throws Exception 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 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 45 { 46 Registry registry = buildFrameworkRegistry("MultipleMethodInterceptors.xml"); 47 final FortuneCookie cookie = (FortuneCookie) registry.getService(FortuneCookie.class); 48 final String fortune = cookie.generateFortune(); 49 assertEquals( FortuneCookieImpl.FORTUNE + SuffixMethodInterceptor.SUFFIX + SuffixMethodInterceptor.SUFFIX, fortune); 50 } 51 public void testWithNonMethodInterceptor() throws Exception 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 |