ORCentral

src/eu/coform/test/UserIdForSessDBCommandTest.java

Go to the documentation of this file.
00001 package eu.coform.test;
00002 
00003 import static org.junit.Assert.*;
00004 
00005 import java.sql.ResultSet;
00006 import java.sql.SQLException;
00007 
00008 import org.junit.Before;
00009 import org.junit.Test;
00010 
00011 import eu.coform.Location;
00012 import eu.coform.Session;
00013 import eu.coform.command.location.QueryAllLocationCommand;
00014 import eu.coform.command.loginsession.LoginCommand;
00015 import eu.coform.database.DBException;
00016 import eu.coform.database.Database;
00017 import eu.coform.database.Query;
00018 import eu.coform.database.command.UserIdForSessDBCommand;
00019 
00020 public class UserIdForSessDBCommandTest {
00021 
00022    private LoginCommand loginCom =  null;
00023    private QueryAllLocationCommand allLoc = null;
00024    private Session session = null;
00025    @Before
00026    public void setUp() throws Exception {
00027       allLoc = new QueryAllLocationCommand();
00028       Location[] locs = allLoc.execute();
00029       loginCom = new LoginCommand();
00030       loginCom.setLocation(locs[0]);
00031       loginCom.setMinutesTimout(100);
00032       loginCom.setPassword("werner");
00033       loginCom.setUsername("werner");
00034       session = loginCom.execute();
00035    }
00036 
00037    @Test
00038    public void testExec() {
00039       UserIdForSessDBCommand com = new UserIdForSessDBCommand(session);
00040       try {
00041          com.exec();
00042       } catch (DBException e) {
00043          // TODO Auto-generated catch block
00044          e.printStackTrace();
00045          assert(false);
00046       }
00047       int userId = com.getResult();
00048       
00049       Query query = Database.getInstance().getNewQuery();
00050       query.setQuery("SELECT ID FROM user WHERE Username = 'werner'");
00051       ResultSet set = Database.getInstance().query(query);
00052       try {
00053          set.next();
00054       } catch (SQLException e) {
00055          // TODO Auto-generated catch block
00056          assert(false);
00057       }
00058       int queriedId=0;
00059       try {
00060          queriedId = set.getInt(1);
00061       } catch (SQLException e) {
00062          // TODO Auto-generated catch block
00063          assert(false);
00064       }
00065       System.out.println("from com :"+userId);
00066       System.out.println("queried:"+queriedId);
00067       assertEquals(userId,queriedId);
00068    }
00069 
00070 }
 All Classes Namespaces Files Functions Variables Enumerations