From 2624e63baa4bbdecbeebd5bbd92f65516ef0af30 Mon Sep 17 00:00:00 2001 From: Steffen Nitschke Date: Sun, 31 Jan 2021 03:50:18 +0100 Subject: [PATCH] extract login routing to ServerApp --- .../src/main/java/de/fd/fh/ServerApp.java | 1 + .../fh/server/access/web/AccessController.java | 2 -- .../src/test/java/de/fd/fh/ServerAppTest.java | 16 ++++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/fh.fd.ci.server/src/main/java/de/fd/fh/ServerApp.java b/fh.fd.ci.server/src/main/java/de/fd/fh/ServerApp.java index 04d9fb6..dbef579 100644 --- a/fh.fd.ci.server/src/main/java/de/fd/fh/ServerApp.java +++ b/fh.fd.ci.server/src/main/java/de/fd/fh/ServerApp.java @@ -42,6 +42,7 @@ public class ServerApp before("/*", (req, res) -> accessController.before(req)); post("/accounts/registrate", accessController::registrate); + post("/accounts/login", accessController::login); get("/hello", (req, res) -> "Hello World"); diff --git a/fh.fd.ci.server/src/main/java/de/fd/fh/server/access/web/AccessController.java b/fh.fd.ci.server/src/main/java/de/fd/fh/server/access/web/AccessController.java index de3f26f..ab504ac 100644 --- a/fh.fd.ci.server/src/main/java/de/fd/fh/server/access/web/AccessController.java +++ b/fh.fd.ci.server/src/main/java/de/fd/fh/server/access/web/AccessController.java @@ -102,8 +102,6 @@ public class AccessController { this.service = service; - post("/accounts/login", this::login); - post("/accounts/logout",this::logout); delete("/accounts/:player_id", this::deletePlayer); diff --git a/fh.fd.ci.server/src/test/java/de/fd/fh/ServerAppTest.java b/fh.fd.ci.server/src/test/java/de/fd/fh/ServerAppTest.java index 82a1cc1..0efea84 100644 --- a/fh.fd.ci.server/src/test/java/de/fd/fh/ServerAppTest.java +++ b/fh.fd.ci.server/src/test/java/de/fd/fh/ServerAppTest.java @@ -1,5 +1,6 @@ package de.fd.fh; +import com.fasterxml.jackson.core.JsonProcessingException; import de.fd.fh.server.ApiTestUtils; import de.fd.fh.server.access.web.AccessController; import de.fd.fh.server.user.web.UserController; @@ -69,4 +70,19 @@ class ServerAppTest assertEquals(200, res.getStatus()); then(accessController).should().registrate(any(), any()); } + + @Test + void testLogin() throws JsonProcessingException + { + when(accessController.login(any(), any())).thenReturn("Test"); + + String url = "/accounts/login"; + + ApiTestUtils.TestResponse res = new ApiTestUtils() + .request("POST", url, null, null, String.class); + + assertNotNull(res); + assertEquals(200, res.getStatus()); + then(accessController).should().login(any(), any()); + } } \ No newline at end of file