Search in sources :

Example 16 with IotHubConnectionString

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

Example 17 with IotHubConnectionString

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);
}
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 18 with IotHubConnectionString

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);
}
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 19 with IotHubConnectionString

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

Example 20 with IotHubConnectionString

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);
}
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