Browse Source

extract delete player routing to ServerApp

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

2
fh.fd.ci.server/src/main/java/de/fd/fh/ServerApp.java

@ -44,6 +44,8 @@ public class ServerApp
post("/accounts/registrate", accessController::registrate);
post("/accounts/login", accessController::login);
post("/accounts/logout", accessController::logout);
delete("/accounts/:player_id", accessController::deletePlayer);
get("/hello", (req, res) -> "Hello World");

12
fh.fd.ci.server/src/main/java/de/fd/fh/server/access/web/AccessController.java

@ -8,12 +8,11 @@ import de.fd.fh.server.user.UserId;
import de.fd.fh.shared.Utils;
import de.fd.fh.shared.network.messages.LoginRequest;
import de.fd.fh.shared.network.messages.RegistrateRequest;
import lombok.RequiredArgsConstructor;
import spark.Request;
import spark.Response;
import spark.Spark;
import static spark.Spark.*;
@RequiredArgsConstructor
public class AccessController
{
private final ObjectMapper objectMapper = new ObjectMapper();
@ -97,11 +96,4 @@ public class AccessController
req.session().attribute("userId",
accessToken);
}
public AccessController(final AccessService service)
{
this.service = service;
delete("/accounts/:player_id", this::deletePlayer);
}
}

18
fh.fd.ci.server/src/test/java/de/fd/fh/ServerAppTest.java

@ -8,6 +8,7 @@ import de.fd.fh.shared.Utils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import spark.Response;
import java.io.IOException;
import java.util.HashMap;
@ -100,4 +101,21 @@ class ServerAppTest
assertEquals(200, res.getStatus());
then(accessController).should().logout(any(), any());
}
@Test
void testDeletePlayer()
{
final Response response = mock(Response.class);
when(accessController.deletePlayer(any(), any())).thenReturn(response);
String url = "/accounts/12345";
ApiTestUtils.TestResponse<String> res = new ApiTestUtils<String>()
.request("DELETE", url, null, null, String.class);
assertNotNull(res);
assertEquals(200, res.getStatus());
then(accessController).should().deletePlayer(any(), any());
}
}
Loading…
Cancel
Save