Search in sources :

Example 16 with OAuthFactory

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;
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) OAuthClientService(org.openhab.core.auth.client.oauth2.OAuthClientService) OAuthFactory(org.openhab.core.auth.client.oauth2.OAuthFactory) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 17 with OAuthFactory

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);
}
Also used : OAuthClientService(org.openhab.core.auth.client.oauth2.OAuthClientService) OAuthFactory(org.openhab.core.auth.client.oauth2.OAuthFactory) OpenHabOAuthTokenRefresher(org.openhab.binding.mielecloud.internal.auth.OpenHabOAuthTokenRefresher) AccessTokenResponse(org.openhab.core.auth.client.oauth2.AccessTokenResponse)

Example 18 with 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;
}
Also used : Configuration(org.openhab.core.config.core.Configuration) OAuthClientService(org.openhab.core.auth.client.oauth2.OAuthClientService) OAuthFactory(org.openhab.core.auth.client.oauth2.OAuthFactory) OpenHabOAuthTokenRefresher(org.openhab.binding.mielecloud.internal.auth.OpenHabOAuthTokenRefresher) AccessTokenResponse(org.openhab.core.auth.client.oauth2.AccessTokenResponse)

Aggregations

OAuthFactory (org.openhab.core.auth.client.oauth2.OAuthFactory)18 OAuthClientService (org.openhab.core.auth.client.oauth2.OAuthClientService)14 Test (org.junit.jupiter.api.Test)13 OpenHabOAuthTokenRefresher (org.openhab.binding.mielecloud.internal.auth.OpenHabOAuthTokenRefresher)5 AccessTokenResponse (org.openhab.core.auth.client.oauth2.AccessTokenResponse)5 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Nullable (org.eclipse.jdt.annotation.Nullable)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 OpenHabOsgiTest (org.openhab.binding.mielecloud.internal.util.OpenHabOsgiTest)2 IOException (java.io.IOException)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 HttpClient (org.eclipse.jetty.client.HttpClient)1 InnogyWebSocket (org.openhab.binding.innogysmarthome.internal.InnogyWebSocket)1 OAuthResponseException (org.openhab.core.auth.client.oauth2.OAuthResponseException)1 Configuration (org.openhab.core.config.core.Configuration)1 Bridge (org.openhab.core.thing.Bridge)1 ThingRegistry (org.openhab.core.thing.ThingRegistry)1 ThingUID (org.openhab.core.thing.ThingUID)1