use of com.microsoft.azure.sdk.iot.service.Configuration 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.Configuration in project azure-iot-sdk-java by Azure.
the class ConfigurationTest method constructor_initialize_properties.
// Tests_SRS_SERVICE_SDK_JAVA_MODULE_28_002: [The constructor shall initialize all properties to default values]
@Test
public void constructor_initialize_properties() {
// Arrange
String utcTimeDefault = "0001-01-01T00:00:00";
String configurationId = "xxx-configuration";
// Act
Configuration config = Deencapsulation.newInstance(Configuration.class, configurationId);
// Assert
assertNotEquals(null, config);
assertEquals(configurationId, config.getId());
assertEquals("1.0", config.getSchemaVersion());
assertNotNull(config.getMetrics());
assertEquals("", config.getEtag());
assertEquals(utcTimeDefault, config.getCreatedTimeUtc());
assertEquals(utcTimeDefault, config.getLastUpdatedTimeUtc());
}
use of com.microsoft.azure.sdk.iot.service.Configuration in project azure-iot-sdk-java by Azure.
the class ConfigurationTest method conversionToConfigurationParser.
// Tests_SRS_SERVICE_SDK_JAVA_CONFIGURATION_28_004: [This method shall return a new instance of a ConfigurationParser
// object that is populated using the properties of this.]
@Test
public void conversionToConfigurationParser() {
// arrange
String expectedConfigId = "configuration";
String expectedSchemaVersion = "2.0";
String expectedETag = "1234";
String expectedLastUpdatedTimeUtc = "2001-09-09T09:09:09";
String expectedCreatedTimeUtc = "2001-09-09T09:09:09";
String expectedTargetCondition = "*";
Integer expectedPriority = 100;
HashMap<String, String> expectedLabels = new HashMap<String, String>() {
{
put("label1", "val1");
}
};
Configuration config = Deencapsulation.newInstance(Configuration.class, expectedConfigId);
Deencapsulation.setField(config, "schemaVersion", expectedSchemaVersion);
Deencapsulation.setField(config, "createdTimeUtc", expectedCreatedTimeUtc);
Deencapsulation.setField(config, "lastUpdatedTimeUtc", expectedLastUpdatedTimeUtc);
config.setEtag(expectedETag);
config.setTargetCondition(expectedTargetCondition);
config.setPriority(expectedPriority);
config.setLabels(expectedLabels);
// act
ConfigurationParser parser = Deencapsulation.invoke(config, "toConfigurationParser");
// assert
assertEquals(expectedConfigId, parser.getId());
assertEquals(ParserUtility.getDateTimeUtc(expectedCreatedTimeUtc), parser.getCreatedTimeUtc());
assertEquals(ParserUtility.getDateTimeUtc(expectedLastUpdatedTimeUtc), parser.getLastUpdatedTimeUtc());
assertEquals(expectedETag, parser.getETag());
assertEquals(expectedPriority, parser.getPriority());
assertEquals(expectedSchemaVersion, parser.getSchemaVersion());
assertEquals(expectedTargetCondition, parser.getTargetCondition());
assertEquals(expectedLabels, parser.getLabels());
}
use of com.microsoft.azure.sdk.iot.service.Configuration in project azure-iot-sdk-java by Azure.
the class ConfigurationTest method config_get_all_properties.
// Tests_SRS_SERVICE_SDK_JAVA_MODULE_28_003: [The Configuration class shall have the following properties: id, schemaVersion,
// labels, content, targetCondition, createdTimeUtc, lastUpdatedTimeUtc, priority, systemMetrics, metrics, etag
@Test
public void config_get_all_properties() {
// Arrange
String configurationId = "xxx-configuration";
// Act
Configuration config = Deencapsulation.newInstance(Configuration.class, configurationId);
// Assert
config.getId();
config.getSchemaVersion();
config.getLabels();
config.getPriority();
config.getContent();
config.getCreatedTimeUtc();
config.getLastUpdatedTimeUtc();
config.getSystemMetrics();
config.getMetrics();
config.getEtag();
config.getTargetCondition();
}
use of com.microsoft.azure.sdk.iot.service.Configuration 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));
}
Aggregations