1 15 package org.apache.hivemind.service.impl; 16 17 import org.apache.hivemind.ApplicationRuntimeException; 18 import org.apache.hivemind.ServiceImplementationFactoryParameters; 19 import org.apache.hivemind.TranslatorManager; 20 import org.apache.hivemind.internal.Module; 21 import org.apache.hivemind.schema.Translator; 22 import org.apache.hivemind.test.HiveMindTestCase; 23 import org.easymock.MockControl; 24 25 public class TestBuilderPropertyFacet extends HiveMindTestCase 26 { 27 public void testCachingOfTranslatedValues() throws Exception 28 { 29 MockControl moduleControl = newControl(Module.class); 30 Module module = (Module) moduleControl.getMock(); 31 32 MockControl translatorControl = newControl(Translator.class); 33 Translator translator = (Translator) translatorControl.getMock(); 34 35 MockControl paramsControl = newControl(ServiceImplementationFactoryParameters.class); 36 ServiceImplementationFactoryParameters params = (ServiceImplementationFactoryParameters) paramsControl 37 .getMock(); 38 39 MockControl tmControl = newControl(TranslatorManager.class); 40 TranslatorManager tm = (TranslatorManager) tmControl.getMock(); 41 42 BuilderPropertyFacet facet = new BuilderPropertyFacet(); 43 44 facet.setTranslator("foo"); 45 facet.setValue("bar"); 46 47 params.getInvokingModule(); 48 paramsControl.setDefaultReturnValue(module); 49 50 module.getService(TranslatorManager.class); 51 moduleControl.setReturnValue(tm); 52 53 tm.getTranslator("foo"); 54 tmControl.setReturnValue(translator); 55 56 translator.translate(module, Object .class, "bar", null); 57 translatorControl.setReturnValue("BAR"); 58 59 replayControls(); 60 61 facet.isAssignableToType(params, Object .class); 62 facet.getFacetValue(params, Object .class); 63 64 verifyControls(); 65 } 66 67 public void testAssignableFromBadValue() 68 { 69 MockControl moduleControl = newControl(Module.class); 70 Module module = (Module) moduleControl.getMock(); 71 72 MockControl translatorControl = newControl(Translator.class); 73 Translator translator = (Translator) translatorControl.getMock(); 74 75 MockControl paramsControl = newControl(ServiceImplementationFactoryParameters.class); 76 ServiceImplementationFactoryParameters params = (ServiceImplementationFactoryParameters) paramsControl 77 .getMock(); 78 79 MockControl tmControl = newControl(TranslatorManager.class); 80 TranslatorManager tm = (TranslatorManager) tmControl.getMock(); 81 82 BuilderPropertyFacet facet = new BuilderPropertyFacet(); 83 84 facet.setTranslator("foo"); 85 facet.setValue("bar"); 86 87 params.getInvokingModule(); 88 paramsControl.setDefaultReturnValue(module); 89 90 module.getService(TranslatorManager.class); 91 moduleControl.setReturnValue(tm); 92 93 tm.getTranslator("foo"); 94 tmControl.setReturnValue(translator); 95 96 translator.translate(module, Object .class, "bar", null); 97 ApplicationRuntimeException exception = new ApplicationRuntimeException(""); 98 translatorControl.setThrowable(exception); 99 100 replayControls(); 101 102 try 103 { 104 facet.isAssignableToType(params, Object .class); 105 unreachable(); 106 } 107 catch (ApplicationRuntimeException e) 108 { 109 assertSame(exception, e); 110 } 111 112 verifyControls(); 113 } 114 } 115 | Popular Tags |