Compare commits
2 commits
14b12634f8
...
e3b18ace64
Author | SHA1 | Date | |
---|---|---|---|
e3b18ace64 | |||
ebabcf4d2c |
7 changed files with 255 additions and 20 deletions
|
@ -1 +1,126 @@
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ 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;
|
||||||
|
|
||||||
|
@ -21,7 +22,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+"\n";
|
while((line = reader.readLine()) != null) schem+=line;
|
||||||
reader.close();
|
reader.close();
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -37,15 +38,26 @@ 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{
|
||||||
this.con.prepareStatement(schem).execute();
|
String[] split = schem.split(";");
|
||||||
|
for(String statment : split){
|
||||||
|
this.con.prepareStatement(statment).execute();
|
||||||
|
}
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,11 @@ public class BaseUserStoriesTest {
|
||||||
|
|
||||||
public BaseUserStoriesTest(){}
|
public BaseUserStoriesTest(){}
|
||||||
|
|
||||||
public void init(){
|
public void init() throws Exception{
|
||||||
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(){
|
||||||
|
|
79
test/be/jeffcheasey88/peeratcode/userstories/LoginTests.java
Normal file
79
test/be/jeffcheasey88/peeratcode/userstories/LoginTests.java
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
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,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;
|
||||||
|
@ -16,7 +17,9 @@ public class RegisterTests extends BaseUserStoriesTest{
|
||||||
private WebClient client;
|
private WebClient client;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void init(){
|
public void init() throws Exception{
|
||||||
|
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||||
|
|
||||||
super.init();
|
super.init();
|
||||||
getRepository().init();
|
getRepository().init();
|
||||||
getRepository().reset();
|
getRepository().reset();
|
||||||
|
@ -38,6 +41,7 @@ public class RegisterTests extends BaseUserStoriesTest{
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void stop(){
|
public void stop(){
|
||||||
server.interrupt();
|
server.interrupt();
|
||||||
|
getRepository().close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -47,27 +51,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