Search in sources :

Example 1 with ConfigurationContent

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();
}
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 ConfigurationContent

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

Example 3 with ConfigurationContent

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);
}
Also used : IotHubBadFormatException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubBadFormatException) HashMap(java.util.HashMap) Device(com.microsoft.azure.sdk.iot.service.Device) 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)

Example 4 with ConfigurationContent

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));
}
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)

Example 5 with ConfigurationContent

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

Aggregations

ConfigurationContent (com.microsoft.azure.sdk.iot.service.ConfigurationContent)6 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 Configuration (com.microsoft.azure.sdk.iot.service.Configuration)2 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)2 Map (java.util.Map)2 IntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest)2 ContinuousIntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)2 IotHubTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest)2 StandardTierHubOnlyTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest)2 ConfigurationContentParser (com.microsoft.azure.sdk.iot.deps.serializer.ConfigurationContentParser)1 Device (com.microsoft.azure.sdk.iot.service.Device)1 RegistryManager (com.microsoft.azure.sdk.iot.service.RegistryManager)1 IotHubBadFormatException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubBadFormatException)1 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)1 IOException (java.io.IOException)1