ORCentral

src/eu/coform/test/QueryLocationCommandTest.java

Go to the documentation of this file.
00001 package eu.coform.test;
00002 
00003 import java.sql.ResultSet;
00004 import java.sql.SQLException;
00005 
00006 import eu.coform.Location;
00007 import eu.coform.ORException;
00008 import eu.coform.UniqueID;
00009 import eu.coform.command.location.QueryLocationCommand;
00010 import eu.coform.database.Database;
00011 import eu.coform.database.Query;
00012 import junit.framework.TestCase;
00013 
00014 public class QueryLocationCommandTest extends TestCase {
00015    
00016    private UniqueID uuid = new UniqueID("990e8400-e29b-11d4-a716-446655449999");
00017    private String uuidID;
00018    
00019    private String locationName = "woohpwoohoop";
00020    private String wsUrl = "webserviceurl";
00021    private String homeUrl = "homepageurl";
00022    private String description = "descriptionz";
00023    
00024    public QueryLocationCommandTest(String name) {
00025       super(name);
00026    }
00027 
00028    private void setUpUniqueID() throws SQLException {
00029       {
00030          Query query = Database.getInstance().getNewQuery();
00031          query.setQuery(
00032          "INSERT INTO `uuidtable` (`UUID`) VALUES (0x" + uuid.toBin16() + ")");
00033          Database.getInstance().insert(query);
00034       }
00035       
00036       {
00037          Query query = Database.getInstance().getNewQuery();
00038          query.setQuery(
00039                "SELECT ID FROM `uuidtable` WHERE hex(UUID) = '" + uuid.toBin16() + "'");
00040          ResultSet rs = Database.getInstance().query(query);
00041          rs.next();
00042          uuidID = rs.getString("ID");
00043       }
00044    }
00045    
00046    private void tearDownUniqueID() throws SQLException {
00047       Query query = Database.getInstance().getNewQuery();
00048       query.setQuery(
00049       "DELETE FROM `uuidtable` WHERE `ID`='" + uuidID + "';");
00050       Database.getInstance().insert(query);      
00051    }
00052    
00053    private void setUpLocation() throws SQLException {
00054       Query query = Database.getInstance().getNewQuery();
00055       query.setQuery(
00056             "INSERT INTO `location` (`ID`, `Name`, `WebserviceURL`, `HomepageURL`, `Description`) " +
00057             "VALUES ('" + uuidID + "', " +
00058             "'" + locationName + "', " +
00059             "'" + wsUrl + "', " +
00060             "'" + homeUrl + "', " +
00061             "'" + description + "')");
00062       Database.getInstance().insert(query);
00063    }
00064    
00065    private void tearDownLocation() throws SQLException {
00066       Query query = Database.getInstance().getNewQuery();
00067       query.setQuery(
00068       "DELETE FROM `location` WHERE `ID`='" + uuidID + "';");
00069       Database.getInstance().insert(query);      
00070    }
00071    
00072    protected void setUp() throws Exception {
00073       super.setUp();
00074       setUpUniqueID();
00075       setUpLocation();
00076    }
00077 
00078    protected void tearDown() throws Exception {
00079       super.tearDown();
00080       tearDownLocation();
00081       tearDownUniqueID();
00082    }
00083 
00084    public void testExecute() throws Exception {
00085       QueryLocationCommand c = new QueryLocationCommand();
00086       c.setLocationName(locationName);
00087       Location l = c.execute();
00088       assertNotNull(l);
00089       assertEquals(l.getName(), locationName);
00090       assertEquals(l.getWebserviceURL(), wsUrl);
00091       assertEquals(l.getLocationId().getId(), uuid.getId());
00092    }
00093    
00094    public void testBogusExecute() throws Exception {
00095       QueryLocationCommand c = new QueryLocationCommand();
00096       c.setLocationName("trololo");
00097       Location l = null;
00098       try {
00099          l = c.execute();
00100          fail("Should have raised Invalid Location exception");
00101       } catch (ORException e) {}
00102       assertNull(l);
00103    }
00104 }
 All Classes Namespaces Files Functions Variables Enumerations