Search in sources :

Example 1 with Configuration

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

Example 2 with Configuration

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

Example 3 with Configuration

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

Example 4 with Configuration

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

Example 5 with Configuration

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));
}
Also used : Configuration(com.microsoft.azure.sdk.iot.service.Configuration) HashMap(java.util.HashMap) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) ConfigurationContent(com.microsoft.azure.sdk.iot.service.ConfigurationContent) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest) IotHubTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest) IntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) Test(org.junit.Test)

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