ORCentral
|
00001 package eu.coform.test; 00002 import org.junit.Before; 00003 import org.junit.Test; 00004 00005 import eu.coform.command.*; 00006 import eu.coform.*; 00007 import eu.coform.Error; 00008 import eu.coform.command.location.QueryLocationCommand; 00009 import eu.coform.command.loginsession.LoginCommand; 00010 import junit.framework.TestCase; 00011 00012 public class LoginCommandTest extends TestCase { 00013 00014 private Location l; 00015 00016 @Before 00017 public void setUp() throws Exception { 00018 00019 00020 QueryLocationCommand cLoc = new QueryLocationCommand(); 00021 cLoc.setLocationName("TU Graz"); 00022 l = null; 00023 try { 00024 l = cLoc.execute(); 00025 } catch (ORException e1) { 00026 // TODO Auto-generated catch block 00027 e1.printStackTrace(); 00028 } 00029 } 00030 @Test 00031 public void testCorrectLogin() 00032 { 00033 00034 LoginCommand c = new LoginCommand(); 00035 c.setLocation(l); 00036 c.setUsername("susi"); 00037 c.setPassword("susi"); 00038 c.setMinutesTimout(10); 00039 Session s = null; 00040 00041 try{ 00042 s = c.execute(); 00043 }catch(ORException e){ 00044 assert(false); 00045 } 00046 00047 assertNotNull(s); 00048 } 00049 @Test 00050 public void testWrongPassword() 00051 { 00052 00053 LoginCommand c = new LoginCommand(); 00054 c.setLocation(l); 00055 c.setUsername("susi"); 00056 c.setPassword("susiiii"); 00057 c.setMinutesTimout(10); 00058 Session s = null; 00059 00060 try{ 00061 s = c.execute(); 00062 }catch(ORException e){ 00063 assertTrue(e.errorcode == Error.UsernamePwWrong.code()); 00064 } 00065 assertNull(s); 00066 } 00067 @Test 00068 public void testWrongUsername() 00069 { 00070 00071 LoginCommand c = new LoginCommand(); 00072 c.setLocation(l); 00073 c.setUsername("susssssi"); 00074 c.setPassword("susi"); 00075 c.setMinutesTimout(10); 00076 Session s = null; 00077 00078 try{ 00079 s = c.execute(); 00080 }catch(ORException e){ 00081 assertTrue(e.errorcode == Error.UsernamePwWrong.code()); 00082 } 00083 assertNull(s); 00084 } 00085 @Test 00086 public void testWrongLocation() 00087 { 00088 // noch nicht fertig 00089 00090 QueryLocationCommand cLoc = new QueryLocationCommand(); 00091 cLoc.setLocationName("Stadtarchiev Graz"); 00092 Location lerror = null; 00093 try { 00094 lerror = cLoc.execute(); 00095 } catch (ORException e1) { 00096 // TODO Auto-generated catch block 00097 e1.printStackTrace(); 00098 } 00099 00100 00101 LoginCommand c = new LoginCommand(); 00102 lerror.setName("wrong location"); 00103 c.setLocation(lerror); 00104 c.setUsername("susi"); 00105 c.setPassword("susi"); 00106 c.setMinutesTimout(10); 00107 Session s = null; 00108 00109 try{ 00110 s = c.execute(); 00111 }catch(ORException e){ 00112 assertTrue(e.errorcode == Error.LocationInvalid.code()); 00113 } 00114 assertNull(s); 00115 } 00116 00117 00118 00119 }