Search in sources :

Example 1 with MessageType

use of com.microsoft.azure.sdk.iot.device.MessageType in project azure-iot-sdk-java by Azure.

the class MessageTest method testPropertyGettersAndSetters.

// Tests_SRS_MESSAGE_34_051: [The function shall set the message's connection device id to the provided value.]
// Tests_SRS_MESSAGE_34_052: [The function shall set the message's connection module id to the provided value.]
// Tests_SRS_MESSAGE_34_053: [The function shall set the message's output name to the provided value.]
// Tests_SRS_MESSAGE_34_047: [The function shall set the message's expiry time.]
// Tests_SRS_MESSAGE_34_048: [The function shall set the message's message type.]
// Tests_SRS_MESSAGE_34_046: [The function shall set the message's correlation ID to the provided value.]
// Tests_SRS_MESSAGE_34_044: [The function shall set the message's message ID to the provided value.]
// Tests_SRS_MESSAGE_34_058: [The function shall set the message's input name to the provided value.]
// Tests_SRS_MESSAGE_34_049: [The function shall return the message's message type.]
// Tests_SRS_MESSAGE_34_045: [The function shall return the message's correlation ID.]
// Tests_SRS_MESSAGE_34_043: [The function shall return the message's message Id.]
// Tests_SRS_MESSAGE_34_039: [The function shall return the message's DeliveryAcknowledgement.]
// Tests_SRS_MESSAGE_34_037: [The function shall return the message's user ID.]
// Tests_SRS_MESSAGE_34_041: [The function shall return the message's To value.]
// Tests_SRS_MESSAGE_12_001: [The function shall return the message's iotHubConnectionString object.]
// Tests_SRS_MESSAGE_34_054: [The function shall return the message's connection device id value.]
// Tests_SRS_MESSAGE_34_055: [The function shall return the message's connection module id value.]
// Tests_SRS_MESSAGE_34_056: [The function shall return the message's input name value.]
// Tests_SRS_MESSAGE_34_057: [The function shall return the message's output name value.]
// Tests_SRS_MESSAGE_12_002: [The function shall set the message's iotHubConnectionString object to the provided value.]
// Tests_SRS_MESSAGE_34_059: [The function shall return the message's content type.]
// Tests_SRS_MESSAGE_34_060: [The function shall save the provided content type.]
// Tests_SRS_MESSAGE_34_061: [The function shall return the message's content encoding.]
// Tests_SRS_MESSAGE_34_062: [The function shall save the provided content encoding.]
// Tests_SRS_MESSAGE_34_065: [The function shall save the provided creationTimeUTC.]
// Tests_SRS_MESSAGE_34_063: [The function shall return the saved creationTimeUTC.]
@Test
public void testPropertyGettersAndSetters() {
    // arrange
    Message msg = new Message();
    MessageType type = MessageType.DEVICE_TELEMETRY;
    String messageId = "1234";
    String correlationId = "6789";
    final String iotHubHostname = "test.iothubhostname";
    final String deviceId = "test-deviceid";
    final String deviceKey = "test-devicekey";
    final String userId = "user id";
    final String connectionDeviceId = "connectionDeviceId";
    final String connectionModuleId = "connectionModuleId";
    final String inputName = "inputName";
    final String outputName = "outputName";
    final String contentType = "json";
    final String contentEncoding = "utf-8";
    final Date date = new Date(0);
    final String sharedAccessToken = null;
    final IotHubConnectionString iotHubConnectionString = Deencapsulation.newInstance(IotHubConnectionString.class, new Class[] { String.class, String.class, String.class, String.class }, iotHubHostname, deviceId, deviceKey, sharedAccessToken);
    // act
    msg.setMessageType(type);
    msg.setCorrelationId(correlationId);
    msg.setMessageId(messageId);
    msg.setIotHubConnectionString(iotHubConnectionString);
    msg.setUserId(userId);
    msg.setConnectionDeviceId(connectionDeviceId);
    msg.setConnectionModuleId(connectionModuleId);
    msg.setOutputName(outputName);
    msg.setInputName(inputName);
    msg.setContentEncoding(contentEncoding);
    msg.setContentTypeFinal(contentType);
    msg.setCreationTimeUTC(date);
    // assert
    assertEquals(type, msg.getMessageType());
    assertEquals(correlationId, msg.getCorrelationId());
    assertEquals(messageId, msg.getMessageId());
    assertEquals(iotHubConnectionString, msg.getIotHubConnectionString());
    assertEquals(userId, msg.getUserId());
    assertEquals(connectionDeviceId, msg.getConnectionDeviceId());
    assertEquals(connectionModuleId, msg.getConnectionModuleId());
    assertEquals(inputName, msg.getInputName());
    assertEquals(outputName, msg.getOutputName());
    assertEquals(contentEncoding, msg.getContentEncoding());
    assertEquals(contentType, msg.getContentType());
    assertEquals(date, msg.getCreationTimeUTC());
    assertNull(msg.getTo());
    assertNull(msg.getDeliveryAcknowledgement());
}
Also used : Message(com.microsoft.azure.sdk.iot.device.Message) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) MessageType(com.microsoft.azure.sdk.iot.device.MessageType) Date(java.util.Date) Test(org.junit.Test)

Example 2 with MessageType

use of com.microsoft.azure.sdk.iot.device.MessageType in project azure-iot-sdk-java by Azure.

