peer-at-code-backend/test/be/jeffcheasey88/peeratcode/routes/TmpRoutesTests.java
jeffcheasey88 14e37b9e38 Fix groups
2023-04-10 17:00:57 +02:00

64 lines
1.4 KiB
Java

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);
}
}
}