Search in sources :

Example 1 with StandardTierHubOnlyTest

use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest in project azure-iot-sdk-java by Azure.

the class DigitalTwinClientComponentTests method updateDigitalTwin.

@Test
@StandardTierHubOnlyTest
public void updateDigitalTwin() {
    // arrange
    String newProperty = "currentTemperature";
    Integer newPropertyValue = 35;
    String newComponent = "newThermostat";
    String newComponentPath = "/newThermostat";
    Map<String, Object> componentProperties = new HashMap<>();
    componentProperties.put(newProperty, newPropertyValue);
    DigitalTwinUpdateRequestOptions optionsWithoutEtag = new DigitalTwinUpdateRequestOptions();
    optionsWithoutEtag.setIfMatch("*");
    // get digital twin and Etag before update
    ServiceResponseWithHeaders<BasicDigitalTwin, DigitalTwinGetHeaders> responseWithHeaders = digitalTwinClient.getDigitalTwinWithResponse(deviceId, BasicDigitalTwin.class);
    DigitalTwinUpdateRequestOptions optionsWithEtag = new DigitalTwinUpdateRequestOptions();
    optionsWithEtag.setIfMatch(responseWithHeaders.headers().eTag());
    // act
    // Add component at root level - conditional update with max overload
    UpdateOperationUtility updateOperationUtility = new UpdateOperationUtility().appendAddComponentOperation(newComponentPath, componentProperties);
    digitalTwinClient.updateDigitalTwinWithResponse(deviceId, updateOperationUtility.getUpdateOperations(), optionsWithEtag);
    BasicDigitalTwin digitalTwin = digitalTwinClient.getDigitalTwinWithResponse(deviceId, BasicDigitalTwin.class).body();
    // assert
    assertEquals(E2ETestConstants.TEMPERATURE_CONTROLLER_MODEL_ID, digitalTwin.getMetadata().getModelId());
    assertTrue(digitalTwin.getCustomProperties().containsKey(newComponent));
}
Also used : UpdateOperationUtility(com.microsoft.azure.sdk.iot.service.digitaltwin.UpdateOperationUtility) BasicDigitalTwin(com.microsoft.azure.sdk.iot.service.digitaltwin.serialization.BasicDigitalTwin) DigitalTwinGetHeaders(com.microsoft.azure.sdk.iot.service.digitaltwin.customized.DigitalTwinGetHeaders) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) IntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) DigitalTwinTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.DigitalTwinTest)

Example 2 with StandardTierHubOnlyTest

use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest 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 3 with StandardTierHubOnlyTest

use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest 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 4 with StandardTierHubOnlyTest

use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest in project azure-iot-sdk-java by Azure.

the class ServiceClientTests method feedbackMessageReceiverWithAzureSasCredential.

@Test
@StandardTierHubOnlyTest
public void feedbackMessageReceiverWithAzureSasCredential() throws Exception {
    RegistryManager registryManager = RegistryManager.createFromConnectionString(iotHubConnectionString, RegistryManagerOptions.builder().httpReadTimeout(HTTP_READ_TIMEOUT).build());
    IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(iotHubConnectionString);
    IotHubServiceSasToken serviceSasToken = new IotHubServiceSasToken(iotHubConnectionStringObj);
    AzureSasCredential sasTokenProvider = new AzureSasCredential(serviceSasToken.toString());
    ServiceClient serviceClient = new ServiceClient(iotHubConnectionStringObj.getHostName(), sasTokenProvider, testInstance.protocol);
    FeedbackReceiver feedbackReceiver = serviceClient.getFeedbackReceiver();
    feedbackReceiver.open();
    // received feedback message can be ignored since we no longer have any tests that need to consume them
    // All this test cares about is that this API doesn't result in an unauthorized exception
    feedbackReceiver.receive(2 * 1000);
    feedbackReceiver.close();
    serviceClient.close();
    registryManager.close();
}
Also used : IotHubServiceSasToken(com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken) AzureSasCredential(com.azure.core.credential.AzureSasCredential) ServiceClient(com.microsoft.azure.sdk.iot.service.ServiceClient) FeedbackReceiver(com.microsoft.azure.sdk.iot.service.FeedbackReceiver) RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) 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 StandardTierHubOnlyTest

