Compare commits
No commits in common. "e3b18ace64ddcbf53b35a96bcdcca078119403b1" and "14b12634f8adc17572835fe16c811c813bd0af15" have entirely different histories.
e3b18ace64
...
14b12634f8
7 changed files with 20 additions and 255 deletions
|
@ -1,126 +1 @@
|
||||||
DROP TABLE IF EXISTS `containsTags`;
|
|
||||||
DROP TABLE IF EXISTS `tags`;
|
|
||||||
DROP TABLE IF EXISTS `containsBadges`;
|
|
||||||
DROP TABLE IF EXISTS `badges`;
|
|
||||||
DROP TABLE IF EXISTS `containsGroups`;
|
|
||||||
DROP TABLE IF EXISTS `nextPart`;
|
|
||||||
DROP TABLE IF EXISTS `groups`;
|
|
||||||
DROP TABLE IF EXISTS `completions`;
|
|
||||||
DROP TABLE IF EXISTS `players`;
|
|
||||||
DROP TABLE IF EXISTS `puzzles`;
|
|
||||||
DROP TABLE IF EXISTS `chapters`;
|
|
||||||
|
|
||||||
CREATE TABLE `players` (
|
|
||||||
`id_player` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`pseudo` varchar(100) NOT NULL,
|
|
||||||
`email` varchar(100) NOT NULL,
|
|
||||||
`passwd` varchar(150) NOT NULL,
|
|
||||||
`firstname` varchar(100) NOT NULL,
|
|
||||||
`lastname` varchar(100) NOT NULL,
|
|
||||||
`description` varchar(200) DEFAULT NULL,
|
|
||||||
`avatar` blob DEFAULT NULL,
|
|
||||||
PRIMARY KEY (`id_player`)
|
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
||||||
|
|
||||||
CREATE TABLE badges (
|
|
||||||
id_badge int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
name varchar(50) NOT NULL,
|
|
||||||
logo mediumblob DEFAULT NULL,
|
|
||||||
level int(11) DEFAULT 1,
|
|
||||||
PRIMARY KEY (id_badge)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE `chapters` (
|
|
||||||
`id_chapter` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`name` varchar(150) NOT NULL,
|
|
||||||
`start_date` datetime DEFAULT NULL,
|
|
||||||
`end_date` datetime DEFAULT NULL,
|
|
||||||
PRIMARY KEY (`id_chapter`)
|
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
||||||
|
|
||||||
CREATE TABLE `puzzles` (
|
|
||||||
`id_puzzle` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`name` varchar(150) NOT NULL,
|
|
||||||
`content` text NOT NULL,
|
|
||||||
`soluce` blob NOT NULL,
|
|
||||||
`verify` text DEFAULT NULL,
|
|
||||||
`score_max` int(11) NOT NULL,
|
|
||||||
`fk_chapter` int(11) NOT NULL,
|
|
||||||
PRIMARY KEY (`id_puzzle`),
|
|
||||||
KEY `fk_chapter` (`fk_chapter`),
|
|
||||||
CONSTRAINT `puzzles_ibfk_1` FOREIGN KEY (`fk_chapter`) REFERENCES `chapters` (`id_chapter`)
|
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=49 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE `groups` (
|
|
||||||
`id_group` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`name` varchar(150) DEFAULT NULL,
|
|
||||||
`fk_chapter` int(11) DEFAULT NULL,
|
|
||||||
`fk_puzzle` int(11) DEFAULT NULL,
|
|
||||||
PRIMARY KEY (`id_group`),
|
|
||||||
KEY `fk_chapter` (`fk_chapter`),
|
|
||||||
KEY `fk_puzzle` (`fk_puzzle`),
|
|
||||||
CONSTRAINT `groups_ibfk_1` FOREIGN KEY (`fk_chapter`) REFERENCES `chapters` (`id_chapter`),
|
|
||||||
CONSTRAINT `groups_ibfk_2` FOREIGN KEY (`fk_puzzle`) REFERENCES `puzzles` (`id_puzzle`)
|
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE `nextPart` (
|
|
||||||
`origin` int(11) NOT NULL,
|
|
||||||
`next` int(11) NOT NULL,
|
|
||||||
PRIMARY KEY (`origin`,`next`),
|
|
||||||
KEY `next` (`next`),
|
|
||||||
CONSTRAINT `nextPart_ibfk_1` FOREIGN KEY (`origin`) REFERENCES `puzzles` (`id_puzzle`),
|
|
||||||
CONSTRAINT `nextPart_ibfk_2` FOREIGN KEY (`next`) REFERENCES `puzzles` (`id_puzzle`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE `completions` (
|
|
||||||
`id_completion` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`fk_puzzle` int(11) NOT NULL,
|
|
||||||
`fk_player` int(11) NOT NULL,
|
|
||||||
`tries` int(11) DEFAULT 0,
|
|
||||||
`code` blob DEFAULT NULL,
|
|
||||||
`score` int(11) DEFAULT 0,
|
|
||||||
`fileName` varchar(100) DEFAULT NULL,
|
|
||||||
PRIMARY KEY (`id_completion`),
|
|
||||||
KEY `fk_puzzle` (`fk_puzzle`),
|
|
||||||
KEY `fk_player` (`fk_player`),
|
|
||||||
CONSTRAINT `completions_ibfk_1` FOREIGN KEY (`fk_puzzle`) REFERENCES `puzzles` (`id_puzzle`),
|
|
||||||
CONSTRAINT `completions_ibfk_2` FOREIGN KEY (`fk_player`) REFERENCES `players` (`id_player`)
|
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
||||||
|
|
||||||
CREATE TABLE `tags` (
|
|
||||||
`id_tag` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`name` varchar(50) NOT NULL,
|
|
||||||
PRIMARY KEY (`id_tag`)
|
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
||||||
|
|
||||||
CREATE TABLE `containsBadges` (
|
|
||||||
`fk_player` int(11) NOT NULL,
|
|
||||||
`fk_badge` int(11) NOT NULL,
|
|
||||||
PRIMARY KEY (`fk_player`,`fk_badge`),
|
|
||||||
KEY `fk_badge` (`fk_badge`),
|
|
||||||
CONSTRAINT `containsBadges_ibfk_1` FOREIGN KEY (`fk_player`) REFERENCES `players` (`id_player`),
|
|
||||||
CONSTRAINT `containsBadges_ibfk_2` FOREIGN KEY (`fk_badge`) REFERENCES `badges` (`id_badge`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
||||||
|
|
||||||
CREATE TABLE `containsGroups` (
|
|
||||||
`fk_player` int(11) NOT NULL,
|
|
||||||
`fk_group` int(11) NOT NULL,
|
|
||||||
PRIMARY KEY (`fk_player`,`fk_group`),
|
|
||||||
KEY `fk_group` (`fk_group`),
|
|
||||||
CONSTRAINT `containsGroups_ibfk_1` FOREIGN KEY (`fk_player`) REFERENCES `players` (`id_player`),
|
|
||||||
CONSTRAINT `containsGroups_ibfk_2` FOREIGN KEY (`fk_group`) REFERENCES `groups` (`id_group`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
||||||
|
|
||||||
CREATE TABLE `containsTags` (
|
|
||||||
`fk_tag` int(11) NOT NULL,
|
|
||||||
`fk_puzzle` int(11) NOT NULL,
|
|
||||||
PRIMARY KEY (`fk_tag`,`fk_puzzle`),
|
|
||||||
KEY `fk_puzzle` (`fk_puzzle`),
|
|
||||||
CONSTRAINT `containsTags_ibfk_1` FOREIGN KEY (`fk_tag`) REFERENCES `tags` (`id_tag`),
|
|
||||||
CONSTRAINT `containsTags_ibfk_2` FOREIGN KEY (`fk_puzzle`) REFERENCES `puzzles` (`id_puzzle`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import java.util.Set;
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
public class Player implements Comparable<Player>{
|
public class Player implements Comparable<Player> {
|
||||||
private String pseudo;
|
private String pseudo;
|
||||||
private String email;
|
private String email;
|
||||||
private String firstname;
|
private String firstname;
|
||||||
|
@ -184,8 +184,8 @@ public class Player implements Comparable<Player>{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode(){
|
public int hashCode() {
|
||||||
return Objects.hash(email);
|
return Objects.hash(email, pseudo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@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);
|
return Objects.equals(email, other.email) && Objects.equals(pseudo, other.pseudo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class DatabaseRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensureConnection() throws SQLException {
|
private void ensureConnection() throws SQLException {
|
||||||
if (con == null || (!con.isValid(5))){
|
if (con == null || (!con.isValid(5))) {
|
||||||
this.con = DriverManager.getConnection(
|
this.con = DriverManager.getConnection(
|
||||||
"jdbc:mysql://" + config.getDbHost() + ":" + config.getDbPort() + "/" + config.getDbDatabase() + "",
|
"jdbc:mysql://" + config.getDbHost() + ":" + config.getDbPort() + "/" + config.getDbDatabase() + "",
|
||||||
config.getDbUser(), config.getDbPassword());
|
config.getDbUser(), config.getDbPassword());
|
||||||
|
|
|
@ -6,7 +6,6 @@ import java.io.FileReader;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import be.jeffcheasey88.peeratcode.repository.DatabaseRepository;
|
import be.jeffcheasey88.peeratcode.repository.DatabaseRepository;
|
||||||
|
|
||||||
|
@ -22,7 +21,7 @@ public class TestDatabaseRepository extends DatabaseRepository{
|
||||||
schem = "";
|
schem = "";
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(databaseSchem));
|
BufferedReader reader = new BufferedReader(new FileReader(databaseSchem));
|
||||||
String line;
|
String line;
|
||||||
while((line = reader.readLine()) != null) schem+=line;
|
while((line = reader.readLine()) != null) schem+=line+"\n";
|
||||||
reader.close();
|
reader.close();
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -38,26 +37,15 @@ public class TestDatabaseRepository extends DatabaseRepository{
|
||||||
Field field = DatabaseRepository.class.getDeclaredField("con");
|
Field field = DatabaseRepository.class.getDeclaredField("con");
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
this.con = (Connection) field.get(this);
|
this.con = (Connection) field.get(this);
|
||||||
System.out.println("connected !");
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.getCause().printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close(){
|
|
||||||
try {
|
|
||||||
this.con.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
System.out.println(e.getCause());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset(){
|
public void reset(){
|
||||||
try{
|
try{
|
||||||
String[] split = schem.split(";");
|
this.con.prepareStatement(schem).execute();
|
||||||
for(String statment : split){
|
|
||||||
this.con.prepareStatement(statment).execute();
|
|
||||||
}
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,11 +12,9 @@ public class BaseUserStoriesTest {
|
||||||
|
|
||||||
public BaseUserStoriesTest(){}
|
public BaseUserStoriesTest(){}
|
||||||
|
|
||||||
public void init() throws Exception{
|
public void init(){
|
||||||
this.config = new Configuration("config-test.txt");
|
this.config = new Configuration("config-test.txt");
|
||||||
this.repo = new TestDatabaseRepository(config, new File("database-schem.sql"));
|
this.repo = new TestDatabaseRepository(config, new File("database-schem.sql"));
|
||||||
|
|
||||||
this.config.load();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Configuration getConfig(){
|
public Configuration getConfig(){
|
||||||
|
|
|
@ -1,79 +0,0 @@
|
||||||
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() throws Exception{
|
|
||||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
|
||||||
|
|
||||||
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,6 +1,5 @@
|
||||||
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;
|
||||||
|
@ -17,9 +16,7 @@ public class RegisterTests extends BaseUserStoriesTest{
|
||||||
private WebClient client;
|
private WebClient client;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void init() throws Exception{
|
public void init(){
|
||||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
|
||||||
|
|
||||||
super.init();
|
super.init();
|
||||||
getRepository().init();
|
getRepository().init();
|
||||||
getRepository().reset();
|
getRepository().reset();
|
||||||
|
@ -41,7 +38,6 @@ public class RegisterTests extends BaseUserStoriesTest{
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void stop(){
|
public void stop(){
|
||||||
server.interrupt();
|
server.interrupt();
|
||||||
getRepository().close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -51,40 +47,27 @@ public class RegisterTests extends BaseUserStoriesTest{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pseudoAlreadyUse() throws Exception{
|
public void pseudoAlreadyUse(){
|
||||||
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() throws Exception{
|
public void emailAlreadyUse(){
|
||||||
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() throws Exception{
|
public void emptyField(){
|
||||||
client.register("","","",",","","");
|
|
||||||
client.assertResponseCode(400);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void lostField() throws Exception{
|
public void lostField(){
|
||||||
client.route("/register", "POST", new JSONObject().toJSONString());
|
|
||||||
client.assertResponseCode(400);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void alreadyLoggedin() throws Exception{
|
public void alreadyLoggedin(){
|
||||||
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