use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class IotHubConnectionStringBuilderTest method parse_iotHubConnectionString_null.
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRINGBUILDER_12_007: [The function shall throw IllegalArgumentException if the input target itoHubConnectionString is null]
// Assert
@Test(expected = IllegalArgumentException.class)
public void parse_iotHubConnectionString_null() 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", connectionString, String.class);
}
use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class IotHubConnectionStringBuilderTest method createConnectionString_hosName_empty.
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRINGBUILDER_12_003: [The function shall throw IllegalArgumentException if the input string is empty or null]
// Assert
@Test(expected = IllegalArgumentException.class)
public void createConnectionString_hosName_empty() throws Exception {
// Arrange
AuthenticationMethod authenticationMethod = new ServiceAuthenticationWithSharedAccessPolicyKey("", "");
// Act
IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString("", authenticationMethod);
}
use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class IotHubConnectionStringBuilderTest method createConnectionString_good_case_policy_key.
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRINGBUILDER_12_005: [The function shall create a new IotHubConnectionString object using the given hostname and auhtenticationMethod]
@Test
public void createConnectionString_good_case_policy_key() throws Exception {
// Arrange
ServiceAuthenticationWithSharedAccessPolicyKey auth = new ServiceAuthenticationWithSharedAccessPolicyKey("myPolicy", "<key>");
// Act
IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString("hostname", auth);
String connString = iotHubConnectionString.toString();
// Assert
assertEquals("Connection string mismatch!", "HostName=hostname;SharedAccessKeyName=myPolicy;SharedAccessKey=<key>;SharedAccessSignature=null", connString);
}
use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class IotHubConnectionStringBuilderTest method parse_good_case.
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRINGBUILDER_12_009: [The function shall tokenize and parse the given connection string and fill up the target IotHubConnectionString object with proper values]
@Test
public void parse_good_case() 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;
String userString = sharedAccessKeyName + "@sas.root." + iotHubName;
IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
// Act
Deencapsulation.invoke(iotHubConnectionString, "parse", connectionString, iotHubConnectionString);
// Assert
assertEquals("Parser error: HostName mismatch!", iotHubName + "." + iotHostName, iotHubConnectionString.getHostName());
assertEquals("Parser error: SharedAccessKeyName mismatch!", sharedAccessKeyName, iotHubConnectionString.getSharedAccessKeyName());
assertEquals("Parser error: SharedAccessKey mismatch!", iotHubConnectionString.getSharedAccessKey(), sharedAccessKey);
assertEquals("Parser error: SharedAccessSignature mismatch!", "", iotHubConnectionString.getSharedAccessSignature());
assertEquals("Parser error: IotHubName mismatch!", iotHubName, iotHubConnectionString.getIotHubName());
assertEquals("Parser error: UserString mismatch!", userString, iotHubConnectionString.getUserString());
}
use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class IotHubConnectionStringBuilderTest method parse_connectionString_null.
// 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_null() 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", String.class, iotHubConnectionString);
}
Aggregations