|
|
@ -1,6 +1,9 @@ |
|
|
|
package de.fd.fh.server.user.web; |
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException; |
|
|
|
import de.fd.fh.server.access.AccessToken; |
|
|
|
import de.fd.fh.server.user.User; |
|
|
|
import de.fd.fh.server.user.UserId; |
|
|
|
import de.fd.fh.server.user.UserService; |
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
@ -24,6 +27,8 @@ class UserControllerTest |
|
|
|
@Mock |
|
|
|
Response response; |
|
|
|
@Mock |
|
|
|
Session session; |
|
|
|
@Mock |
|
|
|
UserService service; |
|
|
|
|
|
|
|
@BeforeEach |
|
|
@ -67,4 +72,52 @@ class UserControllerTest |
|
|
|
then(service).should().getSmallPlayer(any()); |
|
|
|
then(service).shouldHaveNoMoreInteractions(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void getCompleteUserTest() throws JsonProcessingException |
|
|
|
{ |
|
|
|
when(request.session()).thenReturn(session); |
|
|
|
when(session.attribute(any())).thenReturn( |
|
|
|
new AccessToken(null, null, null, UserId.of("12345"))); |
|
|
|
when(service.getPlayer(any(UserId.class))).thenReturn(User.of("TestName")); |
|
|
|
|
|
|
|
final ArgumentCaptor<Integer> statusCapture = ArgumentCaptor.forClass(Integer.class); |
|
|
|
final ArgumentCaptor<String> bodyCapture = ArgumentCaptor.forClass(String.class); |
|
|
|
final ArgumentCaptor<String> typeCapture = ArgumentCaptor.forClass(String.class); |
|
|
|
|
|
|
|
final Response result = new UserController(service).getCompleteUser(request, response); |
|
|
|
|
|
|
|
verify(response).status(statusCapture.capture()); |
|
|
|
verify(response).type(typeCapture.capture()); |
|
|
|
verify(response).body(bodyCapture.capture()); |
|
|
|
|
|
|
|
assertEquals(response, result, "Should return the incoming Response"); |
|
|
|
assertEquals(Integer.valueOf(200), statusCapture.getValue(), "Should return status code 200."); |
|
|
|
assertEquals("application/json", typeCapture.getValue(), "Should have content type json."); |
|
|
|
assertEquals("{\"id\":null,\"name\":\"TestName\"}", bodyCapture.getValue(), "Should return user as json."); |
|
|
|
|
|
|
|
then(service).should().getPlayer(any()); |
|
|
|
then(service).shouldHaveNoMoreInteractions(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void failedGetCompleteUserTest() throws JsonProcessingException |
|
|
|
{ |
|
|
|
when(request.session()).thenReturn(session); |
|
|
|
when(session.attribute(any())).thenReturn( |
|
|
|
new AccessToken(null, null, null, UserId.of("12345"))); |
|
|
|
when(service.getPlayer(any(UserId.class))).thenReturn(null); |
|
|
|
|
|
|
|
final ArgumentCaptor<Integer> capture = ArgumentCaptor.forClass(Integer.class); |
|
|
|
|
|
|
|
final Response result = new UserController(service).getCompleteUser(request, response); |
|
|
|
|
|
|
|
verify(response).status(capture.capture()); |
|
|
|
|
|
|
|
assertEquals(response, result, "Should return the incoming Response"); |
|
|
|
assertEquals(Integer.valueOf(404), capture.getValue(), "Should return status code 200."); |
|
|
|
then(service).should().getPlayer(any()); |
|
|
|
then(service).shouldHaveNoMoreInteractions(); |
|
|
|
} |
|
|
|
|
|
|
|
} |