the class IotHubTransportMessageTest method constructorWithPropertiesSavesProperties.

// Tests_SRS_IOTHUBTRANSPORTMESSAGE_34_017: [This constructor shall return an instance of IotHubTransportMessage with provided bytes, messagetype, correlationid, messageid, and application properties.]
@Test
public void constructorWithPropertiesSavesProperties() {
    // arrange
    byte[] expectedData = new byte[] { 12, 34, 56 };
    MessageType expectedMessageType = MessageType.DEVICE_TELEMETRY;
    String expectedCorrelationId = "1234";
    String expectedMessageId = "5678";
    MessageProperty[] expectedProperties = new MessageProperty[2];
    expectedProperties[0] = new MessageProperty("bob", "job");
    expectedProperties[1] = new MessageProperty("john", "bill");
    // act
    IotHubTransportMessage transportMessage = new IotHubTransportMessage(expectedData, expectedMessageType, expectedMessageId, expectedCorrelationId, expectedProperties);
    // assert
    assertArrayEquals(expectedData, transportMessage.getBytes());
    assertEquals(expectedMessageType, transportMessage.getMessageType());
    assertEquals(expectedMessageId, transportMessage.getMessageId());
    assertEquals(expectedCorrelationId, transportMessage.getCorrelationId());
    assertEquals(expectedProperties.length, transportMessage.getProperties().length);
}
Also used : MessageProperty(com.microsoft.azure.sdk.iot.device.MessageProperty) IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) MessageType(com.microsoft.azure.sdk.iot.device.MessageType) Test(org.junit.Test)

Example 3 with MessageType

use of com.microsoft.azure.sdk.iot.device.MessageType in project azure-iot-sdk-java by Azure.

the class IotHubTransportMessageTest method setVersionSetsTheVersion.

/*
    **Tests_SRS_IOTHUBTRANSPORTMESSAGE_12_004: [**The function shall set the version.**]**
     */
@Test
public void setVersionSetsTheVersion() {
    // arrange
    String versionStr = "abcdefg";
    byte[] data = new byte[1];
    MessageType messageType = MessageType.DEVICE_TWIN;
    IotHubTransportMessage iotHubTransportMessage = new IotHubTransportMessage(data, messageType);
    // act
    iotHubTransportMessage.setVersion(versionStr);
    // assert
    assertEquals(versionStr, iotHubTransportMessage.getVersion());
}
Also used : IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) MessageType(com.microsoft.azure.sdk.iot.device.MessageType) Test(org.junit.Test)

Example 4 with MessageType

use of com.microsoft.azure.sdk.iot.device.MessageType in project azure-iot-sdk-java by Azure.

the class IotHubTransportMessageTest method getOperationTypeGetsTheOperationType.

/*
     **Tests_SRS_IOTHUBTRANSPORTMESSAGE_12_011: [**The function shall return the operation type either set by the setter or the default if unset so far.**]**
     */
@Test
public void getOperationTypeGetsTheOperationType() {
    // arrange
    DeviceOperations deviceOperations = DeviceOperations.DEVICE_OPERATION_TWIN_GET_REQUEST;
    byte[] data = new byte[1];
    MessageType messageType = MessageType.DEVICE_TWIN;
    IotHubTransportMessage iotHubTransportMessage = new IotHubTransportMessage(data, messageType);
    iotHubTransportMessage.setDeviceOperationType(deviceOperations);
    // act
    DeviceOperations operationType = iotHubTransportMessage.getDeviceOperationType();
    // assert
    assertEquals(deviceOperations, operationType);
}
Also used : DeviceOperations(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations) IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) MessageType(com.microsoft.azure.sdk.iot.device.MessageType) Test(org.junit.Test)

Example 5 with MessageType

use of com.microsoft.azure.sdk.iot.device.MessageType in project azure-iot-sdk-java by Azure.

the class IotHubTransportMessageTest method setOperationTypeSetsTheOperationType.

/*
     **Tests_SRS_IOTHUBTRANSPORTMESSAGE_12_010: [**The function shall save the device twin operation type.**]**
     */
@Test
public void setOperationTypeSetsTheOperationType() {
    // arrange
    DeviceOperations deviceOperations = DeviceOperations.DEVICE_OPERATION_TWIN_GET_REQUEST;
    byte[] data = new byte[1];
    MessageType messageType = MessageType.DEVICE_TWIN;
    IotHubTransportMessage iotHubTransportMessage = new IotHubTransportMessage(data, messageType);
    // act
    iotHubTransportMessage.setDeviceOperationType(deviceOperations);
    // assert
    assertEquals(deviceOperations, iotHubTransportMessage.getDeviceOperationType());
}
Also used : DeviceOperations(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations) IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) MessageType(com.microsoft.azure.sdk.iot.device.MessageType) Test(org.junit.Test)

Aggregations

MessageType (com.microsoft.azure.sdk.iot.device.MessageType)15 IotHubTransportMessage (com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage)14 Test (org.junit.Test)14 DeviceOperations (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations)3 IotHubConnectionString (com.microsoft.azure.sdk.iot.device.IotHubConnectionString)1 Message (com.microsoft.azure.sdk.iot.device.Message)1 MessageProperty (com.microsoft.azure.sdk.iot.device.MessageProperty)1 Date (java.util.Date)1