Search in sources :

Example 1 with ServiceAuthenticationWithSharedAccessPolicyKey

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());
}
Also used : ServiceAuthenticationWithSharedAccessPolicyKey(com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyKey) Test(org.junit.Test)

Example 2 with ServiceAuthenticationWithSharedAccessPolicyKey

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);
}
Also used : Expectations(mockit.Expectations) ServiceAuthenticationWithSharedAccessPolicyKey(com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyKey) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Test(org.junit.Test)

Example 3 with ServiceAuthenticationWithSharedAccessPolicyKey

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);
}
Also used : ServiceAuthenticationWithSharedAccessPolicyKey(com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyKey) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) AuthenticationMethod(com.microsoft.azure.sdk.iot.service.AuthenticationMethod) Test(org.junit.Test)

Example 4 with ServiceAuthenticationWithSharedAccessPolicyKey

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);
}
Also used : ServiceAuthenticationWithSharedAccessPolicyKey(com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyKey) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Test(org.junit.Test)

Example 5 with ServiceAuthenticationWithSharedAccessPolicyKey

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);
}
Also used : ServiceAuthenticationWithSharedAccessPolicyKey(com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyKey) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) AuthenticationMethod(com.microsoft.azure.sdk.iot.service.AuthenticationMethod) Test(org.junit.Test)

Aggregations

ServiceAuthenticationWithSharedAccessPolicyKey (com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyKey)9 Test (org.junit.Test)9 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)8 AuthenticationMethod (com.microsoft.azure.sdk.iot.service.AuthenticationMethod)2 Expectations (mockit.Expectations)2