Search in sources :

Example 11 with OAuth

use of com.github.robozonky.common.remote.OAuth in project robozonky by RoboZonky.

the class ZonkySettingsValidatorTest method properLogin.

@Test
void properLogin() {
    // mock data
    final ZonkyApiToken token = mock(ZonkyApiToken.class);
    final OAuth oauth = mock(OAuth.class);
    when(oauth.login(any(), any())).thenReturn(token);
    final Zonky zonky = mock(Zonky.class);
    final ApiProvider provider = mockApiProvider(oauth, token, zonky);
    // execute SUT
    final ZonkySettingsValidator validator = new ZonkySettingsValidator(() -> provider);
    final InstallData d = ZonkySettingsValidatorTest.mockInstallData();
    final DataValidator.Status result = validator.validateData(d);
    // test
    assertThat(result).isEqualTo(DataValidator.Status.OK);
    verify(oauth).login(eq(ZonkySettingsValidatorTest.USERNAME), eq(ZonkySettingsValidatorTest.PASSWORD.toCharArray()));
    verify(zonky).logout();
}
Also used : InstallData(com.izforge.izpack.api.data.InstallData) DataValidator(com.izforge.izpack.api.installer.DataValidator) ApiProvider(com.github.robozonky.common.remote.ApiProvider) ZonkyApiToken(com.github.robozonky.api.remote.entities.ZonkyApiToken) OAuth(com.github.robozonky.common.remote.OAuth) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test)

Example 12 with OAuth

use of com.github.robozonky.common.remote.OAuth in project robozonky by RoboZonky.

the class ZonkySettingsValidatorTest method error.

@Test
void error() {
    // mock data
    final OAuth oauth = mock(OAuth.class);
    when(oauth.login(any(), any())).thenThrow(new ServerErrorException(Response.Status.INTERNAL_SERVER_ERROR));
    final ApiProvider provider = mockApiProvider(oauth);
    final InstallData d = ZonkySettingsValidatorTest.mockInstallData();
    // execute SUT
    final ZonkySettingsValidator validator = new ZonkySettingsValidator(() -> provider);
    final DataValidator.Status result = validator.validateData(d);
    // test
    assertThat(result).isEqualTo(DataValidator.Status.ERROR);
}
Also used : InstallData(com.izforge.izpack.api.data.InstallData) DataValidator(com.izforge.izpack.api.installer.DataValidator) ApiProvider(com.github.robozonky.common.remote.ApiProvider) ServerErrorException(javax.ws.rs.ServerErrorException) OAuth(com.github.robozonky.common.remote.OAuth) Test(org.junit.jupiter.api.Test)

Aggregations

ApiProvider (com.github.robozonky.common.remote.ApiProvider)12 OAuth (com.github.robozonky.common.remote.OAuth)12 Test (org.junit.jupiter.api.Test)11 ZonkyApiToken (com.github.robozonky.api.remote.entities.ZonkyApiToken)9 Optional (java.util.Optional)5 Zonky (com.github.robozonky.common.remote.Zonky)4 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)3 SecretProvider (com.github.robozonky.common.secrets.SecretProvider)3 InstallData (com.izforge.izpack.api.data.InstallData)3 DataValidator (com.izforge.izpack.api.installer.DataValidator)3 Collection (java.util.Collection)3 RawInvestment (com.github.robozonky.api.remote.entities.RawInvestment)2 ServerErrorException (javax.ws.rs.ServerErrorException)1