1 15 package org.apache.hivemind.service.impl; 16 17 import java.util.Collections ; 18 19 import org.apache.hivemind.ErrorLog; 20 import org.apache.hivemind.internal.Module; 21 import org.apache.hivemind.service.ObjectProvider; 22 import org.apache.hivemind.test.HiveMindTestCase; 23 import org.easymock.MockControl; 24 25 30 public class TestObjectTranslator extends HiveMindTestCase 31 { 32 33 public void testBadLocator() 34 { 35 ObjectTranslator ot = new ObjectTranslator(); 36 37 Module module = (Module) newMock(Module.class); 38 39 ErrorLog el = (ErrorLog) newMock(ErrorLog.class); 40 41 ot.setErrorLog(el); 42 ot.setContributions(Collections.EMPTY_MAP); 43 44 el.error("Object provider selector 'badprefix' is not properly formatted.", null, null); 45 46 replayControls(); 47 48 Object result = ot.translate(module, Object .class, "badprefix", null); 49 50 assertNull(result); 51 52 verifyControls(); 53 } 54 55 public void testUnknownPrefix() 56 { 57 ObjectTranslator ot = new ObjectTranslator(); 58 59 Module module = (Module) newMock(Module.class); 60 61 ErrorLog el = (ErrorLog) newMock(ErrorLog.class); 62 63 ot.setErrorLog(el); 64 ot.setContributions(Collections.EMPTY_MAP); 65 66 el.error("No object provider exists for prefix 'zap'.", null, null); 67 68 replayControls(); 69 70 Object result = ot.translate(module, Object .class, "zap:foo", null); 71 72 assertNull(result); 73 74 verifyControls(); 75 } 76 77 public void testSuccess() 78 { 79 MockControl c = newControl(ObjectProvider.class); 80 ObjectProvider p = (ObjectProvider) c.getMock(); 81 82 ObjectTranslator ot = new ObjectTranslator(); 83 ot.setContributions(Collections.singletonMap("fetch", p)); 84 85 Module module = (Module) newMock(Module.class); 86 87 p.provideObject(module, Integer .class, "zap", null); 88 Object value = new Integer (13); 89 90 c.setReturnValue(value); 91 92 replayControls(); 93 94 Object result = ot.translate(module, Integer .class, "fetch:zap", null); 95 96 assertSame(value, result); 97 98 verifyControls(); 99 } 100 101 public void testNullInput() 102 { 103 ObjectTranslator ot = new ObjectTranslator(); 104 105 assertNull(ot.translate(null, null, null, null)); 106 } 107 } | Popular Tags |