Search in sources :

Example 26 with DeviceClientConfig

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

Example 27 with DeviceClientConfig

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

the class DeviceClientConfigTest method getPathToCertificateGets.

//Tests_SRS_DEVICECLIENTCONFIG_25_027: [**The function shall return the value of the path to the certificate.**] **
@Test
public void getPathToCertificateGets() 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)

Example 28 with DeviceClientConfig

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

the class DeviceClientConfigTest method getSasTokenReturnsSasToken.

// Tests_SRS_DEVICECLIENTCONFIG_25_018: [**The function shall return the SharedAccessToken given in the constructor.**] **
@Test
public void getSasTokenReturnsSasToken() throws URISyntaxException {
    final String iotHubHostname = "test.iothubhostname";
    final String deviceId = "test-deviceid";
    final String deviceKey = null;
    final String sharedAccessToken = "SharedAccessSignature sr=sample-iothub-hostname.net%2fdevices%2fsample-device-ID&sig=S3%2flPidfBF48B7%2fOFAxMOYH8rpOneq68nu61D%2fBP6fo%3d&se=1469813873";
    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 testSasToken = config.getSharedAccessToken();
    final String expectedSasToken = sharedAccessToken;
    assertThat(testSasToken, is(expectedSasToken));
}
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 29 with DeviceClientConfig

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

the class IotHubSasTokenTest method doesNotSetInvalidSASToken.

// Tests_SRS_IOTHUBSASTOKEN_25_008: [**The required format for the SAS Token shall be verified and IllegalArgumentException is thrown if unmatched.**]**
//Tests_SRS_IOTHUBSASTOKEN_11_001: [**The SAS token shall have the format `SharedAccessSignature sig=<signature >&se=<expiryTime>&sr=<resourceURI>`. The params can be in any order.**]**
@Test(expected = IllegalArgumentException.class)
public void doesNotSetInvalidSASToken() throws URISyntaxException {
    String sastoken = "SharedAccessSignature sr =sample-iothub-hostname.net%2fdevices%2fsample-device-ID&sig =S3%2flPidfBF48B7%2fOFAxMOYH8rpOneq68nu61D%2fBP6fo%3d&se =1469813873";
    final IotHubConnectionString iotHubConnectionString = Deencapsulation.newInstance(IotHubConnectionString.class, new Class[] { String.class, String.class, String.class, String.class }, "iothub.sample-iothub-hostname.net", "sample-device-ID", null, sastoken);
    IotHubSasToken token = new IotHubSasToken(new DeviceClientConfig(iotHubConnectionString), 0);
    String tokenStr = token.toString();
    assertTrue(tokenStr != sastoken);
}
Also used : DeviceClientConfig(com.microsoft.azure.sdk.iot.device.DeviceClientConfig) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) IotHubSasToken(com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) Test(org.junit.Test)

Example 30 with DeviceClientConfig

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

the class IotHubSasTokenTest method setValidSASTokenCorrectly.

// Tests_SRS_IOTHUBSASTOKEN_25_007: [**If device key is not provided in config then the SASToken from config shall be used.**]**
@Test
public void setValidSASTokenCorrectly() throws URISyntaxException {
    String sastoken = "SharedAccessSignature sr=sample-iothub-hostname.net%2fdevices%2fsample-device-ID&sig=S3%2flPidfBF48B7%2fOFAxMOYH8rpOneq68nu61D%2fBP6fo%3d&se=1469813873";
    final IotHubConnectionString iotHubConnectionString = Deencapsulation.newInstance(IotHubConnectionString.class, new Class[] { String.class, String.class, String.class, String.class }, "iothub.sample-iothub-hostname.net", "sample-device-ID", null, sastoken);
    IotHubSasToken token = new IotHubSasToken(new DeviceClientConfig(iotHubConnectionString), 0);
    String tokenStr = token.toString();
    assertTrue(tokenStr == sastoken);
}
Also used : DeviceClientConfig(com.microsoft.azure.sdk.iot.device.DeviceClientConfig) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) IotHubSasToken(com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken) 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