use of org.openhab.core.auth.client.oauth2.OAuthFactory in project openhab-addons by openhab.
the class OAuthAuthorizationHandlerImplTest method setUp.
@BeforeEach
public void setUp() {
OAuthClientService clientService = mock(OAuthClientService.class);
OAuthFactory oauthFactory = mock(OAuthFactory.class);
when(oauthFactory.createOAuthClientService(anyString(), anyString(), anyString(), anyString(), anyString(), isNull(), any())).thenReturn(clientService);
ScheduledFuture<?> timer = mock(ScheduledFuture.class);
when(timer.isDone()).thenReturn(false);
ScheduledExecutorService scheduler = mock(ScheduledExecutorService.class);
when(scheduler.schedule(ArgumentMatchers.<Runnable>any(), anyLong(), any())).thenAnswer(invocation -> {
scheduledRunnable = invocation.getArgument(0);
return timer;
});
OAuthAuthorizationHandler authorizationHandler = new OAuthAuthorizationHandlerImpl(oauthFactory, scheduler);
this.clientService = clientService;
this.timer = timer;
this.scheduledRunnable = null;
this.authorizationHandler = authorizationHandler;
}
use of org.openhab.core.auth.client.oauth2.OAuthFactory in project openhab-addons by openhab.
the class MieleBridgeHandlerTest method setUpOAuthFactory.
private void setUpOAuthFactory() throws Exception {
AccessTokenResponse accessTokenResponse = new AccessTokenResponse();
accessTokenResponse.setAccessToken(ACCESS_TOKEN);
oauthClientServiceMock = mock(OAuthClientService.class);
when(oauthClientServiceMock.getAccessTokenResponse()).thenReturn(accessTokenResponse);
OAuthFactory oAuthFactory = mock(OAuthFactory.class);
Mockito.when(oAuthFactory.getOAuthClientService(SERVICE_HANDLE)).thenReturn(getOAuthClientServiceMock());
oauthFactoryMock = oAuthFactory;
OpenHabOAuthTokenRefresher tokenRefresher = getService(OAuthTokenRefresher.class, OpenHabOAuthTokenRefresher.class);
assertNotNull(tokenRefresher);
setPrivate(Objects.requireNonNull(tokenRefresher), "oauthFactory", oAuthFactory);
}
use of org.openhab.core.auth.client.oauth2.OAuthFactory in project openhab-addons by openhab.
the class AbstractMieleThingHandlerTest method setUpBridge.
private void setUpBridge() throws Exception {
AccessTokenResponse accessTokenResponse = new AccessTokenResponse();
accessTokenResponse.setAccessToken(ACCESS_TOKEN);
OAuthClientService oAuthClientService = mock(OAuthClientService.class);
when(oAuthClientService.getAccessTokenResponse()).thenReturn(accessTokenResponse);
OAuthFactory oAuthFactory = mock(OAuthFactory.class);
when(oAuthFactory.getOAuthClientService(MieleCloudBindingIntegrationTestConstants.BRIDGE_THING_UID.getAsString())).thenReturn(oAuthClientService);
OpenHabOAuthTokenRefresher tokenRefresher = getService(OAuthTokenRefresher.class, OpenHabOAuthTokenRefresher.class);
assertNotNull(tokenRefresher);
setPrivate(Objects.requireNonNull(tokenRefresher), "oauthFactory", oAuthFactory);
bridge = BridgeBuilder.create(MieleCloudBindingConstants.THING_TYPE_BRIDGE, MieleCloudBindingIntegrationTestConstants.BRIDGE_THING_UID).withLabel("Miele@home Account").withConfiguration(new Configuration(Collections.singletonMap(MieleCloudBindingConstants.CONFIG_PARAM_EMAIL, MieleCloudBindingIntegrationTestConstants.EMAIL))).build();
assertNotNull(bridge);
getThingRegistry().add(getBridge());
// then:
waitForAssert(() -> {
assertNotNull(getBridge().getHandler());
assertTrue(getBridge().getHandler() instanceof MieleBridgeHandler, "Handler type is wrong");
});
MieleBridgeHandler bridgeHandler = (MieleBridgeHandler) getBridge().getHandler();
assertNotNull(bridgeHandler);
waitForAssert(() -> {
assertNotNull(bridgeHandler.getThing());
});
bridgeHandler.initialize();
bridgeHandler.onConnectionAlive();
setPrivate(bridgeHandler, "discoveryService", null);
this.bridgeHandler = bridgeHandler;
}
Aggregations