use of com.microsoft.azure.sdk.iot.service.Configuration in project azure-iot-sdk-java by Azure.
the class ConfigurationTest method canSetConfigurationMetrics.
@Test
public void canSetConfigurationMetrics(@Mocked final ConfigurationMetrics mockedConfigurationMetrics) {
Configuration configuration = new Configuration("asdf");
configuration.setMetrics(mockedConfigurationMetrics);
Assert.assertEquals(mockedConfigurationMetrics, configuration.getMetrics());
}
use of com.microsoft.azure.sdk.iot.service.Configuration in project azure-iot-sdk-java by Azure.
the class ConfigurationTest method conversionFromConfigurationParser.
// Tests_SRS_SERVICE_SDK_JAVA_CONFIGURATION_28_005: [This constructor shall create a new Configuration object using the values within the provided parser.]
@Test
public void conversionFromConfigurationParser() {
// arrange
String expectedConfigId = "configuration";
String expectedSchemaVersion = "2.0";
String expectedETag = "1234";
String expectedTargetCondition = "*";
Integer expectedPriority = 100;
HashMap<String, String> expectedLabels = new HashMap<String, String>() {
{
put("label1", "val1");
}
};
// arrange
ConfigurationParser parserCA = new ConfigurationParser();
parserCA.setId(expectedConfigId);
parserCA.setSchemaVersion(expectedSchemaVersion);
parserCA.setETag(expectedETag);
parserCA.setTargetCondition(expectedTargetCondition);
parserCA.setPriority(expectedPriority);
parserCA.setLabels(expectedLabels);
ConfigurationMetricsParser parserMetric = new ConfigurationMetricsParser();
parserMetric.setQueries(new HashMap<String, String>() {
{
put("queryKey", "queryVal");
}
});
parserMetric.setResults(new HashMap<String, Long>() {
{
put("resultKey", 100L);
}
});
parserCA.setMetrics(parserMetric);
ConfigurationMetricsParser parserSystemMetric = new ConfigurationMetricsParser();
parserSystemMetric.setQueries(new HashMap<String, String>() {
{
put("squeryKey", "squeryVal");
}
});
parserSystemMetric.setResults(new HashMap<String, Long>() {
{
put("sresultKey", 101L);
}
});
parserCA.setSystemMetrics(parserSystemMetric);
// act
Configuration configurationCA = Deencapsulation.newInstance(Configuration.class, new Class[] { ConfigurationParser.class }, parserCA);
// assert
assertEquals(expectedConfigId, configurationCA.getId());
assertEquals(expectedSchemaVersion, configurationCA.getSchemaVersion());
assertEquals(expectedETag, configurationCA.getEtag());
assertEquals(expectedTargetCondition, configurationCA.getTargetCondition());
assertEquals(expectedPriority, configurationCA.getPriority());
assertEquals(expectedLabels, parserCA.getLabels());
assertEquals(1, configurationCA.getMetrics().getQueries().size());
assertEquals("queryVal", configurationCA.getMetrics().getQueries().get("queryKey"));
assertEquals(new Long(100), configurationCA.getMetrics().getResults().get("resultKey"));
assertEquals("squeryVal", configurationCA.getSystemMetrics().getQueries().get("squeryKey"));
assertEquals(new Long(101), configurationCA.getSystemMetrics().getResults().get("sresultKey"));
}
use of com.microsoft.azure.sdk.iot.service.Configuration in project azure-iot-sdk-java by Azure.
the class ConfigurationManangerSample method GetAllConfiguration.
private static void GetAllConfiguration() throws Exception {
RegistryManager registryManager = RegistryManager.createFromConnectionString(SampleUtils.iotHubConnectionString);
try {
List<Configuration> configList = registryManager.getConfigurations(20);
System.out.println(configList.size() + " Configurations found");
for (Configuration config : configList) {
System.out.println("Configuration Id: " + config.getId());
}
} catch (IotHubException | IOException iote) {
iote.printStackTrace();
}
}
use of com.microsoft.azure.sdk.iot.service.Configuration in project azure-iot-sdk-java by Azure.
the class ConfigurationManangerSample method GetConfiguration.
private static Configuration GetConfiguration() throws Exception {
RegistryManager registryManager = RegistryManager.createFromConnectionString(SampleUtils.iotHubConnectionString);
Configuration returnConfig = null;
try {
returnConfig = registryManager.getConfiguration(SampleUtils.configurationId);
printConfiguration(returnConfig);
} catch (IotHubException | IOException iote) {
iote.printStackTrace();
}
registryManager.close();
return returnConfig;
}
use of com.microsoft.azure.sdk.iot.service.Configuration in project azure-iot-sdk-java by Azure.
the class ConfigurationManangerSample method main.
/**
* A simple sample for doing CRUD operations
* @param args unused
* @throws Exception If any exception is thrown
*/
public static void main(String[] args) throws Exception {
System.out.println("Starting sample...");
System.out.println("Get All Configuration started");
GetAllConfiguration();
System.out.println("Get All Configuration finished");
System.out.println("=================================");
System.out.println("Add Configuration started");
AddConfiguration();
System.out.println("Add Configuration finished");
System.out.println("=================================");
System.out.println("Get Configuration started");
Configuration config = GetConfiguration();
System.out.println("Get Configuration finished");
System.out.println("=================================");
System.out.println("Update Device started");
UpdateConfiguration(config);
System.out.println("Update Device finished");
System.out.println("=================================");
System.out.println("Remove Device started");
RemoveConfiguration();
System.out.println("Remove Device finished");
System.out.println("Shutting down sample...");
}
Aggregations