@Test @Disabled("Fails from time to time non-deterministically") void testGetTokenFailure() { Assertions .assertThatExceptionOfType(GenieClientException.class) .isThrownBy( () -> { final TokenFetcher tokenFetcher = new TokenFetcher(URL, CLIENT_ID, CLIENT_SECRET, GRANT_TYPE, SCOPE); tokenFetcher.getToken(); } ) .satisfies(e -> Assertions.assertThat(e.getErrorCode()).isEqualTo(-1)); }
public AccessToken getToken() throws GenieClientException { try { if (Instant.now().isAfter(this.expirationTime)) { final Response<AccessToken> response = tokenService.getToken(oauthUrl, credentialParams).execute(); if (response.isSuccessful()) { this.accessToken = response.body(); this.expirationTime = Instant .now() .plus(this.accessToken.getExpiresIn() - 300, ChronoUnit.SECONDS); return this.accessToken; } else { throw new GenieClientException(response.code(), "Could not fetch Token"); } } else { return this.accessToken; } } catch (final Exception e) { throw new GenieClientException("Could not get access tokens" + e); } }
TokenFetcher { public AccessToken getToken() throws GenieClientException { try { if (Instant.now().isAfter(this.expirationTime)) { final Response<AccessToken> response = tokenService.getToken(oauthUrl, credentialParams).execute(); if (response.isSuccessful()) { this.accessToken = response.body(); this.expirationTime = Instant .now() .plus(this.accessToken.getExpiresIn() - 300, ChronoUnit.SECONDS); return this.accessToken; } else { throw new GenieClientException(response.code(), "Could not fetch Token"); } } else { return this.accessToken; } } catch (final Exception e) { throw new GenieClientException("Could not get access tokens" + e); } } }
TokenFetcher { public AccessToken getToken() throws GenieClientException { try { if (Instant.now().isAfter(this.expirationTime)) { final Response<AccessToken> response = tokenService.getToken(oauthUrl, credentialParams).execute(); if (response.isSuccessful()) { this.accessToken = response.body(); this.expirationTime = Instant .now() .plus(this.accessToken.getExpiresIn() - 300, ChronoUnit.SECONDS); return this.accessToken; } else { throw new GenieClientException(response.code(), "Could not fetch Token"); } } else { return this.accessToken; } } catch (final Exception e) { throw new GenieClientException("Could not get access tokens" + e); } } TokenFetcher(
        final String oauthUrl,
        final String clientId,
        final String clientSecret,
        final String grantType,
        final String scope
    ); }
TokenFetcher { public AccessToken getToken() throws GenieClientException { try { if (Instant.now().isAfter(this.expirationTime)) { final Response<AccessToken> response = tokenService.getToken(oauthUrl, credentialParams).execute(); if (response.isSuccessful()) { this.accessToken = response.body(); this.expirationTime = Instant .now() .plus(this.accessToken.getExpiresIn() - 300, ChronoUnit.SECONDS); return this.accessToken; } else { throw new GenieClientException(response.code(), "Could not fetch Token"); } } else { return this.accessToken; } } catch (final Exception e) { throw new GenieClientException("Could not get access tokens" + e); } } TokenFetcher(
        final String oauthUrl,
        final String clientId,
        final String clientSecret,
        final String grantType,
        final String scope
    ); AccessToken getToken(); }
TokenFetcher { public AccessToken getToken() throws GenieClientException { try { if (Instant.now().isAfter(this.expirationTime)) { final Response<AccessToken> response = tokenService.getToken(oauthUrl, credentialParams).execute(); if (response.isSuccessful()) { this.accessToken = response.body(); this.expirationTime = Instant .now() .plus(this.accessToken.getExpiresIn() - 300, ChronoUnit.SECONDS); return this.accessToken; } else { throw new GenieClientException(response.code(), "Could not fetch Token"); } } else { return this.accessToken; } } catch (final Exception e) { throw new GenieClientException("Could not get access tokens" + e); } } TokenFetcher(
        final String oauthUrl,
        final String clientId,
        final String clientSecret,
        final String grantType,
        final String scope
    ); AccessToken getToken();  }