From 5f7573f0cdfb1401269128a3d0d9b97b1a96dbdd Mon Sep 17 00:00:00 2001 From: jeffcheasey88 <66554203+jeffcheasey88@users.noreply.github.com> Date: Mon, 10 Apr 2023 14:52:42 +0200 Subject: [PATCH] tmpTest --- .../jeffcheasey88/peeratcode/model/Group.java | 2 - .../peeratcode/routes/TmpRoutesTests.java | 55 +++++++++++++++++++ .../peeratcode/webclient/WebClient.java | 4 +- 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 test/be/jeffcheasey88/peeratcode/routes/TmpRoutesTests.java diff --git a/src/be/jeffcheasey88/peeratcode/model/Group.java b/src/be/jeffcheasey88/peeratcode/model/Group.java index 74a7c7b..c46df4f 100644 --- a/src/be/jeffcheasey88/peeratcode/model/Group.java +++ b/src/be/jeffcheasey88/peeratcode/model/Group.java @@ -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; diff --git a/test/be/jeffcheasey88/peeratcode/routes/TmpRoutesTests.java b/test/be/jeffcheasey88/peeratcode/routes/TmpRoutesTests.java new file mode 100644 index 0000000..2b5bad9 --- /dev/null +++ b/test/be/jeffcheasey88/peeratcode/routes/TmpRoutesTests.java @@ -0,0 +1,55 @@ +package be.jeffcheasey88.peeratcode.routes; + +import static org.junit.jupiter.api.Assertions.fail; + +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 { + WebClient deploy = new WebClient("api.peerat.dev", 80); + + deploy.auth("JeffCheasey88", "TheoPueDesPieds"); + deploy.route("/player/","GET"); + + deploy.assertResponseCode(200); + }catch(Exception e){ + fail(e); + } + } + +} diff --git a/test/be/jeffcheasey88/peeratcode/webclient/WebClient.java b/test/be/jeffcheasey88/peeratcode/webclient/WebClient.java index b85dc0a..0455b41 100644 --- a/test/be/jeffcheasey88/peeratcode/webclient/WebClient.java +++ b/test/be/jeffcheasey88/peeratcode/webclient/WebClient.java @@ -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); } }