@Test public void testInstanceCreationWhenUnableToRefreshTokenThenCloudConnectorExceptionComes() { when(credentialView.getRefreshToken()).thenReturn(REFRESH_TOKEN); when(cbRefreshTokenClient.refreshToken(anyString(), anyString(), anyString(), anyString(), anyString(), anyBoolean())).thenReturn(null); thrown.expect(CloudConnectorException.class); thrown.expectMessage(String.format("New token couldn't be obtain with refresh token for credential: %s", CREDENTIAL_NAME)); new AzureClientCredentials(credentialView, LOG_LEVEL, cbRefreshTokenClientProvider, authenticationContextProvider, tracingInterceptor); verify(credentialView, times(1)).getTenantId(); verify(credentialView, times(1)).getAccessKey(); verify(credentialView, times(1)).getSecretKey(); verify(credentialView, times(1)).getAppReplyUrl(); verify(credentialView, times(1)).getRefreshToken(); verify(credentialView, times(2)).codeGrantFlow(); verify(credentialView, times(1)).getSubscriptionId(); verify(credentialView, times(1)).getAuthorizationCode(); verify(cbRefreshTokenClientProvider, times(1)).getCBRefreshTokenClient(anyString()); verify(cbRefreshTokenClient, times(0)).refreshToken(anyString(), anyString(), anyString(), anyString(), anyString(), anyBoolean()); verify(cbRefreshTokenClientProvider, times(1)).getCBRefreshTokenClient(eq(AzureEnvironment.AZURE.activeDirectoryEndpoint())); }
public Optional<String> getRefreshToken() { String refreshToken = null; Optional<Boolean> codeGrantFlow = Optional.ofNullable(credentialView.codeGrantFlow()); if (codeGrantFlow.orElse(Boolean.FALSE)) { CbDelegatedTokenCredentials delegatedCredentials = (CbDelegatedTokenCredentials) azureClientCredentials; Optional<AuthenticationResult> authenticationResult = delegatedCredentials.getTokens() .values() .stream() .findFirst(); if (authenticationResult.isPresent()) { refreshToken = authenticationResult.get().getRefreshToken(); } } return Optional.ofNullable(refreshToken); }
AzureClientCredentials { public Optional<String> getRefreshToken() { String refreshToken = null; Optional<Boolean> codeGrantFlow = Optional.ofNullable(credentialView.codeGrantFlow()); if (codeGrantFlow.orElse(Boolean.FALSE)) { CbDelegatedTokenCredentials delegatedCredentials = (CbDelegatedTokenCredentials) azureClientCredentials; Optional<AuthenticationResult> authenticationResult = delegatedCredentials.getTokens() .values() .stream() .findFirst(); if (authenticationResult.isPresent()) { refreshToken = authenticationResult.get().getRefreshToken(); } } return Optional.ofNullable(refreshToken); } }
AzureClientCredentials { public Optional<String> getRefreshToken() { String refreshToken = null; Optional<Boolean> codeGrantFlow = Optional.ofNullable(credentialView.codeGrantFlow()); if (codeGrantFlow.orElse(Boolean.FALSE)) { CbDelegatedTokenCredentials delegatedCredentials = (CbDelegatedTokenCredentials) azureClientCredentials; Optional<AuthenticationResult> authenticationResult = delegatedCredentials.getTokens() .values() .stream() .findFirst(); if (authenticationResult.isPresent()) { refreshToken = authenticationResult.get().getRefreshToken(); } } return Optional.ofNullable(refreshToken); } AzureClientCredentials(AzureCredentialView credentialView, LogLevel logLevel, CBRefreshTokenClientProvider cbRefreshTokenClientProvider,
            AuthenticationContextProvider authenticationContextProvider, AzureOkHttp3TracingInterceptor tracingInterceptor); }
AzureClientCredentials { public Optional<String> getRefreshToken() { String refreshToken = null; Optional<Boolean> codeGrantFlow = Optional.ofNullable(credentialView.codeGrantFlow()); if (codeGrantFlow.orElse(Boolean.FALSE)) { CbDelegatedTokenCredentials delegatedCredentials = (CbDelegatedTokenCredentials) azureClientCredentials; Optional<AuthenticationResult> authenticationResult = delegatedCredentials.getTokens() .values() .stream() .findFirst(); if (authenticationResult.isPresent()) { refreshToken = authenticationResult.get().getRefreshToken(); } } return Optional.ofNullable(refreshToken); } AzureClientCredentials(AzureCredentialView credentialView, LogLevel logLevel, CBRefreshTokenClientProvider cbRefreshTokenClientProvider,
            AuthenticationContextProvider authenticationContextProvider, AzureOkHttp3TracingInterceptor tracingInterceptor); Azure getAzure(); Optional<String> getRefreshToken(); }
AzureClientCredentials { public Optional<String> getRefreshToken() { String refreshToken = null; Optional<Boolean> codeGrantFlow = Optional.ofNullable(credentialView.codeGrantFlow()); if (codeGrantFlow.orElse(Boolean.FALSE)) { CbDelegatedTokenCredentials delegatedCredentials = (CbDelegatedTokenCredentials) azureClientCredentials; Optional<AuthenticationResult> authenticationResult = delegatedCredentials.getTokens() .values() .stream() .findFirst(); if (authenticationResult.isPresent()) { refreshToken = authenticationResult.get().getRefreshToken(); } } return Optional.ofNullable(refreshToken); } AzureClientCredentials(AzureCredentialView credentialView, LogLevel logLevel, CBRefreshTokenClientProvider cbRefreshTokenClientProvider,
            AuthenticationContextProvider authenticationContextProvider, AzureOkHttp3TracingInterceptor tracingInterceptor); Azure getAzure(); Optional<String> getRefreshToken();  }