Search in sources :

Example 11 with StandardTierHubOnlyTest

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

the class TwinTagsTests method testAddTagUpdates.

@Test
@StandardTierHubOnlyTest
public void testAddTagUpdates() throws IOException, InterruptedException, IotHubException, GeneralSecurityException, URISyntaxException, ModuleClientException {
    addMultipleDevices(MAX_DEVICES);
    // Update tag for multiple devices
    for (int i = 0; i < MAX_DEVICES; i++) {
        Set<Pair> tags = new HashSet<>();
        tags.add(new Pair(TAG_KEY + i, TAG_VALUE + i));
        testInstance.devicesUnderTest[i].sCDeviceForTwin.setTags(tags);
        testInstance.twinServiceClient.updateTwin(testInstance.devicesUnderTest[i].sCDeviceForTwin);
        Thread.sleep(DELAY_BETWEEN_OPERATIONS);
        testInstance.devicesUnderTest[i].sCDeviceForTwin.clearTwin();
    }
    // Read updates on multiple devices
    for (int i = 0; i < MAX_DEVICES; i++) {
        testInstance.twinServiceClient.getTwin(testInstance.devicesUnderTest[i].sCDeviceForTwin);
        Thread.sleep(DELAY_BETWEEN_OPERATIONS);
        for (Pair t : testInstance.devicesUnderTest[i].sCDeviceForTwin.getTags()) {
            assertEquals(buildExceptionMessage("unexpected tag key, expected " + TAG_KEY + i + " but was " + t.getKey(), testInstance.testIdentity.getClient()), TAG_KEY + i, t.getKey());
            assertEquals(buildExceptionMessage("Unexpected tag value, expected " + TAG_VALUE + i + " but was " + t.getValue(), testInstance.testIdentity.getClient()), TAG_VALUE + i, t.getValue());
        }
    }
}
Also used : Pair(com.microsoft.azure.sdk.iot.service.devicetwin.Pair) HashSet(java.util.HashSet) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) IotHubTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest) Test(org.junit.Test) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest)

Example 12 with StandardTierHubOnlyTest

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

the class TwinTagsTests method testUpdateTagUpdates.

@Test
@StandardTierHubOnlyTest
public void testUpdateTagUpdates() throws IOException, InterruptedException, IotHubException, GeneralSecurityException, URISyntaxException, ModuleClientException {
    addMultipleDevices(MAX_DEVICES);
    // Add tag for multiple devices
    for (int i = 0; i < MAX_DEVICES; i++) {
        Set<Pair> tags = new HashSet<>();
        tags.add(new Pair(TAG_KEY + i, TAG_VALUE + i));
        testInstance.devicesUnderTest[i].sCDeviceForTwin.setTags(tags);
        testInstance.twinServiceClient.updateTwin(testInstance.devicesUnderTest[i].sCDeviceForTwin);
        testInstance.devicesUnderTest[i].sCDeviceForTwin.clearTwin();
    }
    // Update Tags on multiple devices
    for (int i = 0; i < MAX_DEVICES; i++) {
        testInstance.twinServiceClient.getTwin(testInstance.devicesUnderTest[i].sCDeviceForTwin);
        Set<Pair> tags = testInstance.devicesUnderTest[i].sCDeviceForTwin.getTags();
        for (Pair tag : tags) {
            tag.setValue(TAG_VALUE_UPDATE + i);
        }
        testInstance.devicesUnderTest[i].sCDeviceForTwin.setTags(tags);
        testInstance.twinServiceClient.updateTwin(testInstance.devicesUnderTest[i].sCDeviceForTwin);
        testInstance.devicesUnderTest[i].sCDeviceForTwin.clearTwin();
    }
    // Read updates on multiple devices
    for (int i = 0; i < MAX_DEVICES; i++) {
        testInstance.twinServiceClient.getTwin(testInstance.devicesUnderTest[i].sCDeviceForTwin);
        for (Pair t : testInstance.devicesUnderTest[i].sCDeviceForTwin.getTags()) {
            assertEquals(buildExceptionMessage("unexpected tag key, expected " + TAG_KEY + i + " but was " + t.getKey(), testInstance.testIdentity.getClient()), TAG_KEY + i, t.getKey());
            assertEquals(buildExceptionMessage("Unexpected tag value, expected " + TAG_VALUE + i + " but was " + t.getValue(), testInstance.testIdentity.getClient()), TAG_VALUE_UPDATE + i, t.getValue());
        }
    }
    // Delete tags
    for (int i = 0; i < MAX_DEVICES; i++) {
        testInstance.twinServiceClient.getTwin(testInstance.devicesUnderTest[i].sCDeviceForTwin);
        Set<Pair> tags = testInstance.devicesUnderTest[i].sCDeviceForTwin.getTags();
        for (Pair tag : tags) {
            tag.setValue(null);
        }
        testInstance.devicesUnderTest[i].sCDeviceForTwin.setTags(tags);
        testInstance.twinServiceClient.updateTwin(testInstance.devicesUnderTest[i].sCDeviceForTwin);
        testInstance.devicesUnderTest[i].sCDeviceForTwin.clearTwin();
    }
    // Verify tags were deleted successfully
    for (int i = 0; i < MAX_DEVICES; i++) {
        testInstance.twinServiceClient.getTwin(testInstance.devicesUnderTest[i].sCDeviceForTwin);
        assertEquals(buildExceptionMessage("Tags were not deleted by being set null", testInstance.testIdentity.getClient()), 0, testInstance.devicesUnderTest[i].sCDeviceForTwin.getTags().size());
    }
}
Also used : Pair(com.microsoft.azure.sdk.iot.service.devicetwin.Pair) HashSet(java.util.HashSet) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) IotHubTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest) Test(org.junit.Test) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest)

