Search in sources :

Example 6 with IotHubConnectionString

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

the class DeviceClientConfigTest method getAndSetDeviceTwinMessageCallbackAndContextsMatch.

/*
    **Tests_SRS_DEVICECLIENTCONFIG_25_023: [**The function shall set the DeviceTwin message callback.**] **
    **Tests_SRS_DEVICECLIENTCONFIG_25_024: [**The function shall set the DeviceTwin message context.**] **
    **Tests_SRS_DEVICECLIENTCONFIG_25_025: [**The function shall return the current DeviceTwin message callback.**] **
    **Tests_SRS_DEVICECLIENTCONFIG_25_026: [**The function shall return the current DeviceTwin message context.**] **
     */
@Test
public void getAndSetDeviceTwinMessageCallbackAndContextsMatch(@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.setDeviceTwinMessageCallback(mockCallback, context);
    Object testContext = config.getDeviceTwinMessageContext();
    final Object expectedContext = context;
    assertThat(testContext, is(expectedContext));
    assertEquals(config.getDeviceTwinMessageCallback(), 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 7 with IotHubConnectionString

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

the class DeviceClientConfigTest method getAndSetMessageCallbackMatch.

// Tests_SRS_DEVICECLIENTCONFIG_11_006: [The function shall set the message callback, with its associated context.]
// Tests_SRS_DEVICECLIENTCONFIG_11_010: [The function shall return the current message callback.]
@Test
public void getAndSetMessageCallbackMatch(@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.setMessageCallback(mockCallback, context);
    MessageCallback testCallback = config.getMessageCallback();
    final MessageCallback expectedCallback = mockCallback;
    assertThat(testCallback, is(expectedCallback));
}
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) MessageCallback(com.microsoft.azure.sdk.iot.device.MessageCallback) Test(org.junit.Test)

Example 8 with IotHubConnectionString

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

the class DeviceClientConfigTest method setIotHubSSLContextSets.

//Tests_SRS_DEVICECLIENTCONFIG_25_031: [**The function shall set IotHub SSL Context**] **
@Test
public void setIotHubSSLContextSets(@Mocked final IotHubSSLContext mockedContext) 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.setIotHubSSLContext(mockedContext);
    IotHubSSLContext testContext = config.getIotHubSSLContext();
    assertNotNull(testContext);
    assertEquals(testContext, mockedContext);
}
Also used : IotHubSSLContext(com.microsoft.azure.sdk.iot.device.IotHubSSLContext) 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 9 with IotHubConnectionString

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

the class DeviceClientConfigTest method getDeviceIdReturnsDeviceId.

// Tests_SRS_DEVICECLIENTCONFIG_11_003: [The function shall return the device ID given in the constructor.]
@Test
public void getDeviceIdReturnsDeviceId() 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 testDeviceId = config.getDeviceId();
    final String expectedDeviceId = deviceId;
    assertThat(testDeviceId, is(expectedDeviceId));
}
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 10 with IotHubConnectionString

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

the class DeviceClientConfigTest method setPathToCertificateSets.

//Tests_SRS_DEVICECLIENTCONFIG_25_028: [**The function shall set the path to the certificate**] **
@Test
public void setPathToCertificateSets() throws URISyntaxException {
    final String iotHubHostname = "test.iothubhostname";
    final String deviceId = "test-deviceid";
    final String deviceKey = "test-devicekey";
    final String sharedAccessToken = null;
    final String certPath = "/test/path/to/certificate";
    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.setPathToCert(certPath);
    String testCertPath = config.getPathToCertificate();
    assertNotNull(certPath);
    assertEquals(testCertPath, certPath);
}
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