ORCentral
|
00001 package eu.coform.test; 00002 00003 import java.sql.ResultSet; 00004 import java.sql.SQLException; 00005 00006 import eu.coform.UniqueID; 00007 import eu.coform.command.QueryUniqueIDCommand; 00008 import eu.coform.database.Database; 00009 import eu.coform.database.Query; 00010 import junit.framework.TestCase; 00011 00012 public class QueryUniqueIDCommandTest extends TestCase { 00013 00014 private UniqueID guid = new UniqueID("550e8400-e29b-11d4-a716-446655440000"); 00015 private String uuidID; 00016 00017 public QueryUniqueIDCommandTest(String name) { 00018 super(name); 00019 } 00020 00021 private void setUpUniqueID() throws SQLException { 00022 { 00023 Query query = Database.getInstance().getNewQuery(); 00024 query.setQuery( 00025 "INSERT INTO `uuidtable` (`UUID`) VALUES (0x" + guid.toBin16() + ")"); 00026 Database.getInstance().insert(query); 00027 } 00028 00029 { 00030 Query query = Database.getInstance().getNewQuery(); 00031 query.setQuery( 00032 "SELECT ID FROM `uuidtable` WHERE hex(UUID) = '" + guid.toBin16() + "'"); 00033 ResultSet rs = Database.getInstance().query(query); 00034 rs.next(); 00035 uuidID = rs.getString("ID"); 00036 } 00037 } 00038 00039 private void tearDownUniqueID() throws SQLException { 00040 Query query = Database.getInstance().getNewQuery(); 00041 query.setQuery( 00042 "DELETE FROM `uuidtable` WHERE `ID`='" + uuidID + "';"); 00043 Database.getInstance().insert(query); 00044 } 00045 00046 protected void setUp() throws Exception { 00047 super.setUp(); 00048 setUpUniqueID(); 00049 } 00050 00051 protected void tearDown() throws Exception { 00052 super.tearDown(); 00053 tearDownUniqueID(); 00054 } 00055 00056 public void testExecute() throws Exception { 00057 QueryUniqueIDCommand c = new QueryUniqueIDCommand(); 00058 c.setId(uuidID); 00059 UniqueID u = c.execute(); 00060 assertNotNull(u); 00061 assertEquals(u.getId(), guid.getId()); 00062 } 00063 00064 }