Search in sources :

Example 46 with IotHubConnectionString

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

the class IotHubConnectionStringTest method getUrlQueryWithoutJobTypeSucceeds.

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRING_21_024: [** If the jobType is null or empty, the function shall not include the jobType in the URL **]**
@Test
public void getUrlQueryWithoutJobTypeSucceeds() 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/jobs/v2/query?jobStatus=jobStatus&" + URL_API_VERSION;
    final String jobType = null;
    final String jobStatus = "jobStatus";
    // act
    String actual = iotHubConnectionString.getUrlQuery(jobType, jobStatus).toString();
    // assert
    assertEquals(actual, expected);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Test(org.junit.Test)

Example 47 with IotHubConnectionString

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

the class IotHubConnectionStringTest method getUrlQueryWithoutJobTypeAndJobStatusSucceeds.

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRING_21_024: [** If the jobType is null or empty, the function shall not include the jobType in the URL **]**
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRING_21_025: [** If the jobStatus is null or empty, the function shall not include the jobStatus in the URL **]**
@Test
public void getUrlQueryWithoutJobTypeAndJobStatusSucceeds() 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/jobs/v2/query?" + URL_API_VERSION;
    final String jobType = null;
    final String jobStatus = null;
    // act
    String actual = iotHubConnectionString.getUrlQuery(jobType, jobStatus).toString();
    // assert
    assertEquals(actual, expected);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Test(org.junit.Test)

Example 48 with IotHubConnectionString

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

the class IotHubConnectionStringTest method getUrlModuleOnDeviceDeviceGoodCase.

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRING_28_009: [The function shall create a URL object from the given
// deviceId using the following format: https:hostname/devices/deviceId/modules?api-version=201X-XX-XX]
@Test
public void getUrlModuleOnDeviceDeviceGoodCase() throws IOException, IllegalArgumentException {
    // arrange
    final String deviceId = "xxx-device";
    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/xxx-device/modules?" + URL_API_VERSION;
    // act
    String actual = iotHubConnectionString.getUrlModulesOnDevice(deviceId).toString();
    // assert
    assertEquals("Device 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 49 with IotHubConnectionString

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

the class IotHubConnectionStringTest method getUrlConfigurationListMaxCountNull.

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRING_28_006: [The constructor shall throw NullPointerException if the input integer is null]
// assert
@Test(expected = IllegalArgumentException.class)
public void getUrlConfigurationListMaxCountNull() throws IOException, IllegalArgumentException {
    // arrange
    Integer maxCount = 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.getUrlConfigurationsList(maxCount);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Test(org.junit.Test)

Example 50 with IotHubConnectionString

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

the class IotHubConnectionStringTest method getUrlImportExportJobSucceeds.

/*
    ** Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRING_15_009: [The function shall create a URL object from the object properties using the following format: https:hostname/jobs/jobId?api-version=201X-XX-XX.]
     */
@Test
public void getUrlImportExportJobSucceeds() 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 IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
    final String jobId = "testJobId";
    final String expected = "https://HOSTNAME.b.c.d/jobs/testJobId?" + URL_API_VERSION;
    // act
    String actual = iotHubConnectionString.getUrlImportExportJob(jobId).toString();
    // assert
    assertEquals(actual, expected);
}
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