1 /* 2 * Replica is published under the terms 3 * of the Apache Software License. 4 */ 5 package replica.command; 6 7 import java.util.Hashtable; 8 9 import junit.framework.TestCase; 10 11 /*** 12 * 13 * @author Pedro Costa 14 * @author Helder Silva 15 * @since 18/Jan/2004 16 */ 17 public class AbstractCommandProcessorTest extends TestCase { 18 19 final String command = "select * from table;"; 20 21 /*** 22 * Constructor for AbstractCommandProcessorTest. 23 * @param name 24 */ 25 public AbstractCommandProcessorTest(String name) { 26 super(name); 27 } 28 29 public void testProcess() { 30 31 AbstractCommandProcessor proc = new MockCommandProcessor(); 32 33 proc.configure(); 34 35 Object res = proc.process( command ); 36 37 assertEquals( command, res ); 38 39 } 40 41 class MockCommandProcessor extends AbstractCommandProcessor{ 42 public MockCommandProcessor() { 43 super(); 44 } 45 46 protected Mappings readMappings() { 47 48 HashtableMappings mapps = new HashtableMappings(); 49 50 Hashtable mappsTable = new Hashtable(); 51 52 mappsTable.put( "prop1", "value"); 53 mappsTable.put( "prop2", "10" ); 54 55 mapps.addMapping("select", MockCommand.class.getName(), mappsTable ); 56 57 return mapps; 58 } 59 60 /*** 61 * This default implementation assumes that command is a string and that the first word is the action Id. 62 * 63 * It passes the all command instruction, including the action Id, to the mapped command on execute. 64 * 65 * @return Object the result of the command execution. 66 * @see replica.server.cmd.CommandProcessor#process(java.lang.String) 67 * @throws CommandException if there is a problem executing the command. 68 * Callers can choose to catch or not. 69 */ 70 public Object process(Object command) { 71 72 return getCommand( command ).execute( command ); 73 } 74 75 } 76 77 }

This page was automatically generated by Maven