Search in sources :

Example 21 with IotHubConnectionString

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

the class DeviceClientConfigTest method getAndSetDeviceMethodMessageCallbackAndContextsMatch.

/*
    **Tests_SRS_DEVICECLIENTCONFIG_25_022: [**The function shall return the current DeviceMethod message context.**] **
    **Tests_SRS_DEVICECLIENTCONFIG_25_023: [**The function shall set the DeviceTwin message callback.**] **
    **Tests_SRS_DEVICECLIENTCONFIG_25_021: [**The function shall return the current DeviceMethod message callback.**] **
    **Tests_SRS_DEVICECLIENTCONFIG_25_022: [**The function shall return the current DeviceMethod message context.**] **
     */
@Test
public void getAndSetDeviceMethodMessageCallbackAndContextsMatch(@Mocked final MessageCallback mockCallback) 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);
    Object context = new Object();
    config.setDeviceMethodMessageCallback(mockCallback, context);
    Object testContext = config.getDeviceMethodMessageContext();
    final Object expectedContext = context;
    assertThat(testContext, is(expectedContext));
    assertEquals(config.getDeviceMethodMessageCallback(), mockCallback);
}
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 22 with IotHubConnectionString

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

the class DeviceClientConfigTest method getMessageValidSecsReturnsConstant.

// Tests_SRS_DEVICECLIENTCONFIG_11_005: [The function shall return the value of tokenValidSecs.]
@Test
public void getMessageValidSecsReturnsConstant() 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);
    long testMessageValidSecs = config.getTokenValidSecs();
    final long expectedMessageValidSecs = 3600;
    assertThat(testMessageValidSecs, is(expectedMessageValidSecs));
}
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 23 with IotHubConnectionString

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

the class DeviceClientConfigTest method setUserCertificateSets.

//Tests_SRS_DEVICECLIENTCONFIG_25_029: [**The function shall set user certificate String**] **
@Test
public void setUserCertificateSets() 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 24 with IotHubConnectionString

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

the class DeviceClientConfigTest method getIotHubNameReturnsIotHubName.

// Tests_SRS_DEVICECLIENTCONFIG_11_007: [The function shall return the IoT Hub name given in the constructor,
// where the IoT Hub name is embedded in the IoT Hub hostname as follows: [IoT Hub name].[valid HTML chars]+.]
@Test
public void getIotHubNameReturnsIotHubName() 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 testIotHubName = config.getIotHubName();
    final String expectedIotHubName = "test";
    assertThat(testIotHubName, is(expectedIotHubName));
}
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 25 with IotHubConnectionString

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

the class DeviceClientConfigTest method getDeviceKeyReturnsDeviceKey.

// Tests_SRS_DEVICECLIENTCONFIG_11_004: [The function shall return the device key given in the constructor.]
@Test
public void getDeviceKeyReturnsDeviceKey() 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 testDeviceKey = config.getDeviceKey();
    final String expectedDeviceKey = deviceKey;
    assertThat(testDeviceKey, is(expectedDeviceKey));
}
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)31 IotHubConnectionString (com.microsoft.azure.sdk.iot.device.IotHubConnectionString)31 Test (org.junit.Test)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