feature/implement-external-login-api #30
@@ -0,0 +1,50 @@
|
|||||||
|
package com.vaessl.app.connection;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.doThrow;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
|
import com.vaessl.app.dto.ConnectionRequest;
|
||||||
|
import com.vaessl.app.exception.EmptyCredentialsException;
|
||||||
|
|
||||||
|
import static com.vaessl.app.connection.Mockdata.*;
|
||||||
|
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
class ConnectionServiceTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ConnectionProvider mockProvider;
|
||||||
|
@Mock
|
||||||
|
private ConnectionRepository mockRepo;
|
||||||
|
|
||||||
|
private ConnectionService connectionService;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setup() {
|
||||||
|
when(mockProvider.getServiceType()).thenReturn(MOCK_SERVICE_TYPE);
|
||||||
|
connectionService = new ConnectionService(List.of(mockProvider), mockRepo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void login_ShouldAbort_WhenCheckCredentialsThrowsException() {
|
||||||
|
ConnectionRequest request = new ConnectionRequest(MOCK_URL, MOCK_SERVICE_TYPE, null, null, false);
|
||||||
|
|
||||||
|
doThrow(new EmptyCredentialsException(List.of("username")))
|
||||||
|
.when(mockProvider).checkCredentials(request);
|
||||||
|
|
||||||
|
assertThrows(EmptyCredentialsException.class, () -> connectionService.login(request));
|
||||||
|
|
||||||
|
verify(mockProvider, never()).authenticate(any());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.vaessl.app.connection;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import com.vaessl.app.dto.ConnectionRequest;
|
||||||
|
import com.vaessl.app.exception.EmptyCredentialsException;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static com.vaessl.app.connection.Mockdata.*;
|
||||||
|
|
||||||
|
class HomeBoxConnectionProviderTest {
|
||||||
|
|
||||||
|
private final HomeBoxConnectionProvider provider = new HomeBoxConnectionProvider(null, null);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void checkCredentials_ShouldThrowException_WhenFieldsAreMissing() {
|
||||||
|
ConnectionRequest request = new ConnectionRequest(MOCK_URL, "HOMEBOX", null, null, false);
|
||||||
|
|
||||||
|
EmptyCredentialsException exception = assertThrows(EmptyCredentialsException.class, () -> {
|
||||||
|
provider.checkCredentials(request);
|
||||||
|
});
|
||||||
|
|
||||||
|
assertThat(exception.getMissingFields()).containsExactly("username", "password");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.vaessl.app.connection;
|
||||||
|
|
||||||
|
public final class Mockdata {
|
||||||
|
|
||||||
|
private Mockdata() {}
|
||||||
|
|
||||||
|
public static final String MOCK_URL = "http://localhost:1234";
|
||||||
|
public static final String MOCK_SERVICE_TYPE = "SERVICE_TYPE";
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user