|
@ -1,7 +1,9 @@ |
|
|
package de.fd.fh.server.access.web; |
|
|
package de.fd.fh.server.access.web; |
|
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException; |
|
|
import de.fd.fh.server.access.AccessService; |
|
|
import de.fd.fh.server.access.AccessService; |
|
|
import de.fd.fh.server.access.AccessToken; |
|
|
import de.fd.fh.server.access.AccessToken; |
|
|
|
|
|
import de.fd.fh.shared.network.messages.LoginRequest; |
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
import org.junit.jupiter.api.Test; |
|
|
import org.junit.jupiter.api.Test; |
|
|
import org.mockito.ArgumentCaptor; |
|
|
import org.mockito.ArgumentCaptor; |
|
@ -109,4 +111,52 @@ class AccessControllerTest |
|
|
|
|
|
|
|
|
assertEquals(captor.getValue(), Integer.valueOf(400), "Should return Status code 400."); |
|
|
assertEquals(captor.getValue(), Integer.valueOf(400), "Should return Status code 400."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void loginTest() throws JsonProcessingException |
|
|
|
|
|
{ |
|
|
|
|
|
final LoginRequest dummy = new LoginRequest(); |
|
|
|
|
|
dummy.setName("TestName"); |
|
|
|
|
|
dummy.setToken("TestToken"); |
|
|
|
|
|
dummy.setUserId("12345"); |
|
|
|
|
|
|
|
|
|
|
|
when(request.headers(any())).thenReturn("testHeader"); |
|
|
|
|
|
when(service.authorization(any())).thenReturn(dummy); |
|
|
|
|
|
|
|
|
|
|
|
final ArgumentCaptor<Integer> statusCaptor = ArgumentCaptor.forClass(Integer.class); |
|
|
|
|
|
final ArgumentCaptor<String> typeCaptor = ArgumentCaptor.forClass(String.class); |
|
|
|
|
|
final ArgumentCaptor<String> bodyCaptor = ArgumentCaptor.forClass(String.class); |
|
|
|
|
|
|
|
|
|
|
|
new AccessController(service).login(request, response); |
|
|
|
|
|
|
|
|
|
|
|
verify(response).status(statusCaptor.capture()); |
|
|
|
|
|
verify(response).type(typeCaptor.capture()); |
|
|
|
|
|
verify(response).body(bodyCaptor.capture()); |
|
|
|
|
|
|
|
|
|
|
|
then(service).should().authorization(any()); |
|
|
|
|
|
then(service).shouldHaveNoMoreInteractions(); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals(Integer.valueOf(200), statusCaptor.getValue(), "Should return Status code 200."); |
|
|
|
|
|
assertEquals("application/json", typeCaptor.getValue(), "Should have return type json."); |
|
|
|
|
|
assertEquals("{\"name\":\"TestName\",\"userId\":\"12345\",\"token\":\"TestToken\"}", |
|
|
|
|
|
bodyCaptor.getValue(), "Should return correct Body."); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void failedLoginTest() throws JsonProcessingException |
|
|
|
|
|
{ |
|
|
|
|
|
when(request.headers(any())).thenReturn("testHeader"); |
|
|
|
|
|
when(service.authorization(any())).thenReturn(null); |
|
|
|
|
|
|
|
|
|
|
|
final ArgumentCaptor<Integer> statusCaptor = ArgumentCaptor.forClass(Integer.class); |
|
|
|
|
|
|
|
|
|
|
|
new AccessController(service).login(request, response); |
|
|
|
|
|
|
|
|
|
|
|
verify(response).status(statusCaptor.capture()); |
|
|
|
|
|
|
|
|
|
|
|
then(service).should().authorization(any()); |
|
|
|
|
|
then(service).shouldHaveNoMoreInteractions(); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals(Integer.valueOf(401), statusCaptor.getValue(), "Should return Status code 401."); |
|
|
|
|
|
} |
|
|
} |
|
|
} |