use of com.microsoft.azure.sdk.iot.device.Message in project azure-iot-sdk-java by Azure.
the class MqttTest method receiveThrowsExceptionWhenConfigurationIsNotSet.
@Test(expected = InvalidParameterException.class)
public void receiveThrowsExceptionWhenConfigurationIsNotSet() throws IOException, MqttException {
//arrange
final byte[] payload = { 0x61, 0x62, 0x63 };
baseConstructorExpectations(false);
new MockUp<MqttMessaging>() {
@Mock
String parseTopic() throws IOException {
return mockParseTopic;
}
@Mock
byte[] parsePayload(String topic) throws IOException {
return null;
}
};
final Mqtt mockMqtt = new MqttMessaging(serverUri, clientId, userName, password, mockIotHubSSLContext);
Deencapsulation.setField(mockMqtt, "info", null);
//act
try {
Message receivedMessage = mockMqtt.receive();
} finally {
testCleanUp(mockMqtt);
}
}
use of com.microsoft.azure.sdk.iot.device.Message in project azure-iot-sdk-java by Azure.
the class MqttTest method receiveSuccess.
/*
**Tests_SRS_Mqtt_25_021: [**This method shall call parseTopic to parse the topic from the recevived Messages queue corresponding to the messaging client's operation.**]**
*/
/*
**Tests_SRS_Mqtt_25_023: [**This method shall call parsePayload to get the message payload from the recevived Messages queue corresponding to the messaging client's operation.**]**
*/
/*
Tests_SRS_Mqtt_25_024: [**This method shall construct new Message with the bytes obtained from parsePayload and return the message.**]**
*/
@Test
public void receiveSuccess() throws IOException, MqttException {
//arrange
final byte[] payload = { 0x61, 0x62, 0x63 };
baseConstructorExpectations(true);
baseConnectExpectation();
new MockUp<MqttMessaging>() {
@Mock
String parseTopic() throws IOException {
return mockParseTopic;
}
@Mock
byte[] parsePayload(String topic) throws IOException {
return payload;
}
};
final Mqtt mockMqtt = new MqttMessaging(serverUri, clientId, userName, password, mockIotHubSSLContext);
try {
new NonStrictExpectations() {
{
mockMqttAsyncClient.isConnected();
result = true;
}
};
Deencapsulation.invoke(mockMqtt, "connect");
//act
Message receivedMessage = mockMqtt.receive();
//assert
byte[] actualPayload = receivedMessage.getBytes();
assertTrue(actualPayload.length == payload.length);
for (int i = 0; i < payload.length; i++) {
assertEquals(actualPayload[i], payload[i]);
}
} finally {
testCleanUp(mockMqtt);
}
}
use of com.microsoft.azure.sdk.iot.device.Message in project azure-iot-sdk-java by Azure.
the class MessageTest method setPropertyRejectsIllegalValue.
// Tests_SRS_MESSAGE_11_031: [If value name contains a character not specified in RFC 2047, the function shall throw an IllegalArgumentException.]
@Test(expected = IllegalArgumentException.class)
public void setPropertyRejectsIllegalValue(@Mocked final MessageProperty mockProperty) {
final byte[] body = { 0x61, 0x62, 0x63 };
final String name = "test-name";
final String invalidValue = "test-value@";
new NonStrictExpectations() {
{
new MessageProperty(name, invalidValue);
result = new IllegalArgumentException();
}
};
Message msg = new Message(body);
msg.setProperty(name, invalidValue);
}
use of com.microsoft.azure.sdk.iot.device.Message in project azure-iot-sdk-java by Azure.
the class MessageTest method setPropertyRejectsNullValue.
// Tests_SRS_MESSAGE_11_029: [If value is null, the function shall throw an IllegalArgumentException.]
@Test(expected = IllegalArgumentException.class)
public void setPropertyRejectsNullValue() {
final byte[] body = { 0x61, 0x62, 0x63 };
final String name = "test-name";
Message msg = new Message(body);
msg.setProperty(name, null);
}
use of com.microsoft.azure.sdk.iot.device.Message in project azure-iot-sdk-java by Azure.
the class MessageTest method getPropertiesReturnsCopyOfProperties.
// Tests_SRS_MESSAGE_11_033: [The function shall return a copy of the message properties.]
@Test
public void getPropertiesReturnsCopyOfProperties(@Mocked final MessageProperty mockProperty) {
final byte[] body = { 0x61, 0x62, 0x63 };
final String name = "test-name";
final String value = "test-value";
final String httpsName = "test-https-name";
new NonStrictExpectations() {
{
new MessageProperty(name, value);
result = mockProperty;
mockProperty.hasSameName(name);
result = true;
mockProperty.getValue();
result = value;
mockProperty.getName();
result = httpsName;
}
};
Message msg = new Message(body);
msg.setProperty(name, value);
MessageProperty[] testProperties = msg.getProperties();
int expectedNumProperties = 1;
assertThat(testProperties.length, is(expectedNumProperties));
assertThat(testProperties[0], is(not(mockProperty)));
}
Aggregations