use of com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyKey in project azure-iot-sdk-java by Azure.
the class AuthenticationMethodTest method ServiceAuthenticationWithSharedAccessPolicyKey.
/**
* Test of getAuthenticationMethodSharedAccessKey class.
* Create and get
*/
@Test
public void ServiceAuthenticationWithSharedAccessPolicyKey() throws Exception {
// Arrange
String policyName = "SharedAccessKey";
String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
// Act
ServiceAuthenticationWithSharedAccessPolicyKey serviceAuthenticationWithSharedAccessPolicyKey = new ServiceAuthenticationWithSharedAccessPolicyKey(policyName, sharedAccessKey);
// Assert
assertEquals("PolicyName mismatch!", policyName, serviceAuthenticationWithSharedAccessPolicyKey.getPolicyName());
assertEquals("SharedAccessKey mismatch!", sharedAccessKey, serviceAuthenticationWithSharedAccessPolicyKey.getKey());
}
use of com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyKey in project azure-iot-sdk-java by Azure.
the class IotHubConnectionStringBuilderTest method parse_SharedAccessSignature_not_defined.
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRINGBUILDER_12_011: [The function shall create new ServiceAuthenticationWithSharedAccessPolicyKey and set the authenticationMethod if the sharedAccessSignature is not defined]
@Test
public void parse_SharedAccessSignature_not_defined() 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;
// Assert
new Expectations() {
{
new ServiceAuthenticationWithSharedAccessPolicyKey(anyString, anyString);
}
};
// Act
IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
}
use of com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyKey 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.ServiceAuthenticationWithSharedAccessPolicyKey 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.ServiceAuthenticationWithSharedAccessPolicyKey in project azure-iot-sdk-java by Azure.
the class IotHubConnectionStringBuilderTest method createConnectionString_hostName_null.
// 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_hostName_null() throws Exception {
// Arrange
AuthenticationMethod authenticationMethod = new ServiceAuthenticationWithSharedAccessPolicyKey("", "");
// Act
IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(null, authenticationMethod);
}
Aggregations