use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodData in project azure-iot-sdk-java by Azure.
the class DeviceMethodDataTest method setStatusSets.
/*
**Tests_SRS_DEVICEMETHODDATA_25_007: [**The method shall set the status.**]**
*/
@Test
public void setStatusSets() {
//arrange
DeviceMethodData testData = new DeviceMethodData(0, "testMessage");
//act
testData.setStatus(200);
//assert
int testStatus = testData.getStatus();
assertTrue(testStatus == 200);
}
use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodData in project azure-iot-sdk-java by Azure.
the class DeviceMethodDataTest method constructorSucceeds.
/*
**Tests_SRS_DEVICEMETHODDATA_25_001: [**The constructor shall save the status and reponse message provided by user.**]**
*/
@Test
public void constructorSucceeds() {
//act
DeviceMethodData testData = new DeviceMethodData(0, "testMessage");
//assert
int testStatus = testData.getStatus();
String testResponse = testData.getResponseMessage();
assertTrue(testStatus == 0);
assertEquals(testResponse, "testMessage");
}
use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodData in project azure-iot-sdk-java by Azure.
the class TokenCredentialTests method invokeMethodSucceedWithTokenCredential.
@Test
public void invokeMethodSucceedWithTokenCredential() throws Exception {
// only run tests for standard tier hubs
Assume.assumeFalse(isBasicTierHub);
DeviceMethod methodServiceClient = buildDeviceMethodClientWithTokenCredential();
RegistryManager registryManager = new RegistryManager(iotHubConnectionString);
Device device = Device.createDevice("some-device-" + UUID.randomUUID(), AuthenticationType.SAS);
registryManager.addDevice(device);
DeviceClient deviceClient = new DeviceClient(registryManager.getDeviceConnectionString(device), MQTT);
deviceClient.open();
final int successStatusCode = 200;
final AtomicBoolean methodsSubscriptionComplete = new AtomicBoolean(false);
final AtomicBoolean methodsSubscribedSuccessfully = new AtomicBoolean(false);
deviceClient.subscribeToDeviceMethod((methodName, methodData, context) -> new DeviceMethodData(successStatusCode, "success"), null, (responseStatus, callbackContext) -> {
if (responseStatus == IotHubStatusCode.OK_EMPTY || responseStatus == IotHubStatusCode.OK) {
methodsSubscribedSuccessfully.set(true);
}
methodsSubscriptionComplete.set(true);
}, null);
long startTime = System.currentTimeMillis();
while (!methodsSubscriptionComplete.get()) {
Thread.sleep(200);
if (System.currentTimeMillis() - startTime > METHOD_SUBSCRIPTION_TIMEOUT_MILLISECONDS) {
fail("Timed out waiting for device registration to complete.");
}
}
assertTrue("Method subscription callback fired with non 200 status code", methodsSubscribedSuccessfully.get());
MethodResult result = methodServiceClient.invoke(device.getDeviceId(), "someMethod", 5l, 5l, null);
assertEquals((long) successStatusCode, (long) result.getStatus());
}
use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodData in project azure-iot-sdk-java by Azure.
the class DeviceMethodDataTest method constructorSucceeds.
/*
**Tests_SRS_DEVICEMETHODDATA_25_001: [**The constructor shall save the status and response message provided by user.**]**
*/
@Test
public void constructorSucceeds() {
// act
DeviceMethodData testData = new DeviceMethodData(0, "testMessage");
// assert
int testStatus = testData.getStatus();
String testResponse = testData.getResponseMessage();
assertEquals(0, testStatus);
assertEquals(testResponse, "testMessage");
}
use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodData in project azure-iot-sdk-java by Azure.
the class DeviceMethodDataTest method GetStatusGets.
/*
**Tests_SRS_DEVICEMETHODDATA_25_003: [**This method shall return the status previously set.**]**
*/
@Test
public void GetStatusGets() {
// arrange
DeviceMethodData testData = new DeviceMethodData(0, "testMessage");
// act
int testStatus = testData.getStatus();
// assert
assertEquals(0, testStatus);
}
Aggregations