Search in sources :

Example 6 with AmqpSend

use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend in project azure-iot-sdk-java by Azure.

the class ServiceClientTest method constructor_create_sas_token.

// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_005: [The constructor shall create a SAS token object using the IotHubConnectionString]
// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_006: [The constructor shall store connection string, hostname, username and sasToken]
// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_007: [The constructor shall create a new instance of AmqpSend object]
@Test
public void constructor_create_sas_token() 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;
    new Expectations() {

        {
            iotHubServiceSasToken = new IotHubServiceSasToken(withNotNull());
            amqpSend = new AmqpSend(anyString, anyString, anyString, iotHubServiceClientProtocol);
        }
    };
    // Act
    ServiceClient serviceClient = ServiceClient.createFromConnectionString(connectionString, iotHubServiceClientProtocol);
    // Assert
    assertNotEquals(hostName, Deencapsulation.getField(serviceClient, "hostName"));
    assertEquals(iotHubConnectionString.getUserString(), Deencapsulation.getField(serviceClient, "userName"));
}
Also used : Expectations(mockit.Expectations) IotHubServiceSasToken(com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken) ServiceClient(com.microsoft.azure.sdk.iot.service.ServiceClient) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) AmqpSend(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 7 with AmqpSend

use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend in project azure-iot-sdk-java by Azure.

the class AmqpSendTest method constructor_copies_params_to_members_amqps_ws.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPSEND_12_002: [The constructor shall copy all input parameters to private member variables for event processing]
@Test
public void constructor_copies_params_to_members_amqps_ws() {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = "ccc";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS_WS;
    // Act
    AmqpSend amqpSend = new AmqpSend(hostName, userName, sasToken, iotHubServiceClientProtocol);
    String _hostName = Deencapsulation.getField(amqpSend, "hostName");
    String _userName = Deencapsulation.getField(amqpSend, "userName");
    String _sasToken = Deencapsulation.getField(amqpSend, "sasToken");
    IotHubServiceClientProtocol _ioIotHubServiceClientProtocol = Deencapsulation.getField(amqpSend, "iotHubServiceClientProtocol");
    // Assert
    assertEquals(hostName, _hostName);
    assertEquals(userName, _userName);
    assertEquals(sasToken, _sasToken);
    assertEquals(iotHubServiceClientProtocol, _ioIotHubServiceClientProtocol);
}
Also used : AmqpSend(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 8 with AmqpSend

use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend in project azure-iot-sdk-java by Azure.

the class AmqpSendTest method send_throwsIOException_when_open_has_not_been_called.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPSEND_12_009: [The event handler shall throw IOException if the send handler object is not initialized]
// Assert
@Test(expected = IOException.class)
public void send_throwsIOException_when_open_has_not_been_called() throws Exception {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = "ccc";
    String deviceId = "deviceId";
    String content = "abcdefghijklmnopqrst";
    Message message = new Message(content);
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    AmqpSend amqpSend = new AmqpSend(hostName, userName, sasToken, iotHubServiceClientProtocol);
    // Act
    amqpSend.send(deviceId, message);
}
Also used : Message(com.microsoft.azure.sdk.iot.service.Message) AmqpSend(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 9 with AmqpSend

use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend in project azure-iot-sdk-java by Azure.

the class AmqpSendTest method constructor_checks_if_hostName_null.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPSEND_12_001: [The constructor shall throw IllegalArgumentException if any of the input parameter is null or empty]
// Assert
@Test(expected = IllegalArgumentException.class)
public void constructor_checks_if_hostName_null() {
    // Arrange
    String hostName = null;
    String userName = "bbb";
    String sasToken = "ccc";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    // Act
    AmqpSend amqpSend = new AmqpSend(hostName, userName, sasToken, iotHubServiceClientProtocol);
}
Also used : AmqpSend(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 10 with AmqpSend

use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend in project azure-iot-sdk-java by Azure.

the class AmqpSendTest method send_creates_ProtonMessage.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPSEND_12_006: [The event handler shall create a Proton message with the given content]
@Test
public void send_creates_ProtonMessage() throws Exception {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = "ccc";
    String deviceId = "deviceId";
    String content = "abcdefghijklmnopqrst";
    Message message = new Message(content);
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    AmqpSend amqpSend = new AmqpSend(hostName, userName, sasToken, iotHubServiceClientProtocol);
    amqpSend.open();
    AmqpSendHandler handler = Deencapsulation.getField(amqpSend, "amqpSendHandler");
    // Assert
    new Expectations() {

        {
            Deencapsulation.invoke(handler, "createProtonMessage", deviceId, message);
        }
    };
    // Act
    amqpSend.send(deviceId, message);
}
Also used : Expectations(mockit.Expectations) Message(com.microsoft.azure.sdk.iot.service.Message) AmqpSendHandler(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler) AmqpSend(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Aggregations

IotHubServiceClientProtocol (com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol)15 AmqpSend (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend)15 Test (org.junit.Test)15 Expectations (mockit.Expectations)4 Message (com.microsoft.azure.sdk.iot.service.Message)3 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)1 ServiceClient (com.microsoft.azure.sdk.iot.service.ServiceClient)1 IotHubServiceSasToken (com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken)1 AmqpSendHandler (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler)1