Browse Source

extract registrate routing to ServerApp

chore-betterServerTestCoverage
Steffen Nitschke 4 years ago
parent
commit
52b23adea2
  1. 1
      fh.fd.ci.server/src/main/java/de/fd/fh/ServerApp.java
  2. 2
      fh.fd.ci.server/src/main/java/de/fd/fh/server/access/web/AccessController.java
  3. 19
      fh.fd.ci.server/src/test/java/de/fd/fh/ServerAppTest.java

1
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)); before("/*", (req, res) -> accessController.before(req));
post("/accounts/registrate", accessController::registrate);
get("/hello", (req, res) -> "Hello World"); get("/hello", (req, res) -> "Hello World");

2
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; this.service = service;
post("/accounts/registrate", this::registrate);
post("/accounts/login", this::login); post("/accounts/login", this::login);
post("/accounts/logout",this::logout); post("/accounts/logout",this::logout);

19
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.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static org.junit.jupiter.api.Assertions.*; 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.mock;
import static org.mockito.Mockito.when;
import static spark.Spark.awaitInitialization; import static spark.Spark.awaitInitialization;
import static spark.Spark.stop; import static spark.Spark.stop;
@ -50,4 +54,19 @@ class ServerAppTest
assertEquals(200, res.getStatus()); assertEquals(200, res.getStatus());
assertEquals("Hello World", res.getBody()); assertEquals("Hello World", res.getBody());
} }
@Test
void testRegistrate() throws IOException
{
when(accessController.registrate(any(), any())).thenReturn("Test");
String url = "/accounts/registrate";
ApiTestUtils.TestResponse<String> res = new ApiTestUtils<String>()
.request("POST", url, null, null, String.class);
assertNotNull(res);
assertEquals(200, res.getStatus());
then(accessController).should().registrate(any(), any());
}
} }
Loading…
Cancel
Save