Search in sources :

Example 6 with ServiceClient

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

the class ServiceClientTest method send_async_future_throw.

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

        @Mock
        public void send(String deviceId, String message) 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;
    String deviceId = "XXX";
    String content = "HELLO";
    Message iotMessage = new Message(content);
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    ServiceClient serviceClient = ServiceClient.createFromConnectionString(connectionString, iotHubServiceClientProtocol);
    // Act
    CompletableFuture<Void> completableFuture = serviceClient.sendAsync(deviceId, iotMessage);
    completableFuture.get();
}
Also used : Message(com.microsoft.azure.sdk.iot.service.Message) ServiceClient(com.microsoft.azure.sdk.iot.service.ServiceClient) MockUp(mockit.MockUp) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IOException(java.io.IOException) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 7 with ServiceClient

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

the class ServiceClientTest method constructor_input_null.

// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_004: [The constructor shall throw IllegalArgumentException if the input object is null]
// Assert
@Test(expected = IllegalArgumentException.class)
public void constructor_input_null() throws Exception {
    // Arrange
    IotHubConnectionString iotHubConnectionString = null;
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    // Act
    ServiceClient serviceClient = Deencapsulation.newInstance(ServiceClient.class, iotHubConnectionString, iotHubServiceClientProtocol);
}
Also used : ServiceClient(com.microsoft.azure.sdk.iot.service.ServiceClient) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 8 with ServiceClient

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

the class ServiceClientTest method send_sender_null.

// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_0012: [The function shall throw IOException if the member AMQP sender object has not been initialized]
// Assert
@Test(expected = IOException.class)
public void send_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;
    String deviceId = "XXX";
    String content = "HELLO";
    Message iotMessage = new Message(content);
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    ServiceClient serviceClient = ServiceClient.createFromConnectionString(connectionString, iotHubServiceClientProtocol);
    Deencapsulation.setField(serviceClient, "amqpMessageSender", null);
    // Act
    serviceClient.send(deviceId, iotMessage);
}
Also used : Message(com.microsoft.azure.sdk.iot.service.Message) ServiceClient(com.microsoft.azure.sdk.iot.service.ServiceClient) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 9 with ServiceClient

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

the class ServiceClientTest method open_call_amqpsender_open.

// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_009: [The function shall call open() on the member AMQP sender object]
@Test
public void open_call_amqpsender_open() 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.open();
        }
    };
    // Act
    serviceClient.open();
}
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 10 with ServiceClient

use of com.microsoft.azure.sdk.iot.service.ServiceClient 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)

Aggregations

IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)17 IotHubServiceClientProtocol (com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol)17 ServiceClient (com.microsoft.azure.sdk.iot.service.ServiceClient)17 Test (org.junit.Test)17 Expectations (mockit.Expectations)10 Message (com.microsoft.azure.sdk.iot.service.Message)4 IOException (java.io.IOException)3 MockUp (mockit.MockUp)3 FeedbackReceiver (com.microsoft.azure.sdk.iot.service.FeedbackReceiver)2 IotHubServiceSasToken (com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken)1 AmqpSend (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend)1