Search in sources :

Example 1 with DeviceClientConfig

use of com.microsoft.azure.sdk.iot.device.DeviceClientConfig in project azure-iot-sdk-java by Azure.

the class DeviceClientConfigTest method constructorWithConnectionStringKeySucceed.

// Tests_SRS_DEVICECLIENTCONFIG_21_033: [The constructor shall save the IoT Hub hostname, hubname,
// device ID, device key, and device token, provided in the `iotHubConnectionString`.]
@Test
public void constructorWithConnectionStringKeySucceed() throws URISyntaxException {
    // arrange
    final String iotHubname = "iotHubName";
    final String iotHubHostname = iotHubname + ".iothubhostname";
    final String deviceId = "test-deviceid";
    final String deviceKey = "test-devicekey";
    final IotHubConnectionString iotHubConnectionString = Deencapsulation.newInstance(IotHubConnectionString.class, new Class[] { String.class }, "HostName=" + iotHubHostname + ";CredentialType=SharedAccessKey;CredentialScope=Device;" + "DeviceId=" + deviceId + ";SharedAccessKey=" + deviceKey + ";");
    // act
    DeviceClientConfig config = new DeviceClientConfig(iotHubConnectionString);
    // assert
    assertNotNull(config);
    IotHubConnectionString actualConnectionString = Deencapsulation.getField(config, "iotHubConnectionString");
    assertEquals(iotHubHostname, actualConnectionString.getHostName());
    assertEquals(iotHubname, actualConnectionString.getHubName());
    assertEquals(deviceId, actualConnectionString.getDeviceId());
    assertEquals(deviceKey, actualConnectionString.getSharedAccessKey());
}
Also used : DeviceClientConfig(com.microsoft.azure.sdk.iot.device.DeviceClientConfig) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) Test(org.junit.Test)

Example 2 with DeviceClientConfig

use of com.microsoft.azure.sdk.iot.device.DeviceClientConfig in project azure-iot-sdk-java by Azure.

the class DeviceClientConfigTest method getUserCertificateGets.

//Tests_SRS_DEVICECLIENTCONFIG_25_030: [**The function shall return the value of the user certificate string.**] **
@Test
public void getUserCertificateGets() throws URISyntaxException {
    final String iotHubHostname = "test.iothubhostname";
    final String deviceId = "test-deviceid";
    final String deviceKey = "test-devicekey";
    final String sharedAccessToken = null;
    final String cert = "ValidCertString";
    final IotHubConnectionString iotHubConnectionString = Deencapsulation.newInstance(IotHubConnectionString.class, new Class[] { String.class, String.class, String.class, String.class }, iotHubHostname, deviceId, deviceKey, sharedAccessToken);
    DeviceClientConfig config = new DeviceClientConfig(iotHubConnectionString);
    config.setUserCertificateString(cert);
    String testCert = config.getUserCertificateString();
    assertNotNull(cert);
    assertEquals(testCert, cert);
}
Also used : DeviceClientConfig(com.microsoft.azure.sdk.iot.device.DeviceClientConfig) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) Test(org.junit.Test)

Example 3 with DeviceClientConfig

use of com.microsoft.azure.sdk.iot.device.DeviceClientConfig in project azure-iot-sdk-java by Azure.

the class DeviceClientConfigTest method getMessageLockTimeoutSecsReturnsConstant.

// Tests_SRS_DEVICECLIENTCONFIG_11_013: [The function shall return 180s.]
@Test
public void getMessageLockTimeoutSecsReturnsConstant() throws URISyntaxException {
    final String iotHubHostname = "test.iothubhostname";
    final String deviceId = "test-deviceid";
    final String deviceKey = "test-devicekey";
    final String sharedAccessToken = null;
    final IotHubConnectionString iotHubConnectionString = Deencapsulation.newInstance(IotHubConnectionString.class, new Class[] { String.class, String.class, String.class, String.class }, iotHubHostname, deviceId, deviceKey, sharedAccessToken);
    DeviceClientConfig config = new DeviceClientConfig(iotHubConnectionString);
    int testMessageLockTimeoutSecs = config.getMessageLockTimeoutSecs();
    final int expectedMessageLockTimeoutSecs = 180;
    assertThat(testMessageLockTimeoutSecs, is(expectedMessageLockTimeoutSecs));
}
Also used : DeviceClientConfig(com.microsoft.azure.sdk.iot.device.DeviceClientConfig) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) Test(org.junit.Test)

