use of com.github.robozonky.api.remote.entities.ZonkyApiToken in project robozonky by RoboZonky.
the class ZonkyApiTokenSupplierTest method fixesExpiredToken.
@Test
void fixesExpiredToken() {
final OAuth oAuth = mock(OAuth.class);
when(oAuth.login(eq(SECRETS.getUsername()), eq(SECRETS.getPassword()))).thenAnswer(invocation -> getStaleToken());
final ApiProvider api = mockApi(oAuth);
final Supplier<Optional<ZonkyApiToken>> t = new ZonkyApiTokenSupplier(api, SECRETS, Duration.ZERO);
final Optional<ZonkyApiToken> token = t.get();
assertThat(token).isPresent();
final Optional<ZonkyApiToken> token2 = t.get();
assertThat(token2).isPresent();
assertThat(token2).isNotEqualTo(token);
}
use of com.github.robozonky.api.remote.entities.ZonkyApiToken in project robozonky by RoboZonky.
the class ZonkyApiTokenSupplierTest method refreshFailUnknown.
@Test
void refreshFailUnknown() {
final OAuth oAuth = mock(OAuth.class);
when(oAuth.login(eq(SECRETS.getUsername()), eq(SECRETS.getPassword()))).thenAnswer(invocation -> getTokenExpiringIn(Duration.ofSeconds(5)));
when(oAuth.refresh(any())).thenThrow(IllegalStateException.class);
final ApiProvider api = mockApi(oAuth);
final Supplier<Optional<ZonkyApiToken>> t = new ZonkyApiTokenSupplier(api, SECRETS, Duration.ZERO);
final Optional<ZonkyApiToken> token = t.get();
assertThat(token).isPresent();
final Optional<ZonkyApiToken> token2 = t.get();
assertThat(token2).isEmpty();
}
use of com.github.robozonky.api.remote.entities.ZonkyApiToken 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();
}
use of com.github.robozonky.api.remote.entities.ZonkyApiToken in project robozonky by RoboZonky.
the class OAuthTest method refresh.
@Test
void refresh() {
final String originalTokenId = UUID.randomUUID().toString();
final ZonkyApiToken originToken = new ZonkyApiToken(UUID.randomUUID().toString(), originalTokenId, OffsetDateTime.now());
final ZonkyApiToken resultToken = mock(ZonkyApiToken.class);
final ZonkyOAuthApi api = mock(ZonkyOAuthApi.class);
when(api.refresh(eq(originalTokenId), anyString(), anyString())).thenReturn(resultToken);
final Api<ZonkyOAuthApi> wrapper = new Api<>(api);
final OAuth oauth = new OAuth(wrapper);
final ZonkyApiToken returnedToken = oauth.refresh(originToken);
assertThat(returnedToken).isEqualTo(resultToken);
}
Aggregations