use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class IotHubConnectionStringBuilderTest method parse_connectionString_empty.
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRINGBUILDER_12_006: [The function shall throw IllegalArgumentException if the input string is empty or null]
// Assert
@Test(expected = IllegalArgumentException.class)
public void parse_connectionString_empty() throws Exception {
// Arrange
String iotHubName = "IOTHUBNAME";
String iotHostName = "HOSTNAME";
String sharedAccessKeyName = "ACCESSKEYNAME";
String policyName = "SharedAccessKey";
String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
String connectionString = "HostName=" + iotHubName + "." + iotHostName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
// Act
Deencapsulation.invoke(iotHubConnectionString, "parse", "", iotHubConnectionString);
}
use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class IotHubConnectionStringBuilderTest method validateFormat_value_did_not_match.
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRINGBUILDER_12_019: [The function shall throw IllegalArgumentException if the value did not match with the pattern]
@Test(expected = IllegalArgumentException.class)
public void validateFormat_value_did_not_match() throws Exception {
// Arrange
String regex = "[a-zA-Z0-9_\\-\\.]+$";
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 - Assert
Deencapsulation.invoke(iotHubConnectionString, "validateFormat", "+++", "hostName", regex);
}
use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class IotHubConnectionStringTest method getUrlTwinTags_succeeds.
/*
**Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRING_25_013: [** The function shall create a URL object from the given deviceId using the following format: https:hostname/twins/deviceId/tags?api-version=201X-XX-XX **]**
*/
@Test
public void getUrlTwinTags_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/tags?api-version=2016-11-14";
//act
String actual = iotHubConnectionString.getUrlTwinTags(deviceId).toString();
//assert
assertTrue(actual.equals(expected));
}
use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class IotHubConnectionStringTest method getUrlDevice_device_name_empty.
// 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_empty() throws Exception {
// Arrange
String deviceId = "";
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);
}
use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class IotHubConnectionStringTest method getUrlTwin_throwsOnNullDeviceID.
@Test(expected = IllegalArgumentException.class)
public void getUrlTwin_throwsOnNullDeviceID() 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 = null;
IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
//act
String actual = iotHubConnectionString.getUrlTwin(deviceId).toString();
}
Aggregations