RefreshOAuthAccessTokenAction extends AbstractAction { public void actionPerformed(ActionEvent event) { try { getOAuthClientFacade().refreshAccessToken(profile); } catch (InvalidOAuthParametersException e) { UISupport.showErrorMessage(messages.get("RefreshOAuthAccessTokenAction.Error.InvalidParameters", e.getMessage())); } catch (Exception e) { SoapUI.logError(e, messages.get("RefreshOAuthAccessTokenAction.Error.RefreshingFailLog")); UISupport.showErrorMessage(messages.get("RefreshOAuthAccessTokenAction.Error.RefreshingFailMessage")); } } RefreshOAuthAccessTokenAction(OAuth2Profile profile); void actionPerformed(ActionEvent event);  }
@Test public void savesAccessTokenInProfile() throws Exception { final String accessToken = "4/98789adfc8234278243987"; doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocationOnMock) throws Throwable { profile.setAccessToken(accessToken); return null; } }).when(clientFacade).refreshAccessToken(profile); action.actionPerformed(DUMMY_ACTION_EVENT); assertThat(profile.getAccessToken(), is(accessToken)); }
@Test public void showsAnErrorMessageWhenGetAccessTokenFails() throws Exception { Mockito.doThrow(new OAuth2Exception(new RuntimeException())).when(clientFacade).refreshAccessToken(profile); action.actionPerformed(DUMMY_ACTION_EVENT); assertThat(stubbedDialogs.getErrorMessages(), is(aCollectionWithSize(1))); }
@Test public void displaysValidationErrorWhenValidationFails() throws Exception { String theMessage = "Client ID is empty"; Mockito.doThrow(new InvalidOAuthParametersException(theMessage)).when(clientFacade).refreshAccessToken(profile); action.actionPerformed(DUMMY_ACTION_EVENT); assertThat(stubbedDialogs.getErrorMessages(), is(aCollectionWithSize(1))); assertThat(stubbedDialogs.getErrorMessages().get(0), containsString(theMessage)); }