use of com.microsoft.azure.sdk.iot.service.ConfigurationContent in project azure-iot-sdk-java by Azure.
the class ConfigurationManangerSample method AddConfiguration.
private static void AddConfiguration() throws Exception {
RegistryManager registryManager = RegistryManager.createFromConnectionString(SampleUtils.iotHubConnectionString);
ConfigurationContent content = new ConfigurationContent();
content.setDeviceContent(DEVICE_CONTENT_SAMPLE);
Configuration config = new Configuration(SampleUtils.configurationId);
config.setContent(content);
config.getMetrics().setQueries(new HashMap<String, String>() {
{
put("waterSettingsPending", "SELECT deviceId FROM devices WHERE properties.reported.chillerWaterSettings.status='pending'");
}
});
config.setTargetCondition("properties.reported.chillerProperties.model='4000x'");
config.setPriority(20);
try {
config = registryManager.addConfiguration(config);
System.out.println("Add configuration " + config.getId() + " succeeded.");
printConfiguration(config);
} catch (IotHubException | IOException iote) {
iote.printStackTrace();
}
registryManager.close();
}
use of com.microsoft.azure.sdk.iot.service.ConfigurationContent in project azure-iot-sdk-java by Azure.
the class ConfigurationContentTest method constructor_initialize.
// Tests_SRS_SERVICE_SDK_JAVA_CONFIGURATION_METRICS_28_001: [The constructor shall initialize results and queries fields.]
@Test
public void constructor_initialize() {
// Act
ConfigurationContent cm = new ConfigurationContent();
// Assert
Assert.assertNotNull(cm);
Assert.assertNotNull(cm.getModulesContent());
Assert.assertNotNull(cm.getDeviceContent());
}
use of com.microsoft.azure.sdk.iot.service.ConfigurationContent 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 com.microsoft.azure.sdk.iot.service.ConfigurationContent 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 com.microsoft.azure.sdk.iot.service.ConfigurationContent in project azure-iot-sdk-java by Azure.
the class ConfigurationContentTest method getterAndSetter.
// Tests_SRS_SERVICE_SDK_JAVA_CONFIGURATION_CONTENT_28_002: [The ConfigurationContent class shall have the following properties: modulesContent and deviceContent
@Test
public void getterAndSetter() {
// arrange
Map<String, Map<String, Object>> mc = new HashMap<String, Map<String, Object>>() {
{
put("mproperty", new HashMap<String, Object>() {
{
put("abc", "123");
put("cde", "456");
}
});
}
};
Map<String, Object> dc = new HashMap<String, Object>() {
{
put("dproperty", new HashMap<String, Integer>() {
{
put("c", 3);
put("d", 4);
}
});
}
};
ConfigurationContent cc = new ConfigurationContent();
// Act
cc.setDeviceContent(dc);
cc.setModulesContent(mc);
// Assert
Assert.assertNotNull(cc);
Map<String, Object> moduleContentMap = (cc.getModulesContent().get("mproperty"));
assertEquals("123", moduleContentMap.get("abc"));
assertEquals("456", moduleContentMap.get("cde"));
Map<String, Object> deviceContentMap = ((Map<String, Object>) (cc.getDeviceContent().get("dproperty")));
assertEquals(3, deviceContentMap.get("c"));
assertEquals(4, deviceContentMap.get("d"));
}
Aggregations