Search in sources :

Example 6 with Configuration

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());
}
Also used : Configuration(com.microsoft.azure.sdk.iot.service.Configuration) Test(org.junit.Test)

Example 7 with Configuration

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"));
}
Also used : Configuration(com.microsoft.azure.sdk.iot.service.Configuration) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 8 with Configuration

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();
    }
}
Also used : Configuration(com.microsoft.azure.sdk.iot.service.Configuration) RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) IOException(java.io.IOException) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)

Example 9 with Configuration

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;
}
Also used : Configuration(com.microsoft.azure.sdk.iot.service.Configuration) RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) IOException(java.io.IOException) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)

Example 10 with Configuration

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...");
}
Also used : Configuration(com.microsoft.azure.sdk.iot.service.Configuration)

Aggregations

Configuration (com.microsoft.azure.sdk.iot.service.Configuration)10 Test (org.junit.Test)6 RegistryManager (com.microsoft.azure.sdk.iot.service.RegistryManager)3 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 ConfigurationContent (com.microsoft.azure.sdk.iot.service.ConfigurationContent)2 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)1 IntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest)1 ContinuousIntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)1 IotHubTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest)1 StandardTierHubOnlyTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest)1