Search in sources :

Example 36 with IotHubConnectionString

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

the class IotHubConnectionStringTest method getUrlDevice_device_name_null.

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRING_12_002: [The function shall throw IllegalArgumentException if the input string is empty or null]
// Assert
@Test(expected = IllegalArgumentException.class)
public void getUrlDevice_device_name_null() throws Exception {
    // Arrange
    String deviceId = null;
    String iotHubName = "b.c.d";
    String hostName = "HOSTNAME." + iotHubName;
    String sharedAccessKeyName = "ACCESSKEYNAME";
    String policyName = "SharedAccessKey";
    String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
    String connectionString = "HostName=" + hostName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
    IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
    // Act
    URL urlDevice = iotHubConnectionString.getUrlDevice(deviceId);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) URL(java.net.URL) Test(org.junit.Test)

Example 37 with IotHubConnectionString

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

the class IotHubConnectionStringTest method getUrlDeviceList_maxCount_null.

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRING_12_004: [The constructor shall throw NullPointerException if the input integer is null]
// Assert
@Test(expected = IllegalArgumentException.class)
public void getUrlDeviceList_maxCount_null() throws Exception {
    // Arrange
    Integer maxCount = null;
    String iotHubName = "b.c.d";
    String hostName = "HOSTNAME." + iotHubName;
    String sharedAccessKeyName = "ACCESSKEYNAME";
    String policyName = "SharedAccessKey";
    String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
    String connectionString = "HostName=" + hostName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
    IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
    // Act
    URL urlDevice = iotHubConnectionString.getUrlDeviceList(maxCount);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) URL(java.net.URL) Test(org.junit.Test)

Example 38 with IotHubConnectionString

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

the class IotHubConnectionStringTest method getUrlDeviceList_good_case.

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRING_12_005: [The function shall create a URL object from the given integer using the following format: https:hostname/devices/?maxCount=XX&api-version=201X-XX-XX]
@Test
public void getUrlDeviceList_good_case() throws Exception {
    // Arrange
    Integer maxCount = 10;
    String iotHubName = "b.c.d";
    String hostName = "HOSTNAME." + iotHubName;
    String sharedAccessKeyName = "ACCESSKEYNAME";
    String policyName = "SharedAccessKey";
    String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
    String connectionString = "HostName=" + hostName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
    IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
    String expected = "https://HOSTNAME.b.c.d/devices/?top=10&api-version=2016-11-14";
    // Act
    String actual = iotHubConnectionString.getUrlDeviceList(maxCount).toString();
    // Assert
    assertEquals("DeviceList URL mismatch!", expected, actual);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Test(org.junit.Test)

Example 39 with IotHubConnectionString

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

the class IotHubConnectionStringTest method getUrlTwinTags_throwsOnEmptyDeviceID.

/*
    **Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRING_25_012: [** The function shall throw IllegalArgumentException if the input string is empty or null **]**
     */
@Test(expected = IllegalArgumentException.class)
public void getUrlTwinTags_throwsOnEmptyDeviceID() throws Exception {
    //arrange
    String iotHubName = "b.c.d";
    String hostName = "HOSTNAME." + iotHubName;
    String sharedAccessKeyName = "ACCESSKEYNAME";
    String policyName = "SharedAccessKey";
    String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
    String connectionString = "HostName=" + hostName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
    String deviceId = "";
    IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
    //act
    String actual = iotHubConnectionString.getUrlTwinTags(deviceId).toString();
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Test(org.junit.Test)

Example 40 with IotHubConnectionString

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

the class IotHubConnectionStringTest method getUrlTwinDesired_succeeds.

/*
    **Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRING_25_015: [** The function shall create a URL object from the given deviceId using the following format: https:hostname/twins/deviceId/properties/desired?api-version=201X-XX-XX **]**
     */
@Test
public void getUrlTwinDesired_succeeds() throws Exception {
    //arrange
    String iotHubName = "b.c.d";
    String hostName = "HOSTNAME." + iotHubName;
    String sharedAccessKeyName = "ACCESSKEYNAME";
    String policyName = "SharedAccessKey";
    String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
    String connectionString = "HostName=" + hostName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
    String deviceId = "testDevice";
    IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
    String expected = "https://HOSTNAME.b.c.d/twins/testDevice/properties/desired?api-version=2016-11-14";
    //act
    String actual = iotHubConnectionString.getUrlTwinDesired(deviceId).toString();
    //assert
    assertTrue(actual.equals(expected));
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Test(org.junit.Test)

Aggregations

IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)76 Test (org.junit.Test)75 Expectations (mockit.Expectations)17 IotHubServiceClientProtocol (com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol)12 ServiceClient (com.microsoft.azure.sdk.iot.service.ServiceClient)12 ServiceAuthenticationWithSharedAccessPolicyKey (com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyKey)6 IotHubServiceSasToken (com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken)6 URL (java.net.URL)6 ServiceAuthenticationWithSharedAccessPolicyToken (com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyToken)4 AuthenticationMethod (com.microsoft.azure.sdk.iot.service.AuthenticationMethod)3 HttpResponse (com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse)3 IOException (java.io.IOException)2 FeedbackReceiver (com.microsoft.azure.sdk.iot.service.FeedbackReceiver)1 Message (com.microsoft.azure.sdk.iot.service.Message)1 DeviceMethod (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod)1 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)1 AmqpSend (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend)1 HttpMethod (com.microsoft.azure.sdk.iot.service.transport.http.HttpMethod)1 HttpRequest (com.microsoft.azure.sdk.iot.service.transport.http.HttpRequest)1 URLEncoder (java.net.URLEncoder)1