1 15 package hivemind.test.rules; 16 17 import hivemind.test.services.impl.StringHolderImpl; 18 19 import org.apache.hivemind.SymbolExpander; 20 import org.apache.hivemind.impl.ElementImpl; 21 import org.apache.hivemind.internal.Module; 22 import org.apache.hivemind.schema.SchemaProcessor; 23 import org.apache.hivemind.schema.rules.NullTranslator; 24 import org.apache.hivemind.schema.rules.ReadAttributeRule; 25 import org.apache.hivemind.test.HiveMindTestCase; 26 import org.easymock.MockControl; 27 28 public class TestReadAttributeRule extends HiveMindTestCase 29 { 30 public void testReadAttributeRule() 31 { 32 ElementImpl element = new ElementImpl(); 33 element.setElementName("myelement"); 34 35 ReadAttributeRule rule = new ReadAttributeRule(); 36 37 rule.setAttributeName("fred"); 38 rule.setPropertyName("value"); 39 40 MockControl control = newControl(SchemaProcessor.class); 41 SchemaProcessor mockProcessor = (SchemaProcessor) control.getMock(); 42 43 mockProcessor.getAttributeDefault("fred"); 44 control.setReturnValue("${flintstone}"); 45 46 mockProcessor.getContributingModule(); 47 48 MockControl moduleControl = newControl(Module.class); 49 Module mockModule = (Module) moduleControl.getMock(); 50 51 control.setReturnValue(mockModule); 52 53 MockControl symbolExpanderControl = newControl(SymbolExpander.class); 54 SymbolExpander symbolExpander = (SymbolExpander) symbolExpanderControl.getMock(); 55 56 mockProcessor.getSymbolExpander(); 57 control.setReturnValue(symbolExpander); 58 59 mockProcessor.peek(); 60 61 StringHolderImpl target = new StringHolderImpl(); 62 control.setReturnValue(target); 63 64 mockProcessor.getAttributeTranslator("fred"); 65 control.setReturnValue(new NullTranslator()); 66 67 mockProcessor.getContributingModule(); 68 control.setReturnValue(mockModule); 69 70 symbolExpander.expandSymbols("${flintstone}", element.getLocation()); 71 symbolExpanderControl.setReturnValue("FLINTSTONE"); 72 73 replayControls(); 74 75 rule.begin(mockProcessor, element); 76 rule.end(mockProcessor, element); 77 78 verifyControls(); 79 80 assertEquals("FLINTSTONE", target.getValue()); 81 } 82 } 83 | Popular Tags |