From 52b23adea26dde49f6b8b9deec9359b0c9157004 Mon Sep 17 00:00:00 2001 From: Steffen Nitschke Date: Sun, 31 Jan 2021 03:48:35 +0100 Subject: [PATCH] extract registrate routing to ServerApp --- .../src/main/java/de/fd/fh/ServerApp.java | 1 + .../server/access/web/AccessController.java | 2 -- .../src/test/java/de/fd/fh/ServerAppTest.java | 19 +++++++++++++++++++ 3 files changed, 20 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 1c87d4d..04d9fb6 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 @@ -41,6 +41,7 @@ public class ServerApp } before("/*", (req, res) -> accessController.before(req)); + post("/accounts/registrate", accessController::registrate); 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 390730f..de3f26f 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/registrate", this::registrate); - post("/accounts/login", this::login); post("/accounts/logout",this::logout); 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 e5fdb7e..82a1cc1 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 @@ -8,11 +8,15 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import java.io.IOException; import java.util.HashMap; import java.util.Map; import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import static spark.Spark.awaitInitialization; import static spark.Spark.stop; @@ -50,4 +54,19 @@ class ServerAppTest assertEquals(200, res.getStatus()); assertEquals("Hello World", res.getBody()); } + + @Test + void testRegistrate() throws IOException + { + when(accessController.registrate(any(), any())).thenReturn("Test"); + + String url = "/accounts/registrate"; + + ApiTestUtils.TestResponse res = new ApiTestUtils() + .request("POST", url, null, null, String.class); + + assertNotNull(res); + assertEquals(200, res.getStatus()); + then(accessController).should().registrate(any(), any()); + } } \ No newline at end of file