Search in sources :

Example 56 with IotHubConnectionString

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

the class IotHubConnectionStringTest method getUrlJobsThrowsOnNullJobID.

@Test(expected = IllegalArgumentException.class)
public void getUrlJobsThrowsOnNullJobID() throws IOException, IllegalArgumentException {
    // 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 String jobId = null;
    final IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
    // act
    iotHubConnectionString.getUrlJobs(jobId).toString();
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Test(org.junit.Test)

Example 57 with IotHubConnectionString

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

the class IotHubConnectionStringTest method getUrlDeviceListGoodCase.

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRING_12_005: [The function shall create a URL object from the given integer using the following format: https:hostname/devices/?maxCount=XX&api-version=201X-XX-XX]
@Test
public void getUrlDeviceListGoodCase() 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/devices/?top=10&" + URL_API_VERSION;
    // act
    String actual = iotHubConnectionString.getUrlDeviceList(maxCount).toString();
    // assert
    assertEquals("DeviceList 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 58 with IotHubConnectionString

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

the class IotHubConnectionStringTest method getUrlDeviceStatisticsGoodCase.

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRING_12_006: [The function shall create a URL object from the object properties using the following format: https:hostname/statistics/devices?api-version=201X-XX-XX]
@Test
public void getUrlDeviceStatisticsGoodCase() 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 = "https://HOSTNAME.b.c.d/statistics/devices?" + URL_API_VERSION;
    // act
    String actual = iotHubConnectionString.getUrlDeviceStatistics().toString();
    // assert
    assertEquals("Device Statistics 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 59 with IotHubConnectionString

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

the class IotHubConnectionStringTest method getUrlConfigurationConfigurationNameEmpty.

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRING_28_004: [The function shall throw IllegalArgumentException if the input string is empty or null]
// assert
@Test(expected = IllegalArgumentException.class)
public void getUrlConfigurationConfigurationNameEmpty() throws IOException, IllegalArgumentException {
    // arrange
    final String configurationId = "";
    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.getUrlConfiguration(configurationId);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Test(org.junit.Test)

Example 60 with IotHubConnectionString

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

the class IotHubConnectionStringTest method getUrlModuleModuleNameNull.

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRING_28_002: [The function shall throw IllegalArgumentException if the moduleId string is empty or null]
// assert
@Test(expected = IllegalArgumentException.class)
public void getUrlModuleModuleNameNull() throws IOException, IllegalArgumentException {
    // arrange
    final String deviceId = "somedevice";
    final String moduleId = 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.getUrlModule(deviceId, moduleId);
}
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