Search in sources :

Example 96 with IotHubConnectionString

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

the class DeviceOperationsTest method invoke_throwOnCreateIotHubServiceSasToken_failed.

/* Tests_SRS_DEVICE_OPERATIONS_21_006: [The request shall create a new SASToken with the ServiceConnect rights.] */
@Test(expected = IllegalArgumentException.class)
public void invoke_throwOnCreateIotHubServiceSasToken_failed() throws Exception {
    //arrange
    new MockUp<IotHubServiceSasToken>() {

        @Mock
        void $init(IotHubConnectionString iotHubConnectionString) {
            throw new IllegalArgumentException();
        }
    };
    //act
    HttpResponse response = DeviceOperations.request(IOT_HUB_CONNECTION_STRING, new URL(STANDARD_URL), HttpMethod.POST, STANDARD_PAYLOAD, STANDARD_REQUEST_ID, 0);
}
Also used : HttpResponse(com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) URL(java.net.URL) Test(org.junit.Test)

Example 97 with IotHubConnectionString

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

the class DeviceMethodTest method invoke_throwOnHttpRequester_failed.

/* Tests_SRS_DEVICEMETHOD_21_009: [The invoke shall send the created request and get the response using the HttpRequester.] */
/* Tests_SRS_DEVICEMETHOD_21_010: [The invoke shall create a new HttpRequest with http method as `POST`.] */
@Test(expected = IotHubException.class)
public void invoke_throwOnHttpRequester_failed(@Mocked final MethodParser methodParser, @Mocked final IotHubConnectionStringBuilder mockedConnectionStringBuilder) throws Exception {
    //arrange
    DeviceMethod testMethod = DeviceMethod.createFromConnectionString(STANDARD_CONNECTIONSTRING);
    new NonStrictExpectations() {

        {
            methodParser.toJson();
            result = STANDARD_JSON;
            iotHubConnectionString.getUrlMethod(STANDARD_DEVICEID);
            result = STANDARD_URL;
        }
    };
    new MockUp<DeviceOperations>() {

        @Mock
        HttpResponse request(IotHubConnectionString iotHubConnectionString, URL url, HttpMethod method, byte[] payload, String requestId, long timeoutInMs) throws IOException, IotHubException, IllegalArgumentException {
            throw new IotHubException();
        }
    };
    //act
    testMethod.invoke(STANDARD_DEVICEID, STANDARD_METHODNAME, STANDARD_TIMEOUT_SECONDS, STANDARD_TIMEOUT_SECONDS, STANDARD_PAYLOAD_MAP);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) DeviceMethod(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod) URL(java.net.URL) HttpMethod(com.microsoft.azure.sdk.iot.service.transport.http.HttpMethod) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException) Test(org.junit.Test)

Example 98 with IotHubConnectionString

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

the class ServiceClientTest method close_call_sender_close.

// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_011: [The function shall call close() on the member AMQP sender object]
@Test
public void close_call_sender_close() throws Exception {
    // Arrange
    String iotHubName = "IOTHUBNAME";
    String hostName = "HOSTNAME";
    String sharedAccessKeyName = "ACCESSKEYNAME";
    String policyName = "SharedAccessKey";
    String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
    String connectionString = "HostName=" + hostName + "." + iotHubName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
    IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    ServiceClient serviceClient = ServiceClient.createFromConnectionString(connectionString, iotHubServiceClientProtocol);
    // Assert
    new Expectations() {

        {
            amqpSend.close();
        }
    };
    // Act
    serviceClient.close();
}
Also used : Expectations(mockit.Expectations) ServiceClient(com.microsoft.azure.sdk.iot.service.ServiceClient) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 99 with IotHubConnectionString

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

the class ServiceClientTest method open_sender_null.

// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_008: [The function shall throw IOException if the member AMQP sender object has not been initialized]
// Assert
@Test(expected = IOException.class)
public void open_sender_null() throws Exception {
    // Arrange
    String iotHubName = "IOTHUBNAME";
    String hostName = "HOSTNAME";
    String sharedAccessKeyName = "ACCESSKEYNAME";
    String policyName = "SharedAccessKey";
    String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
    String connectionString = "HostName=" + hostName + "." + iotHubName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
    IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    ServiceClient serviceClient = ServiceClient.createFromConnectionString(connectionString, iotHubServiceClientProtocol);
    Deencapsulation.setField(serviceClient, "amqpMessageSender", null);
    // Act
    serviceClient.open();
}
Also used : ServiceClient(com.microsoft.azure.sdk.iot.service.ServiceClient) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 100 with IotHubConnectionString

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

the class ServiceClientTest method open_async_future_throw.

// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_014: [The function shall create an async wrapper around the open() function call, handle the return value or delegate exception]
// Assert
@Test(expected = Exception.class)
public void open_async_future_throw() throws Exception {
    // Arrange
    new MockUp<ServiceClient>() {

        @Mock
        public void open() throws IOException {
            throw new IOException();
        }
    };
    String iotHubName = "IOTHUBNAME";
    String hostName = "HOSTNAME";
    String sharedAccessKeyName = "ACCESSKEYNAME";
    String policyName = "SharedAccessKey";
    String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
    String connectionString = "HostName=" + hostName + "." + iotHubName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
    IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    ServiceClient serviceClient = ServiceClient.createFromConnectionString(connectionString, iotHubServiceClientProtocol);
    // Act
    CompletableFuture<Void> completableFuture = serviceClient.openAsync();
    completableFuture.get();
}
Also used : ServiceClient(com.microsoft.azure.sdk.iot.service.ServiceClient) MockUp(mockit.MockUp) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IOException(java.io.IOException) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) 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