use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest in project azure-iot-sdk-java by Azure.
the class DigitalTwinClientComponentTests method updateDigitalTwin.
@Test
@StandardTierHubOnlyTest
public void updateDigitalTwin() {
// arrange
String newProperty = "currentTemperature";
Integer newPropertyValue = 35;
String newComponent = "newThermostat";
String newComponentPath = "/newThermostat";
Map<String, Object> componentProperties = new HashMap<>();
componentProperties.put(newProperty, newPropertyValue);
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 component at root level - conditional update with max overload
UpdateOperationUtility updateOperationUtility = new UpdateOperationUtility().appendAddComponentOperation(newComponentPath, componentProperties);
digitalTwinClient.updateDigitalTwinWithResponse(deviceId, updateOperationUtility.getUpdateOperations(), optionsWithEtag);
BasicDigitalTwin digitalTwin = digitalTwinClient.getDigitalTwinWithResponse(deviceId, BasicDigitalTwin.class).body();
// assert
assertEquals(E2ETestConstants.TEMPERATURE_CONTROLLER_MODEL_ID, digitalTwin.getMetadata().getModelId());
assertTrue(digitalTwin.getCustomProperties().containsKey(newComponent));
}
use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest in project azure-iot-sdk-java by Azure.
the class RegistryManagerTests method apply_configuration_e2e.
@Test
@StandardTierHubOnlyTest
public void apply_configuration_e2e() throws Exception {
// Arrange
RegistryManagerTestInstance testInstance = new RegistryManagerTestInstance();
Device deviceSetup = Device.createFromId(testInstance.deviceId, DeviceStatus.Enabled, null);
Tools.addDeviceWithRetry(testInstance.registryManager, deviceSetup);
final HashMap<String, Object> testDeviceContent = new HashMap<String, Object>() {
{
put("properties.desired.chiller-water", new HashMap<String, Object>() {
{
put("temperature", 66);
put("pressure", 28);
}
});
}
};
ConfigurationContent content = new ConfigurationContent();
content.setDeviceContent(testDeviceContent);
boolean expectedExceptionThrown = false;
// Act
try {
testInstance.registryManager.applyConfigurationContentOnDevice(testInstance.deviceId, content);
} catch (IotHubBadFormatException e) {
expectedExceptionThrown = true;
}
assertTrue("Bad format exception wasn't thrown but was expected", expectedExceptionThrown);
}
use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest in project azure-iot-sdk-java by Azure.
the class RegistryManagerTests method crud_adm_configuration_e2e.
@Test
@StandardTierHubOnlyTest
public void crud_adm_configuration_e2e() throws Exception {
// Arrange
RegistryManagerTestInstance testInstance = new RegistryManagerTestInstance();
final HashMap<String, Object> testDeviceContent = new HashMap<String, Object>() {
{
put("properties.desired.chiller-water", new HashMap<String, Object>() {
{
put("temperature", 66);
put("pressure", 28);
}
});
}
};
// -Create-//
Configuration configAdded = new Configuration(testInstance.configId);
ConfigurationContent content = new ConfigurationContent();
content.setDeviceContent(testDeviceContent);
configAdded.setContent(content);
configAdded.getMetrics().setQueries(new HashMap<String, String>() {
{
put("waterSettingsPending", "SELECT deviceId FROM devices WHERE properties.reported.chillerWaterSettings.status=\'pending\'");
}
});
configAdded.setTargetCondition("properties.reported.chillerProperties.model=\'4000x\'");
configAdded.setPriority(20);
testInstance.registryManager.addConfiguration(configAdded);
// -Read-//
Configuration configRetrieved = testInstance.registryManager.getConfiguration(testInstance.configId);
// -Update-//
Configuration configUpdated = testInstance.registryManager.getConfiguration(testInstance.configId);
configUpdated.setPriority(1);
configUpdated = testInstance.registryManager.updateConfiguration(configUpdated);
// -Delete-//
testInstance.registryManager.removeConfiguration(testInstance.configId);
// Assert
assertEquals(buildExceptionMessage("", hostName), testInstance.configId, configAdded.getId());
assertEquals(buildExceptionMessage("", hostName), testInstance.configId, configRetrieved.getId());
String actualString = configRetrieved.getContent().getDeviceContent().get("properties.desired.chiller-water").toString();
actualString = actualString.substring(1, actualString.length() - 1);
String[] keyValuePairs = actualString.split(",");
HashMap<String, String> actualMap = new HashMap<>();
for (String pair : keyValuePairs) {
String[] entry = pair.split("=");
actualMap.put(entry[0].trim(), entry[1].trim());
}
assertEquals(buildExceptionMessage("", hostName), "66.0", actualMap.get("temperature"));
assertEquals(buildExceptionMessage("", hostName), "28.0", actualMap.get("pressure"));
assertEquals(buildExceptionMessage("", hostName), "SELECT deviceId FROM devices WHERE properties.reported.chillerWaterSettings.status=\'pending\'", configRetrieved.getMetrics().getQueries().get("waterSettingsPending"));
assertEquals(buildExceptionMessage("", hostName), "properties.reported.chillerProperties.model=\'4000x\'", configRetrieved.getTargetCondition());
assertEquals(buildExceptionMessage("", hostName), new Integer(20), configRetrieved.getPriority());
assertEquals(buildExceptionMessage("", hostName), testInstance.configId, configUpdated.getId());
assertEquals(buildExceptionMessage("", hostName), new Integer(1), configUpdated.getPriority());
assertTrue(buildExceptionMessage("", hostName), configWasDeletedSuccessfully(testInstance.registryManager, testInstance.configId));
}
use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest in project azure-iot-sdk-java by Azure.
the class ServiceClientTests method feedbackMessageReceiverWithAzureSasCredential.
@Test
@StandardTierHubOnlyTest
public void feedbackMessageReceiverWithAzureSasCredential() throws Exception {
RegistryManager registryManager = RegistryManager.createFromConnectionString(iotHubConnectionString, RegistryManagerOptions.builder().httpReadTimeout(HTTP_READ_TIMEOUT).build());
IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(iotHubConnectionString);
IotHubServiceSasToken serviceSasToken = new IotHubServiceSasToken(iotHubConnectionStringObj);
AzureSasCredential sasTokenProvider = new AzureSasCredential(serviceSasToken.toString());
ServiceClient serviceClient = new ServiceClient(iotHubConnectionStringObj.getHostName(), sasTokenProvider, testInstance.protocol);
FeedbackReceiver feedbackReceiver = serviceClient.getFeedbackReceiver();
feedbackReceiver.open();
// received feedback message can be ignored since we no longer have any tests that need to consume them
// All this test cares about is that this API doesn't result in an unauthorized exception
feedbackReceiver.receive(2 * 1000);
feedbackReceiver.close();
serviceClient.close();
registryManager.close();
}
use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest in project azure-iot-sdk-java by Azure.
the class DeviceTwinWithVersionTests method testSendReportedPropertiesWithoutVersionSucceed.
@Test
@StandardTierHubOnlyTest
public void testSendReportedPropertiesWithoutVersionSucceed() throws IOException, InterruptedException, URISyntaxException, IotHubException {
// arrange
createDevice(testInstance.protocol);
testInstance.deviceTwinWithVersionTestDevice.expectedProperties = new HashSet<>(PROPERTIES);
testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus = STATUS.UNKNOWN;
// act
testInstance.deviceTwinWithVersionTestDevice.deviceClient.sendReportedProperties(PROPERTIES);
// assert
// test device client
Thread.sleep(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB);
while (testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus == STATUS.UNKNOWN) {
Thread.sleep(BREATHE_TIME);
}
testInstance.deviceTwinWithVersionTestDevice.deviceClient.getDeviceTwin();
long startTime = System.currentTimeMillis();
while (!testInstance.deviceTwinWithVersionTestDevice.expectedProperties.isEmpty()) {
if (System.currentTimeMillis() - startTime > EXPECTED_PROPERTIES_MAX_WAIT_MILLISECONDS) {
fail(buildExceptionMessage("Timed out waiting for expected property change", testInstance.deviceTwinWithVersionTestDevice.deviceClient));
}
Thread.sleep(BREATHE_TIME);
if (testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus == STATUS.BAD_ANSWER) {
throw new IOException(testInstance.deviceTwinWithVersionTestDevice.exception);
}
}
assertEquals(buildExceptionMessage("Expected 2, but reported properties version was " + testInstance.deviceTwinWithVersionTestDevice.reportedPropertyVersion, testInstance.deviceTwinWithVersionTestDevice.deviceClient), 2, (int) testInstance.deviceTwinWithVersionTestDevice.reportedPropertyVersion);
// test service client
DeviceTwinDevice deviceOnServiceClient = new DeviceTwinDevice(testInstance.deviceTwinWithVersionTestDevice.deviceId);
testInstance.twinServiceClient.getTwin(deviceOnServiceClient);
assertEquals(buildExceptionMessage("Expected reported properties version 2 but was " + deviceOnServiceClient.getReportedPropertiesVersion(), testInstance.deviceTwinWithVersionTestDevice.deviceClient), 2, (int) deviceOnServiceClient.getReportedPropertiesVersion());
Set<Pair> reported = deviceOnServiceClient.getReportedProperties();
assertSetEquals(PROPERTIES, reported);
}
Aggregations