Example 13 with StandardTierHubOnlyTest

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

the class ProvisioningTests method groupEnrollmentReprovisioningCanKeepTwin.

@Test
@StandardTierHubOnlyTest
public void groupEnrollmentReprovisioningCanKeepTwin() throws Exception {
    ReprovisionPolicy reprovisionPolicy = new ReprovisionPolicy();
    reprovisionPolicy.setMigrateDeviceData(true);
    reprovisionPolicy.setUpdateHubAssignment(true);
    DeviceCapabilities deviceCapabilities = new DeviceCapabilities();
    deviceCapabilities.setIotEdge(true);
    reprovisioningFlow(EnrollmentType.GROUP, null, reprovisionPolicy, null, getStartingHubs(), getHubsToReprovisionTo(), deviceCapabilities);
}
Also used : DeviceCapabilities(com.microsoft.azure.sdk.iot.deps.twin.DeviceCapabilities) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) Test(org.junit.Test) DeviceProvisioningServiceTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.DeviceProvisioningServiceTest)

Example 14 with StandardTierHubOnlyTest

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

the class DigitalTwinClientTests method getMultiplexedDigitalTwinsRegisteredBeforeOpen.

// Open a multiplexed connection with two devices, each with a different model Id. Verify that their reported twin has
// the expected model Ids.
@Test
@StandardTierHubOnlyTest
public void getMultiplexedDigitalTwinsRegisteredBeforeOpen() throws IotHubException, IOException, URISyntaxException, MultiplexingClientException, InterruptedException {
    if (protocol == MQTT || protocol == MQTT_WS) {
        // multiplexing isn't supported over MQTT, so it can't be tested
        return;
    }
    MultiplexingClient multiplexingClient = new MultiplexingClient(deviceClient.getConfig().getIotHubHostname(), protocol);
    List<DeviceClient> multiplexedDeviceClients = new ArrayList<>();
    multiplexedDeviceClients.add(createDeviceClient(protocol, E2ETestConstants.THERMOSTAT_MODEL_ID));
    multiplexedDeviceClients.add(createDeviceClient(protocol, E2ETestConstants.TEMPERATURE_CONTROLLER_MODEL_ID));
    // register the devices before the multiplexing client has been opened
    multiplexingClient.registerDeviceClients(multiplexedDeviceClients);
    multiplexingClient.open();
    // act
    String thermostatDeviceId = multiplexedDeviceClients.get(0).getConfig().getDeviceId();
    BasicDigitalTwin thermostatResponse = digitalTwinClient.getDigitalTwin(thermostatDeviceId, BasicDigitalTwin.class);
    ServiceResponseWithHeaders<BasicDigitalTwin, DigitalTwinGetHeaders> thermostatResponseWithHeaders = digitalTwinClient.getDigitalTwinWithResponse(thermostatDeviceId, BasicDigitalTwin.class);
    String temperatureControllerDeviceId = multiplexedDeviceClients.get(1).getConfig().getDeviceId();
    BasicDigitalTwin temperatureControllerResponse = digitalTwinClient.getDigitalTwin(temperatureControllerDeviceId, BasicDigitalTwin.class);
    ServiceResponseWithHeaders<BasicDigitalTwin, DigitalTwinGetHeaders> temperatureControllerResponseWithHeaders = digitalTwinClient.getDigitalTwinWithResponse(temperatureControllerDeviceId, BasicDigitalTwin.class);
    // assert
    assertEquals(thermostatResponse.getMetadata().getModelId(), E2ETestConstants.THERMOSTAT_MODEL_ID);
    assertEquals(thermostatResponseWithHeaders.body().getMetadata().getModelId(), E2ETestConstants.THERMOSTAT_MODEL_ID);
    assertEquals(temperatureControllerResponse.getMetadata().getModelId(), E2ETestConstants.TEMPERATURE_CONTROLLER_MODEL_ID);
    assertEquals(temperatureControllerResponseWithHeaders.body().getMetadata().getModelId(), E2ETestConstants.TEMPERATURE_CONTROLLER_MODEL_ID);
}
Also used : BasicDigitalTwin(com.microsoft.azure.sdk.iot.service.digitaltwin.serialization.BasicDigitalTwin) DeviceClient(com.microsoft.azure.sdk.iot.device.DeviceClient) ArrayList(java.util.ArrayList) DigitalTwinGetHeaders(com.microsoft.azure.sdk.iot.service.digitaltwin.customized.DigitalTwinGetHeaders) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) MultiplexingClient(com.microsoft.azure.sdk.iot.device.MultiplexingClient) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) DigitalTwinTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.DigitalTwinTest) 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 15 with StandardTierHubOnlyTest

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

the class DigitalTwinClientTests method getDigitalTwinWithAzureSasCredential.

@Test
@StandardTierHubOnlyTest
public void getDigitalTwinWithAzureSasCredential() {
    if (protocol != MQTT) {
        // This test is for the service client, so no need to rerun it for all the different device protocols
        return;
    }
    // arrange
    digitalTwinClient = buildDigitalTwinClientWithAzureSasCredential();
    // act
    BasicDigitalTwin response = digitalTwinClient.getDigitalTwin(deviceId, BasicDigitalTwin.class);
    ServiceResponseWithHeaders<BasicDigitalTwin, DigitalTwinGetHeaders> responseWithHeaders = digitalTwinClient.getDigitalTwinWithResponse(deviceId, BasicDigitalTwin.class);
    // assert
    assertEquals(response.getMetadata().getModelId(), E2ETestConstants.THERMOSTAT_MODEL_ID);
    assertEquals(responseWithHeaders.body().getMetadata().getModelId(), E2ETestConstants.THERMOSTAT_MODEL_ID);
}
Also used : 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) DigitalTwinTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.DigitalTwinTest) 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