use of tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest in project azure-iot-sdk-java by Azure.

the class DeviceTwinWithVersionTests method testSendReportedPropertiesWithoutVersionSucceed.

@Test
@StandardTierHubOnlyTest
public void testSendReportedPropertiesWithoutVersionSucceed() throws IOException, InterruptedException, URISyntaxException, IotHubException {
    // arrange
    createDevice(testInstance.protocol);
    testInstance.deviceTwinWithVersionTestDevice.expectedProperties = new HashSet<>(PROPERTIES);
    testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus = STATUS.UNKNOWN;
    // act
    testInstance.deviceTwinWithVersionTestDevice.deviceClient.sendReportedProperties(PROPERTIES);
    // assert
    // test device client
    Thread.sleep(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB);
    while (testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus == STATUS.UNKNOWN) {
        Thread.sleep(BREATHE_TIME);
    }
    testInstance.deviceTwinWithVersionTestDevice.deviceClient.getDeviceTwin();
    long startTime = System.currentTimeMillis();
    while (!testInstance.deviceTwinWithVersionTestDevice.expectedProperties.isEmpty()) {
        if (System.currentTimeMillis() - startTime > EXPECTED_PROPERTIES_MAX_WAIT_MILLISECONDS) {
            fail(buildExceptionMessage("Timed out waiting for expected property change", testInstance.deviceTwinWithVersionTestDevice.deviceClient));
        }
        Thread.sleep(BREATHE_TIME);
        if (testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus == STATUS.BAD_ANSWER) {
            throw new IOException(testInstance.deviceTwinWithVersionTestDevice.exception);
        }
    }
    assertEquals(buildExceptionMessage("Expected 2, but reported properties version was " + testInstance.deviceTwinWithVersionTestDevice.reportedPropertyVersion, testInstance.deviceTwinWithVersionTestDevice.deviceClient), 2, (int) testInstance.deviceTwinWithVersionTestDevice.reportedPropertyVersion);
    // test service client
    DeviceTwinDevice deviceOnServiceClient = new DeviceTwinDevice(testInstance.deviceTwinWithVersionTestDevice.deviceId);
    testInstance.twinServiceClient.getTwin(deviceOnServiceClient);
    assertEquals(buildExceptionMessage("Expected reported properties version 2 but was " + deviceOnServiceClient.getReportedPropertiesVersion(), testInstance.deviceTwinWithVersionTestDevice.deviceClient), 2, (int) deviceOnServiceClient.getReportedPropertiesVersion());
    Set<Pair> reported = deviceOnServiceClient.getReportedProperties();
    assertSetEquals(PROPERTIES, reported);
}
Also used : DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) IOException(java.io.IOException) Pair(com.microsoft.azure.sdk.iot.service.devicetwin.Pair) 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

StandardTierHubOnlyTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest)45 Test (org.junit.Test)40 IotHubTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest)32 IntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest)31 ContinuousIntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)28 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)19 DigitalTwinTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.DigitalTwinTest)12 AzureSasCredential (com.azure.core.credential.AzureSasCredential)10 IotHubServiceSasToken (com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken)10 DigitalTwinGetHeaders (com.microsoft.azure.sdk.iot.service.digitaltwin.customized.DigitalTwinGetHeaders)9 BasicDigitalTwin (com.microsoft.azure.sdk.iot.service.digitaltwin.serialization.BasicDigitalTwin)9 Device (com.microsoft.azure.sdk.iot.service.Device)8 IOException (java.io.IOException)8 DeviceTwinDevice (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice)7 Pair (com.microsoft.azure.sdk.iot.service.devicetwin.Pair)7 Property (com.microsoft.azure.sdk.iot.device.DeviceTwin.Property)6 DeviceTwin (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin)6 DigitalTwinClient (com.microsoft.azure.sdk.iot.service.digitaltwin.DigitalTwinClient)6 DeviceClient (com.microsoft.azure.sdk.iot.device.DeviceClient)5 ProxyOptions (com.microsoft.azure.sdk.iot.service.ProxyOptions)5