use of com.microsoft.azure.sdk.iot.device.IotHubEventCallback in project azure-iot-sdk-java by Azure.
the class IotHubCallbackPacketTest method getEventCallbackReturnsCallback.
// Tests_SRS_IOTHUBCALLBACKPACKET_11_001: [The constructor shall save the status, eventCallback, and callback context.]
// Tests_SRS_IOTHUBCALLBACKPACKET_11_003: [The function shall return the eventCallback given in the constructor.]
@Test
public void getEventCallbackReturnsCallback() {
final IotHubStatusCode status = IotHubStatusCode.HUB_OR_DEVICE_ID_NOT_FOUND;
final Map<String, Object> context = new HashMap<>();
IotHubCallbackPacket packet = new IotHubCallbackPacket(status, mockEventCallback, context);
IotHubEventCallback testCallback = packet.getCallback();
assertThat(testCallback, is(mockEventCallback));
}
use of com.microsoft.azure.sdk.iot.device.IotHubEventCallback in project azure-iot-sdk-java by Azure.
the class IotHubOutboundPacketTest method getCallbackWithMessageReturnsCallback.
// Tests_SRS_IOTHUBOUTBOUNDPACKET_21_005: [The constructor shall save the message, callback, and callback context.]
// Tests_SRS_IOTHUBOUTBOUNDPACKET_11_006: [The function shall return the response callback given in the constructor.]
// Tests_SRS_IOTHUBOUTBOUNDPACKET_21_008: [The constructor shall set the event callback as null.]
@Test
public void getCallbackWithMessageReturnsCallback() {
final Map<String, Object> context = new HashMap<>();
IotHubOutboundPacket packet = new IotHubOutboundPacket(mockMsg, mockResponseCallback, context);
IotHubEventCallback testCallback = packet.getCallback();
IotHubResponseCallback testResponseCallback = packet.getResponseCallback();
final IotHubResponseCallback expectedCallback = mockResponseCallback;
assertThat(testResponseCallback, is(expectedCallback));
assertNull(testCallback);
}
use of com.microsoft.azure.sdk.iot.device.IotHubEventCallback in project azure-iot-sdk-java by Azure.
the class IotHubOutboundPacketTest method getCallbackReturnsCallback.
// Tests_SRS_IOTHUBOUTBOUNDPACKET_11_001: [The constructor shall save the message, callback, and callback context.]
// Tests_SRS_IOTHUBOUTBOUNDPACKET_11_003: [The function shall return the event callback given in the constructor.]
// Tests_SRS_IOTHUBOUTBOUNDPACKET_21_007: [The constructor shall set the response callback as null.]
@Test
public void getCallbackReturnsCallback() {
final Map<String, Object> context = new HashMap<>();
IotHubOutboundPacket packet = new IotHubOutboundPacket(mockMsg, mockCallback, context);
IotHubEventCallback testCallback = packet.getCallback();
IotHubResponseCallback testResponseCallback = packet.getResponseCallback();
final IotHubEventCallback expectedCallback = mockCallback;
assertThat(testCallback, is(expectedCallback));
assertNull(testResponseCallback);
}
use of com.microsoft.azure.sdk.iot.device.IotHubEventCallback in project azure-iot-sdk-java by Azure.
the class FileUploadTest method callbackDeleteFileUploadInProgressThrows.
@Test
public void callbackDeleteFileUploadInProgressThrows(@Mocked final LinkedBlockingDeque<?> mockFileUploadInProgressQueue) throws IOException {
// arrange
final Map<String, Object> context = new HashMap<>();
constructorExpectations();
new NonStrictExpectations() {
{
new LinkedBlockingDeque<>();
result = mockFileUploadInProgressQueue;
mockFileUploadInProgressQueue.remove(mockFileUploadInProgress);
result = new UnsupportedOperationException();
}
};
FileUpload fileUpload = new FileUpload(mockConfig);
IotHubEventCallback testFileUploadStatusCallBack = new FileUploadStatusCallBack();
// act
testFileUploadStatusCallBack.execute(IotHubStatusCode.OK_EMPTY, mockFileUploadInProgress);
// assert
new Verifications() {
{
Deencapsulation.invoke(mockFileUploadInProgress, "triggerCallback", new Class[] { IotHubStatusCode.class }, IotHubStatusCode.OK_EMPTY);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.IotHubEventCallback in project azure-iot-sdk-java by Azure.
the class DigitalTwinClientTests method updateDigitalTwin.
@Test
@StandardTierHubOnlyTest
public void updateDigitalTwin() throws IOException {
// arrange
String newProperty = "currentTemperature";
String newPropertyPath = "/currentTemperature";
Integer newPropertyValue = 35;
// Property update callback
TwinPropertyCallBack twinPropertyCallBack = (property, context) -> {
Set<Property> properties = new HashSet<>();
properties.add(property);
try {
deviceClient.sendReportedProperties(properties);
} catch (IOException e) {
}
};
// IotHub event callback
IotHubEventCallback iotHubEventCallback = (responseStatus, callbackContext) -> {
};
// start device twin and setup handler for property updates in device
deviceClient.startDeviceTwin(iotHubEventCallback, null, twinPropertyCallBack, null);
Map<Property, Pair<TwinPropertyCallBack, Object>> desiredPropertyUpdateCallback = Collections.singletonMap(new Property(newProperty, null), new Pair<>(twinPropertyCallBack, null));
deviceClient.subscribeToTwinDesiredProperties(desiredPropertyUpdateCallback);
DigitalTwinUpdateRequestOptions optionsWithoutEtag = new DigitalTwinUpdateRequestOptions();
optionsWithoutEtag.setIfMatch("*");
// get digital twin and Etag before update
ServiceResponseWithHeaders<BasicDigitalTwin, DigitalTwinGetHeaders> responseWithHeaders = digitalTwinClient.getDigitalTwinWithResponse(deviceId, BasicDigitalTwin.class);
DigitalTwinUpdateRequestOptions optionsWithEtag = new DigitalTwinUpdateRequestOptions();
optionsWithEtag.setIfMatch(responseWithHeaders.headers().eTag());
// act
// Add properties at root level - conditional update with max overload
UpdateOperationUtility updateOperationUtility = new UpdateOperationUtility().appendAddPropertyOperation(newPropertyPath, newPropertyValue);
digitalTwinClient.updateDigitalTwinWithResponse(deviceId, updateOperationUtility.getUpdateOperations(), optionsWithEtag);
BasicDigitalTwin digitalTwin = digitalTwinClient.getDigitalTwinWithResponse(deviceId, BasicDigitalTwin.class).body();
// assert
assertEquals(E2ETestConstants.THERMOSTAT_MODEL_ID, digitalTwin.getMetadata().getModelId());
assertTrue(digitalTwin.getMetadata().getWriteableProperties().containsKey(newProperty));
assertEquals(newPropertyValue, digitalTwin.getMetadata().getWriteableProperties().get(newProperty).getDesiredValue());
}
Aggregations