Browse Source

extract logout method

chore-betterServerTestCoverage
Steffen Nitschke 4 years ago
parent
commit
e1a3c96810
  1. 20
      fh.fd.ci.server/src/main/java/de/fd/fh/server/access/web/AccessController.java
  2. 36
      fh.fd.ci.server/src/test/java/de/fd/fh/server/access/web/AccessControllerTest.java

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

@ -33,6 +33,23 @@ public class AccessController
return response;
}
public Object logout(Request request, Response response)
{
final String token = request.headers(Utils.AUTHENTICATION_HEADER);
if (service.logout(token))
{
response.status(200);
}
else
{
response.status(400);
}
return response;
}
public AccessController(final AccessService service)
{
this.service = service;
@ -86,7 +103,8 @@ public class AccessController
return response;
});
post("/accounts/logout", this::deletePlayer);
post("/accounts/logout",this::logout);
delete("/accounts/:player_id", this::deletePlayer);
}
}

36
fh.fd.ci.server/src/test/java/de/fd/fh/server/access/web/AccessControllerTest.java

@ -73,4 +73,40 @@ class AccessControllerTest
assertEquals(captor.getValue(), Integer.valueOf(400), "Should return Status code 400.");
}
@Test
void testLogout()
{
when(request.headers(any())).thenReturn("testHeader");
when(service.logout(any())).thenReturn(true);
final ArgumentCaptor<Integer> captor = ArgumentCaptor.forClass(Integer.class);
new AccessController(service).logout(request, response);
verify(response).status(captor.capture());
then(service).should().logout(any());
then(service).shouldHaveNoMoreInteractions();
assertEquals(captor.getValue(), Integer.valueOf(200), "Should return Status code 200.");
}
@Test
void failedLogoutTest()
{
when(request.headers(any())).thenReturn("testHeader");
when(service.logout(any())).thenReturn(false);
final ArgumentCaptor<Integer> captor = ArgumentCaptor.forClass(Integer.class);
new AccessController(service).logout(request, response);
verify(response).status(captor.capture());
then(service).should().logout(any());
then(service).shouldHaveNoMoreInteractions();
assertEquals(captor.getValue(), Integer.valueOf(400), "Should return Status code 400.");
}
}
Loading…
Cancel
Save