Search in sources :

Example 21 with DeviceClientConfig

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

the class DeviceClientConfigTest method getIotHubSSLContextGets.

//Tests_SRS_DEVICECLIENTCONFIG_25_032: [**The function shall return the IotHubSSLContext.**] **
@Test
public void getIotHubSSLContextGets(@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 22 with DeviceClientConfig

use of com.microsoft.azure.sdk.iot.device.DeviceClientConfig 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 23 with DeviceClientConfig

use of com.microsoft.azure.sdk.iot.device.DeviceClientConfig 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 24 with DeviceClientConfig

use of com.microsoft.azure.sdk.iot.device.DeviceClientConfig 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 25 with DeviceClientConfig

use of com.microsoft.azure.sdk.iot.device.DeviceClientConfig 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)

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