use of com.microsoft.azure.sdk.iot.device.IotHubStatusCode in project azure-iot-sdk-java by Azure.
the class IotHubStatusCodeTest method getIotHubStatusCodeMapsUnauthorizedCorrectly.
// Tests_SRS_IOTHUBSTATUSCODE_11_001: [The function shall convert the given HTTPS status code to the corresponding IoT Hub status code.]
@Test
public void getIotHubStatusCodeMapsUnauthorizedCorrectly() {
final int httpsStatus = 401;
IotHubStatusCode testStatus = IotHubStatusCode.getIotHubStatusCode(httpsStatus);
final IotHubStatusCode expectedStatus = IotHubStatusCode.UNAUTHORIZED;
assertThat(testStatus, is(expectedStatus));
}
use of com.microsoft.azure.sdk.iot.device.IotHubStatusCode in project azure-iot-sdk-java by Azure.
the class IotHubStatusCodeTest method getIotHubStatusCodeMapsTooManyDevicesCorrectly.
// Tests_SRS_IOTHUBSTATUSCODE_11_001: [The function shall convert the given HTTPS status code to the corresponding IoT Hub status code.]
@Test
public void getIotHubStatusCodeMapsTooManyDevicesCorrectly() {
final int httpsStatus = 403;
IotHubStatusCode testStatus = IotHubStatusCode.getIotHubStatusCode(httpsStatus);
final IotHubStatusCode expectedStatus = IotHubStatusCode.TOO_MANY_DEVICES;
assertThat(testStatus, is(expectedStatus));
}
use of com.microsoft.azure.sdk.iot.device.IotHubStatusCode in project azure-iot-sdk-java by Azure.
the class IotHubStatusCodeTest method getIotHubStatusCodeMapsOkEmptyCorrectly.
// Tests_SRS_IOTHUBSTATUSCODE_11_001: [The function shall convert the given HTTPS status code to the corresponding IoT Hub status code.]
@Test
public void getIotHubStatusCodeMapsOkEmptyCorrectly() {
final int httpsStatus = 204;
IotHubStatusCode testStatus = IotHubStatusCode.getIotHubStatusCode(httpsStatus);
final IotHubStatusCode expectedStatus = IotHubStatusCode.OK_EMPTY;
assertThat(testStatus, is(expectedStatus));
}
use of com.microsoft.azure.sdk.iot.device.IotHubStatusCode in project azure-iot-sdk-java by Azure.
the class MqttIotHubConnection method sendEvent.
/**
* Sends an event message.
*
* @param message the event message.
*
* @return the status code from sending the event message.
*
* @throws IllegalStateException if the MqttIotHubConnection is not open
*/
public IotHubStatusCode sendEvent(Message message) throws IllegalStateException {
synchronized (MQTT_CONNECTION_LOCK) {
// the function shall return status code BAD_FORMAT.]
if (message == null || message.getBytes() == null || ((message.getMessageType() != MessageType.DeviceTwin && message.getMessageType() != MessageType.DeviceMethods) && message.getBytes().length == 0)) {
return IotHubStatusCode.BAD_FORMAT;
}
// the function shall throw an IllegalStateException.]
if (this.state == State.CLOSED) {
throw new IllegalStateException("Cannot send event using a closed MQTT connection");
}
// Codes_SRS_MQTTIOTHUBCONNECTION_15_008: [The function shall send an event message
// to the IoT Hub given in the configuration.]
// Codes_SRS_MQTTIOTHUBCONNECTION_15_011: [If the message was successfully received by the service,
// the function shall return status code OK_EMPTY.]
IotHubStatusCode result = IotHubStatusCode.OK_EMPTY;
try {
// Codes_SRS_MQTTIOTHUBCONNECTION_15_009: [The function shall send the message payload.]
if (message.getMessageType() == MessageType.DeviceMethods) {
this.deviceMethod.start();
this.deviceMethod.send((DeviceMethodMessage) message);
} else if (message.getMessageType() == MessageType.DeviceTwin) {
this.deviceTwin.start();
this.deviceTwin.send((DeviceTwinMessage) message);
} else {
this.deviceMessaging.send(message);
}
}// received by the service, the function shall return status code ERROR.]
catch (Exception e) {
result = IotHubStatusCode.ERROR;
}
return result;
}
}
use of com.microsoft.azure.sdk.iot.device.IotHubStatusCode in project azure-iot-sdk-java by Azure.
the class IotHubCallbackPacketTest method getContextReturnsContext.
// Tests_SRS_IOTHUBCALLBACKPACKET_11_001: [The constructor shall save the status, eventCallback, and callback context.]
// Tests_SRS_IOTHUBCALLBACKPACKET_11_004: [The function shall return the callback context given in the constructor.]
@Test
public void getContextReturnsContext() {
final IotHubStatusCode status = IotHubStatusCode.OK;
final Map<String, Object> context = new HashMap<>();
final String key = "test-key";
final String value = "test-value";
context.put(key, value);
IotHubCallbackPacket packet = new IotHubCallbackPacket(status, mockEventCallback, context);
Map<String, Object> testContext = (Map<String, Object>) packet.getContext();
Set<Map.Entry<String, Object>> testEntrySet = testContext.entrySet();
final Set<Map.Entry<String, Object>> expectedEntrySet = context.entrySet();
assertThat(testEntrySet, everyItem(isIn(expectedEntrySet)));
}
Aggregations