Compare commits
3 commits
7dee5b60f9
...
14e37b9e38
Author | SHA1 | Date | |
---|---|---|---|
|
14e37b9e38 | ||
|
5609822241 | ||
|
5f7573f0cd |
6 changed files with 71 additions and 8 deletions
|
@ -3,8 +3,6 @@ package be.jeffcheasey88.peeratcode.model;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
|
|
@ -493,8 +493,8 @@ public class DatabaseRepository {
|
|||
ensureConnection();
|
||||
PreparedStatement statement = DatabaseQuery.INSERT_GROUP.prepare(this.con);
|
||||
statement.setString(1, group.getName());
|
||||
statement.setInt(2, group.getLinkToChapter());
|
||||
statement.setInt(3, group.getLinkToPuzzle());
|
||||
statement.setObject(2, group.getLinkToChapter());
|
||||
statement.setObject(3, group.getLinkToPuzzle());
|
||||
if(statement.executeUpdate() >= 0) return insertUserInGroup(group, creator);
|
||||
} catch (Exception e){}
|
||||
return false;
|
||||
|
|
|
@ -25,8 +25,7 @@ public class GroupJoin implements Response{
|
|||
|
||||
@Route(path = "^\\/groupJoin$", type = POST, needLogin = true)
|
||||
public void exec(Matcher matcher, User user, HttpReader reader, HttpWriter writer) throws Exception {
|
||||
HttpUtil.responseHeaders(writer, 200, "Access-Control-Allow-Origin: *");
|
||||
|
||||
HttpUtil.skipHeaders(reader);
|
||||
if (this.repo.insertUserInGroup(new Group((JSONObject) HttpUtil.readJson(reader)), user)) {
|
||||
HttpUtil.responseHeaders(writer, 200, "Access-Control-Allow-Origin: *");
|
||||
} else {
|
||||
|
|
|
@ -25,7 +25,7 @@ public class GroupQuit implements Response{
|
|||
|
||||
@Route(path = "^\\/groupQuit$", type = POST, needLogin = true)
|
||||
public void exec(Matcher matcher, User user, HttpReader reader, HttpWriter writer) throws Exception {
|
||||
HttpUtil.responseHeaders(writer, 200, "Access-Control-Allow-Origin: *");
|
||||
HttpUtil.skipHeaders(reader);
|
||||
|
||||
if (this.repo.leaveGroup(new Group((JSONObject) HttpUtil.readJson(reader)), user)) {
|
||||
HttpUtil.responseHeaders(writer, 200, "Access-Control-Allow-Origin: *");
|
||||
|
|
64
test/be/jeffcheasey88/peeratcode/routes/TmpRoutesTests.java
Normal file
64
test/be/jeffcheasey88/peeratcode/routes/TmpRoutesTests.java
Normal file
|
@ -0,0 +1,64 @@
|
|||
package be.jeffcheasey88.peeratcode.routes;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
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.WebClient;
|
||||
|
||||
@TestInstance(Lifecycle.PER_CLASS)
|
||||
public class TmpRoutesTests {
|
||||
|
||||
private Thread server;
|
||||
private WebClient client;
|
||||
|
||||
@BeforeAll
|
||||
void init(){
|
||||
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);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
void close(){
|
||||
server.interrupt();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testOnDeployed(){
|
||||
try {
|
||||
JSONObject content = new JSONObject();
|
||||
content.put("name", "testTeam1");
|
||||
content.put("chapter", 2);
|
||||
|
||||
client.auth("JeffCheasey88", "TheoPueDesPieds");
|
||||
|
||||
client.route("/groupCreate", "POST", content.toJSONString());
|
||||
client.assertResponseCode(200);
|
||||
|
||||
client.route("/groupJoin","POST",content.toJSONString());
|
||||
client.assertResponseCode(200);
|
||||
|
||||
client.route("/groupQuit", "POST", content.toJSONString());
|
||||
client.assertResponseCode(200);
|
||||
}catch(Exception e){
|
||||
fail(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -50,14 +50,16 @@ public class WebClient {
|
|||
login.put("pseudo", user);
|
||||
login.put("passwd", password);
|
||||
route("/login", "POST", login.toJSONString());
|
||||
System.out.println("["+host+"] /login "+login);
|
||||
|
||||
for(String line : this.headers){
|
||||
Matcher matcher = AUTORIZATION.matcher(line);
|
||||
if(matcher.matches()){
|
||||
this.token = matcher.group(1);
|
||||
System.out.println(token);
|
||||
System.out.println(host+": "+token);
|
||||
break;
|
||||
}
|
||||
System.out.println("["+host+"] "+line);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue