Search in sources :

Example 1 with DigitalTwinClientOptions

use of com.microsoft.azure.sdk.iot.service.digitaltwin.DigitalTwinClientOptions in project azure-iot-sdk-java by Azure.

the class Tools method buildDigitalTwinClientWithTokenCredential.

public static DigitalTwinClient buildDigitalTwinClientWithTokenCredential() {
    IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(iotHubConnectionString);
    TokenCredential tokenCredential = buildTokenCredentialFromEnvironment();
    DigitalTwinClientOptions options = DigitalTwinClientOptions.builder().build();
    return new DigitalTwinClient(iotHubConnectionStringObj.getHostName(), tokenCredential, options);
}
Also used : DigitalTwinClientOptions(com.microsoft.azure.sdk.iot.service.digitaltwin.DigitalTwinClientOptions) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) TokenCredential(com.azure.core.credential.TokenCredential) DigitalTwinClient(com.microsoft.azure.sdk.iot.service.digitaltwin.DigitalTwinClient)

Example 2 with DigitalTwinClientOptions

use of com.microsoft.azure.sdk.iot.service.digitaltwin.DigitalTwinClientOptions in project azure-iot-sdk-java by Azure.

the class DigitalTwinClientTests method digitalTwinConstructorThrowsForNegativeConnectTimeout.

@Test(expected = IllegalArgumentException.class)
@StandardTierHubOnlyTest
public void digitalTwinConstructorThrowsForNegativeConnectTimeout() {
    // arrange
    DigitalTwinClientOptions clientOptions = DigitalTwinClientOptions.builder().httpConnectTimeout(-1).build();
    digitalTwinClient = new DigitalTwinClient(IOTHUB_CONNECTION_STRING, clientOptions);
}
Also used : DigitalTwinClientOptions(com.microsoft.azure.sdk.iot.service.digitaltwin.DigitalTwinClientOptions) DigitalTwinClient(com.microsoft.azure.sdk.iot.service.digitaltwin.DigitalTwinClient) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) DigitalTwinTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.DigitalTwinTest) IntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) Test(org.junit.Test)

Example 3 with DigitalTwinClientOptions

use of com.microsoft.azure.sdk.iot.service.digitaltwin.DigitalTwinClientOptions in project azure-iot-sdk-java by Azure.

the class DigitalTwinClientTests method digitalTwinConstructorThrowsForNegativeReadTimeout.

@Test(expected = IllegalArgumentException.class)
@StandardTierHubOnlyTest
public void digitalTwinConstructorThrowsForNegativeReadTimeout() {
    // arrange
    DigitalTwinClientOptions clientOptions = DigitalTwinClientOptions.builder().httpReadTimeout(-1).build();
    digitalTwinClient = new DigitalTwinClient(IOTHUB_CONNECTION_STRING, clientOptions);
}
Also used : DigitalTwinClientOptions(com.microsoft.azure.sdk.iot.service.digitaltwin.DigitalTwinClientOptions) DigitalTwinClient(com.microsoft.azure.sdk.iot.service.digitaltwin.DigitalTwinClient) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) DigitalTwinTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.DigitalTwinTest) IntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) Test(org.junit.Test)

Example 4 with DigitalTwinClientOptions

use of com.microsoft.azure.sdk.iot.service.digitaltwin.DigitalTwinClientOptions in project azure-iot-sdk-java by Azure.

the class DigitalTwinClientTests method getDigitalTwinWithProxy.

