Search in sources :

Example 51 with IotHubConnectionString

use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.

the class IotHubConnectionStringTest method getUrlConfigurationListGoodCase.

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRING_28_007: [The function shall create a URL object from the given
// integer using the following format: https:hostname/configurations/?maxCount=XX&api-version=201X-XX-XX]
@Test
public void getUrlConfigurationListGoodCase() throws IOException, IllegalArgumentException {
    // arrange
    Integer maxCount = 10;
    final String iotHubName = "b.c.d";
    final String hostName = "HOSTNAME." + iotHubName;
    final String sharedAccessKeyName = "ACCESSKEYNAME";
    final String policyName = "SharedAccessKey";
    final String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
    final String connectionString = "HostName=" + hostName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
    final IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
    final String expected = "https://HOSTNAME.b.c.d/configurations?top=10&" + URL_API_VERSION;
    // act
    String actual = iotHubConnectionString.getUrlConfigurationsList(maxCount).toString();
    // assert
    assertEquals("ConfigurationList URL mismatch!", expected, actual);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Test(org.junit.Test)

Example 52 with IotHubConnectionString

use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.

the class IotHubConnectionStringTest method getUrlDeviceDeviceNameEmpty.

// 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 getUrlDeviceDeviceNameEmpty() throws IOException, IllegalArgumentException {
    // arrange
    final String deviceId = "";
    final String iotHubName = "b.c.d";
    final String hostName = "HOSTNAME." + iotHubName;
    final String sharedAccessKeyName = "ACCESSKEYNAME";
    final String policyName = "SharedAccessKey";
    final String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
    final String connectionString = "HostName=" + hostName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
    final IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
    // act
    iotHubConnectionString.getUrlDevice(deviceId);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Test(org.junit.Test)

Example 53 with IotHubConnectionString

use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.

the class IotHubConnectionStringTest method getUserStringGoodCase.

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRING_12_001: [The function shall serialize the object properties to a string using the following format: SharedAccessKeyName@SAS.root.IotHubName]
@Test
public void getUserStringGoodCase() throws IOException {
    // arrange
    final String iotHubName = "b.c.d";
    final String hostName = "HOSTNAME." + iotHubName;
    final String sharedAccessKeyName = "ACCESSKEYNAME";
    final String policyName = "SharedAccessKey";
    final String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
    final String connectionString = "HostName=" + hostName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
    final IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
    final String expected = sharedAccessKeyName + "@SAS.root.HOSTNAME";
    // act
    String actual = iotHubConnectionString.getUserString();
    // assert
    assertEquals("UserString mismatch!", expected, actual);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Test(org.junit.Test)

Example 54 with IotHubConnectionString

use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.

the class IotHubConnectionStringTest method getUrlModuleTwinDeviceNameNull.

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRING_28_010: [The function shall throw IllegalArgumentException if the deviceId string is empty or null]
// assert
@Test(expected = IllegalArgumentException.class)
public void getUrlModuleTwinDeviceNameNull() throws IOException, IllegalArgumentException {
    // arrange
    final String deviceId = null;
    final String moduleId = "somemodule";
    final String iotHubName = "b.c.d";
    final String hostName = "HOSTNAME." + iotHubName;
    final String sharedAccessKeyName = "ACCESSKEYNAME";
    final String policyName = "SharedAccessKey";
    final String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
    final String connectionString = "HostName=" + hostName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
    final IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
    // act
    iotHubConnectionString.getUrlModuleTwin(deviceId, moduleId);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Test(org.junit.Test)

Example 55 with IotHubConnectionString

use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.

the class IotHubConnectionStringTest method getUrlModuleOnDeviceDeviceNameNull.

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRING_28_008: [The function shall throw IllegalArgumentException if the moduleId string is empty or null]
// assert
@Test(expected = IllegalArgumentException.class)
public void getUrlModuleOnDeviceDeviceNameNull() throws IOException, IllegalArgumentException {
    // arrange
    final String deviceId = null;
    final String iotHubName = "b.c.d";
    final String hostName = "HOSTNAME." + iotHubName;
    final String sharedAccessKeyName = "ACCESSKEYNAME";
    final String policyName = "SharedAccessKey";
    final String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
    final String connectionString = "HostName=" + hostName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
    final IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
    // act
    iotHubConnectionString.getUrlModulesOnDevice(deviceId);
}
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)196 Test (org.junit.Test)171 IotHubServiceSasToken (com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken)30 Expectations (mockit.Expectations)21 IntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest)20 ServiceClient (com.microsoft.azure.sdk.iot.service.ServiceClient)17 AzureSasCredential (com.azure.core.credential.AzureSasCredential)16 JobClient (com.microsoft.azure.sdk.iot.service.jobs.JobClient)13 StandardTierHubOnlyTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest)13 Device (com.microsoft.azure.sdk.iot.service.Device)12 IotHubServiceClientProtocol (com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol)12 IotHubTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest)12 HttpResponse (com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse)11 URL (java.net.URL)11 ContinuousIntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)11 NonStrictExpectations (mockit.NonStrictExpectations)10 DeviceTwin (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin)9 ArrayList (java.util.ArrayList)9 Verifications (mockit.Verifications)9 DeviceClient (com.microsoft.azure.sdk.iot.device.DeviceClient)8