Example 4 with DeviceClientConfig

use of com.microsoft.azure.sdk.iot.device.DeviceClientConfig in project azure-iot-sdk-java by Azure.

the class DeviceClientConfigTest method getIotHubHostnameReturnsIotHubHostname.

// Tests_SRS_DEVICECLIENTCONFIG_11_002: [The function shall return the IoT Hub hostname given in the constructor.]
@Test
public void getIotHubHostnameReturnsIotHubHostname() throws URISyntaxException {
    final String iotHubHostname = "test.iothubhostname";
    final String deviceId = "test-deviceid";
    final String deviceKey = "test-devicekey";
    final String sharedAccessToken = null;
    final IotHubConnectionString iotHubConnectionString = Deencapsulation.newInstance(IotHubConnectionString.class, new Class[] { String.class, String.class, String.class, String.class }, iotHubHostname, deviceId, deviceKey, sharedAccessToken);
    DeviceClientConfig config = new DeviceClientConfig(iotHubConnectionString);
    String testIotHubHostname = config.getIotHubHostname();
    final String expectedIotHubHostname = iotHubHostname;
    assertThat(testIotHubHostname, is(expectedIotHubHostname));
}
Also used : DeviceClientConfig(com.microsoft.azure.sdk.iot.device.DeviceClientConfig) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) Test(org.junit.Test)

Example 5 with DeviceClientConfig

use of com.microsoft.azure.sdk.iot.device.DeviceClientConfig in project azure-iot-sdk-java by Azure.

the class DeviceClientConfigTest method getReadTimeoutMillisReturnsConstant.

// Tests_SRS_DEVICECLIENTCONFIG_11_012: [The function shall return 240000ms.]
@Test
public void getReadTimeoutMillisReturnsConstant() throws URISyntaxException {
    final String iotHubHostname = "test.iothubhostname";
    final String deviceId = "test-deviceid";
    final String deviceKey = "test-devicekey";
    final String sharedAccessToken = null;
    final IotHubConnectionString iotHubConnectionString = Deencapsulation.newInstance(IotHubConnectionString.class, new Class[] { String.class, String.class, String.class, String.class }, iotHubHostname, deviceId, deviceKey, sharedAccessToken);
    DeviceClientConfig config = new DeviceClientConfig(iotHubConnectionString);
    int testReadTimeoutMillis = config.getReadTimeoutMillis();
    final int expectedReadTimeoutMillis = 240000;
    assertThat(testReadTimeoutMillis, is(expectedReadTimeoutMillis));
}
Also used : DeviceClientConfig(com.microsoft.azure.sdk.iot.device.DeviceClientConfig) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) Test(org.junit.Test)

Aggregations

DeviceClientConfig (com.microsoft.azure.sdk.iot.device.DeviceClientConfig)32 Test (org.junit.Test)32 IotHubConnectionString (com.microsoft.azure.sdk.iot.device.IotHubConnectionString)31 IotHubSasToken (com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken)9 NonStrictExpectations (mockit.NonStrictExpectations)3 IotHubSSLContext (com.microsoft.azure.sdk.iot.device.IotHubSSLContext)2 MessageCallback (com.microsoft.azure.sdk.iot.device.MessageCallback)1 State (com.microsoft.azure.sdk.iot.device.transport.State)1 AmqpsIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection)1 FlowController (org.apache.qpid.proton.reactor.FlowController)1 Handshaker (org.apache.qpid.proton.reactor.Handshaker)1