@Test
@StandardTierHubOnlyTest
public void getDigitalTwinWithProxy() {
    // arrange
    Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(testProxyHostname, testProxyPort));
    ProxyOptions proxyOptions = new ProxyOptions(proxy);
    DigitalTwinClientOptions clientOptions = DigitalTwinClientOptions.builder().proxyOptions(proxyOptions).httpReadTimeout(0).build();
    digitalTwinClient = new DigitalTwinClient(IOTHUB_CONNECTION_STRING, clientOptions);
    // act
    BasicDigitalTwin response = digitalTwinClient.getDigitalTwin(deviceId, BasicDigitalTwin.class);
    ServiceResponseWithHeaders<BasicDigitalTwin, DigitalTwinGetHeaders> responseWithHeaders = digitalTwinClient.getDigitalTwinWithResponse(deviceId, BasicDigitalTwin.class);
    // assert
    assertEquals(response.getMetadata().getModelId(), E2ETestConstants.THERMOSTAT_MODEL_ID);
    assertEquals(responseWithHeaders.body().getMetadata().getModelId(), E2ETestConstants.THERMOSTAT_MODEL_ID);
}
Also used : Proxy(java.net.Proxy) ProxyOptions(com.microsoft.azure.sdk.iot.service.ProxyOptions) BasicDigitalTwin(com.microsoft.azure.sdk.iot.service.digitaltwin.serialization.BasicDigitalTwin) InetSocketAddress(java.net.InetSocketAddress) DigitalTwinClientOptions(com.microsoft.azure.sdk.iot.service.digitaltwin.DigitalTwinClientOptions) DigitalTwinGetHeaders(com.microsoft.azure.sdk.iot.service.digitaltwin.customized.DigitalTwinGetHeaders) DigitalTwinClient(com.microsoft.azure.sdk.iot.service.digitaltwin.DigitalTwinClient) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) DigitalTwinTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.DigitalTwinTest) IntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) Test(org.junit.Test)

Example 5 with DigitalTwinClientOptions

use of com.microsoft.azure.sdk.iot.service.digitaltwin.DigitalTwinClientOptions in project azure-iot-sdk-java by Azure.

the class DigitalTwinClientTests method buildDigitalTwinClientWithAzureSasCredential.

private static DigitalTwinClient buildDigitalTwinClientWithAzureSasCredential() {
    IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(IOTHUB_CONNECTION_STRING);
    IotHubServiceSasToken serviceSasToken = new IotHubServiceSasToken(iotHubConnectionStringObj);
    AzureSasCredential azureSasCredential = new AzureSasCredential(serviceSasToken.toString());
    DigitalTwinClientOptions options = DigitalTwinClientOptions.builder().httpReadTimeout(HTTP_READ_TIMEOUT).build();
    return new DigitalTwinClient(iotHubConnectionStringObj.getHostName(), azureSasCredential, options);
}
Also used : IotHubServiceSasToken(com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken) AzureSasCredential(com.azure.core.credential.AzureSasCredential) DigitalTwinClientOptions(com.microsoft.azure.sdk.iot.service.digitaltwin.DigitalTwinClientOptions) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) DigitalTwinClient(com.microsoft.azure.sdk.iot.service.digitaltwin.DigitalTwinClient)

Aggregations

DigitalTwinClient (com.microsoft.azure.sdk.iot.service.digitaltwin.DigitalTwinClient)5 DigitalTwinClientOptions (com.microsoft.azure.sdk.iot.service.digitaltwin.DigitalTwinClientOptions)5 Test (org.junit.Test)3 IntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest)3 DigitalTwinTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.DigitalTwinTest)3 StandardTierHubOnlyTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest)3 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)2 AzureSasCredential (com.azure.core.credential.AzureSasCredential)1 TokenCredential (com.azure.core.credential.TokenCredential)1 ProxyOptions (com.microsoft.azure.sdk.iot.service.ProxyOptions)1 IotHubServiceSasToken (com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken)1 DigitalTwinGetHeaders (com.microsoft.azure.sdk.iot.service.digitaltwin.customized.DigitalTwinGetHeaders)1 BasicDigitalTwin (com.microsoft.azure.sdk.iot.service.digitaltwin.serialization.BasicDigitalTwin)1 InetSocketAddress (java.net.InetSocketAddress)1 Proxy (java.net.Proxy)1