Login Test + refractor hashcode & equals for players
This commit is contained in:
parent
14b12634f8
commit
ebabcf4d2c
3 changed files with 105 additions and 14 deletions
|
@ -185,7 +185,7 @@ public class Player implements Comparable<Player> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode(){
|
public int hashCode(){
|
||||||
return Objects.hash(email, pseudo);
|
return Objects.hash(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -197,6 +197,6 @@ public class Player implements Comparable<Player> {
|
||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
Player other = (Player) obj;
|
Player other = (Player) obj;
|
||||||
return Objects.equals(email, other.email) && Objects.equals(pseudo, other.pseudo);
|
return Objects.equals(email, other.email);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
77
test/be/jeffcheasey88/peeratcode/userstories/LoginTests.java
Normal file
77
test/be/jeffcheasey88/peeratcode/userstories/LoginTests.java
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
package be.jeffcheasey88.peeratcode.userstories;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.TestInstance;
|
||||||
|
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
||||||
|
|
||||||
|
import be.jeffcheasey88.peeratcode.Main;
|
||||||
|
import be.jeffcheasey88.peeratcode.WebClient;
|
||||||
|
|
||||||
|
@TestInstance(Lifecycle.PER_METHOD)
|
||||||
|
public class LoginTests extends BaseUserStoriesTest{
|
||||||
|
|
||||||
|
private Thread server;
|
||||||
|
private WebClient client;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void init(){
|
||||||
|
super.init();
|
||||||
|
getRepository().init();
|
||||||
|
getRepository().reset();
|
||||||
|
|
||||||
|
server = new Thread(new Runnable(){
|
||||||
|
@Override
|
||||||
|
public void run(){
|
||||||
|
try {
|
||||||
|
Main.main(null);
|
||||||
|
} catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
server.start();
|
||||||
|
client = new WebClient("localhost", 80);
|
||||||
|
|
||||||
|
try {
|
||||||
|
client.register("user", "password", "mail@peerat.dev", "firstname", "lastname", "description");
|
||||||
|
client.assertResponseCode(200);
|
||||||
|
client.disconnect();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void stop(){
|
||||||
|
server.interrupt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void normalLogin() throws Exception{
|
||||||
|
client.auth("user", "password");
|
||||||
|
client.assertResponseCode(200);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void wrongPassword() throws Exception{
|
||||||
|
client.auth("user", "password1");
|
||||||
|
client.assertResponseCode(400);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void wrongUsername() throws Exception{
|
||||||
|
client.auth("user1", "password");
|
||||||
|
client.assertResponseCode(400);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void alreadyLoggedin() throws Exception{
|
||||||
|
client.auth("user", "password");
|
||||||
|
client.assertResponseCode(200);
|
||||||
|
client.auth("user", "password");
|
||||||
|
client.assertResponseCode(403);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package be.jeffcheasey88.peeratcode.userstories;
|
package be.jeffcheasey88.peeratcode.userstories;
|
||||||
|
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -47,27 +48,40 @@ public class RegisterTests extends BaseUserStoriesTest{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pseudoAlreadyUse(){
|
public void pseudoAlreadyUse() throws Exception{
|
||||||
|
client.register("test", "test", "test@peerat.dev", "te", "st", "my desc");
|
||||||
|
client.assertResponseCode(200);
|
||||||
|
client.disconnect();
|
||||||
|
client.register("test", "test", "test1@peerat.dev", "te", "st", "my desc");
|
||||||
|
client.assertResponseCode(400);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emailAlreadyUse(){
|
public void emailAlreadyUse() throws Exception{
|
||||||
|
client.register("test", "test", "test@peerat.dev", "te", "st", "my desc");
|
||||||
|
client.assertResponseCode(200);
|
||||||
|
client.disconnect();
|
||||||
|
client.register("test1", "test", "test@peerat.dev", "te", "st", "my desc");
|
||||||
|
client.assertResponseCode(400);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyField(){
|
public void emptyField() throws Exception{
|
||||||
|
client.register("","","",",","","");
|
||||||
|
client.assertResponseCode(400);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void lostField(){
|
public void lostField() throws Exception{
|
||||||
|
client.route("/register", "POST", new JSONObject().toJSONString());
|
||||||
|
client.assertResponseCode(400);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void alreadyLoggedin(){
|
public void alreadyLoggedin() throws Exception{
|
||||||
|
client.register("test", "test", "test@peerat.dev", "te", "st", "my desc");
|
||||||
|
client.assertResponseCode(200);
|
||||||
|
client.register("test1", "test", "test@peerat.dev", "te", "st", "my desc");
|
||||||
|
client.assertResponseCode(403);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue