package test.scotlandyard;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.BeforeClass;
import org.junit.Test;
import scotlandyard.engine.impl.Engine;
import scotlandyard.servlets.beans.WebUserBean;
import scotlandyard.servlets.users.dologin;
import scotlandyard.servlets.web.reset_game_engine;
import web.JavascriptEval;
public class dologinTest {
private static String engine_status;
final String[][] users = {
{"Hussain","hussain"}
,{"Hussain","hussain"}
,{"Ali","hussain"}
,{"Ali","hussain"}
,{"Ali","ali"}
};
@BeforeClass
public static void beforeClass() throws Exception{
engine_status = new reset_game_engine().processRequest("-");
}
private String getUserLoginOutput(int i) throws Exception{
final String []user = users[i];
dologin servlogin = new dologin(user[0], user[1]);
return servlogin.processRequest("-");
}
@Test
public void testProcessRequest() throws Exception{
new WebUserBean();
assertTrue("4ac5200f096a9f402d21e861adc57b57".equals(Engine.md5("hussain.mutawa@gmail.com")));
assertEquals(
"test if the engine has been reset or not",
"the engine is reset now",
JavascriptEval.getJSONproperty(engine_status,"msg")
);
assertEquals(
"test if user [0] has logged in",
Engine.md5("hussain"),
JavascriptEval.getJSONproperty(getUserLoginOutput(0), "msg")
);
assertEquals(
"test if user [1] can not be logged in",
"EXCEPTION : Can not login: already in the users list",
JavascriptEval.getJSONproperty(getUserLoginOutput(1), "msg")
);
assertEquals(
"test if user [2] can not be logged in",
"EXCEPTION : Can not login: already in the users list",
JavascriptEval.getJSONproperty(getUserLoginOutput(2), "msg")
);
assertEquals(
"test if user [3] can not be logged in",
"EXCEPTION : Can not login: already in the users list",
JavascriptEval.getJSONproperty(getUserLoginOutput(3), "msg")
);
assertEquals(
"test if user [4] can be logged in",
Engine.md5("ali"),
JavascriptEval.getJSONproperty(getUserLoginOutput(4), "msg")
);
assertEquals(
"test the number of online users should be :",
2,
Engine.instance().users.size()
);
}
}