1 /* 2 * Replica is published under the terms 3 * of the Apache Software License. 4 */ 5 package replica.server.commands; 6 7 import java.sql.SQLException; 8 9 import org.springframework.jdbc.datasource.DriverManagerDataSource; 10 11 import replica.core.ApplicationMessage; 12 import junit.framework.TestCase; 13 14 /*** 15 * 16 * @author Pedro Costa 17 * @author Helder Silva 18 * @since 31/Jan/2004 19 */ 20 public class StartupDatabaseCommandTest extends TestCase { 21 22 StartupDatabaseCommand stdbc; 23 DriverManagerDataSource dataSource; 24 ShutdownDatabaseCommand sddbc; 25 26 /*** 27 * Constructor for StartupDatabaseCommandTest. 28 * @param name 29 */ 30 public StartupDatabaseCommandTest(String name) { 31 super(name); 32 } 33 34 public void testInternalExecute() { 35 36 ApplicationMessage msg = new ApplicationMessage(); 37 38 msg.setBody("startup database on port 9011;"); 39 40 stdbc.internalExecute(msg); 41 42 assertEquals("org.hsqldb.jdbcDriver", dataSource.getDriverClassName()); 43 assertEquals("jdbc:hsqldb:hsql://localhost:9011/replicatest", dataSource.getUrl()); 44 45 assertNotNull(sddbc.server); 46 47 try{Thread.sleep(500);}catch(InterruptedException e){} 48 49 try{ 50 dataSource.getConnection("sa",""); 51 } 52 catch(SQLException e){ 53 e.printStackTrace(); 54 fail(); 55 } 56 } 57 58 /* (non-Javadoc) 59 * @see junit.framework.TestCase#setUp() 60 */ 61 protected void setUp() throws Exception { 62 super.setUp(); 63 64 stdbc = new StartupDatabaseCommand(); 65 66 stdbc.setName("replicatest"); 67 68 dataSource = new DriverManagerDataSource(); 69 70 stdbc.setDataSource(dataSource); 71 72 sddbc = new ShutdownDatabaseCommand(); 73 74 stdbc.setShutdownDatabaseCommand(sddbc); 75 } 76 77 /* (non-Javadoc) 78 * @see junit.framework.TestCase#tearDown() 79 */ 80 protected void tearDown() throws Exception { 81 super.tearDown(); 82 83 sddbc.server.stop(); 84 while( sddbc.server.getState() != 16 /*ServerConstants.SERVER_STATE_SHUTDOWN*/ ){ 85 try{ Thread.sleep(200); }catch(InterruptedException e){} 86 } 87 } 88 89 }

This page was automatically generated by Maven