Search in sources :

Example 36 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_module_e2e_X509_CA_signed.

@Test
@StandardTierHubOnlyTest
@ContinuousIntegrationTest
public void crud_module_e2e_X509_CA_signed() throws Exception {
    // Arrange
    RegistryManagerTestInstance testInstance = new RegistryManagerTestInstance();
    deleteModuleIfItExistsAlready(testInstance.registryManager, testInstance.deviceId, testInstance.moduleId);
    Device deviceSetup = Device.createFromId(testInstance.deviceId, DeviceStatus.Enabled, null);
    Tools.addDeviceWithRetry(testInstance.registryManager, deviceSetup);
    deleteModuleIfItExistsAlready(testInstance.registryManager, testInstance.deviceId, testInstance.moduleId);
    // -Create-//
    Module moduleAdded = Module.createModule(testInstance.deviceId, testInstance.moduleId, AuthenticationType.CERTIFICATE_AUTHORITY);
    Tools.addModuleWithRetry(testInstance.registryManager, moduleAdded);
    // -Read-//
    Module moduleRetrieved = testInstance.registryManager.getModule(testInstance.deviceId, testInstance.moduleId);
    // -Delete-//
    testInstance.registryManager.removeModule(testInstance.deviceId, testInstance.moduleId);
    testInstance.registryManager.removeDevice(testInstance.deviceId);
    // Assert
    assertEquals(buildExceptionMessage("", hostName), testInstance.deviceId, moduleAdded.getDeviceId());
    assertEquals(buildExceptionMessage("", hostName), testInstance.moduleId, moduleAdded.getId());
    assertEquals(buildExceptionMessage("", hostName), testInstance.deviceId, moduleRetrieved.getDeviceId());
    assertEquals(buildExceptionMessage("", hostName), testInstance.moduleId, moduleRetrieved.getId());
    assertNull(buildExceptionMessage("", hostName), moduleAdded.getPrimaryThumbprint());
    assertNull(buildExceptionMessage("", hostName), moduleAdded.getSecondaryThumbprint());
    assertNull(buildExceptionMessage("", hostName), moduleRetrieved.getPrimaryThumbprint());
    assertNull(buildExceptionMessage("", hostName), moduleRetrieved.getSecondaryThumbprint());
    assertTrue(buildExceptionMessage("", hostName), moduleWasDeletedSuccessfully(testInstance.registryManager, testInstance.deviceId, testInstance.moduleId));
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) Module(com.microsoft.azure.sdk.iot.service.Module) 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) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)

Example 37 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_module_e2e.

@Test
@StandardTierHubOnlyTest
public void crud_module_e2e() throws Exception {
    // Arrange
    RegistryManagerTestInstance testInstance = new RegistryManagerTestInstance();
    SymmetricKey expectedSymmetricKey = new SymmetricKey();
    Device deviceSetup = Device.createFromId(testInstance.deviceId, DeviceStatus.Enabled, null);
    Tools.addDeviceWithRetry(testInstance.registryManager, deviceSetup);
    deleteModuleIfItExistsAlready(testInstance.registryManager, testInstance.deviceId, testInstance.moduleId);
    // -Create-//
    Module moduleAdded = Module.createFromId(testInstance.deviceId, testInstance.moduleId, null);
    Tools.addModuleWithRetry(testInstance.registryManager, moduleAdded);
    // -Read-//
    Module moduleRetrieved = testInstance.registryManager.getModule(testInstance.deviceId, testInstance.moduleId);
    // -Update-//
    Module moduleUpdated = testInstance.registryManager.getModule(testInstance.deviceId, testInstance.moduleId);
    moduleUpdated.getSymmetricKey().setPrimaryKeyFinal(expectedSymmetricKey.getPrimaryKey());
    moduleUpdated = testInstance.registryManager.updateModule(moduleUpdated);
    // -Delete-//
    testInstance.registryManager.removeModule(testInstance.deviceId, testInstance.moduleId);
    testInstance.registryManager.removeDevice(testInstance.deviceId);
    // Assert
    assertEquals(buildExceptionMessage("", hostName), testInstance.deviceId, moduleAdded.getDeviceId());
    assertEquals(buildExceptionMessage("", hostName), testInstance.moduleId, moduleAdded.getId());
    assertEquals(buildExceptionMessage("", hostName), testInstance.deviceId, moduleRetrieved.getDeviceId());
    assertEquals(buildExceptionMessage("", hostName), testInstance.moduleId, moduleRetrieved.getId());
    assertEquals(buildExceptionMessage("", hostName), expectedSymmetricKey.getPrimaryKey(), moduleUpdated.getPrimaryKey());
    assertTrue(buildExceptionMessage("", hostName), moduleWasDeletedSuccessfully(testInstance.registryManager, testInstance.deviceId, testInstance.moduleId));
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) SymmetricKey(com.microsoft.azure.sdk.iot.service.auth.SymmetricKey) Module(com.microsoft.azure.sdk.iot.service.Module) 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 38 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 testUpdateReportedPropertiesWithVersionSucceed.

@Test
@StandardTierHubOnlyTest
public void testUpdateReportedPropertiesWithVersionSucceed() throws IOException, InterruptedException, URISyntaxException, IotHubException {
    // arrange
    createDevice(testInstance.protocol);
    testInstance.deviceTwinWithVersionTestDevice.expectedProperties = new HashSet<>(PROPERTIES);
    // Create the first version of the reported properties.
    testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus = STATUS.UNKNOWN;
    testInstance.deviceTwinWithVersionTestDevice.deviceClient.sendReportedProperties(PROPERTIES);
    Thread.sleep(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB);
    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.IOTHUB_FAILURE) {
            throw new IOException("IoTHub send Http error code");
        }
        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);
    // New values for the reported properties
    final Set<Property> newValues = new HashSet<Property>() {

        {
            add(new Property(PROPERTY_KEY_1, "newValue1"));
            add(new Property(PROPERTY_KEY_2, "newValue2"));
        }
    };
    testInstance.deviceTwinWithVersionTestDevice.expectedProperties = new HashSet<>(newValues);
    testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus = STATUS.UNKNOWN;
    testInstance.deviceTwinWithVersionTestDevice.reportedPropertyVersion = null;
    testInstance.deviceTwinWithVersionTestDevice.receivedProperties = new HashSet<>();
    // act
    testInstance.deviceTwinWithVersionTestDevice.deviceClient.sendReportedProperties(newValues, 2);
    // assert
    // test device client
    Thread.sleep(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB);
    while (testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus == STATUS.UNKNOWN) {
        Thread.sleep(BREATHE_TIME);
    }
    do {
        Thread.sleep(BREATHE_TIME);
        testInstance.deviceTwinWithVersionTestDevice.expectedProperties = new HashSet<>(newValues);
        testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus = STATUS.UNKNOWN;
        testInstance.deviceTwinWithVersionTestDevice.reportedPropertyVersion = null;
        testInstance.deviceTwinWithVersionTestDevice.receivedProperties = new HashSet<>();
        testInstance.deviceTwinWithVersionTestDevice.deviceClient.getDeviceTwin();
        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);
            }
        }
    } while (testInstance.deviceTwinWithVersionTestDevice.reportedPropertyVersion != 3);
    // test service client
    DeviceTwinDevice deviceOnServiceClient = new DeviceTwinDevice(testInstance.deviceTwinWithVersionTestDevice.deviceId);
    testInstance.twinServiceClient.getTwin(deviceOnServiceClient);
    assertEquals(buildExceptionMessage("Expected reported properties version 3 but was " + deviceOnServiceClient.getReportedPropertiesVersion(), testInstance.deviceTwinWithVersionTestDevice.deviceClient), 3, (int) deviceOnServiceClient.getReportedPropertiesVersion());
    Set<Pair> reported = deviceOnServiceClient.getReportedProperties();
    assertSetEquals(newValues, reported);
}
Also used : DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) IOException(java.io.IOException) Property(com.microsoft.azure.sdk.iot.device.DeviceTwin.Property) 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)

Example 39 with StandardTierHubOnlyTest

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

the class GetTwinTests method serviceClientTokenRenewalWithAzureSasCredential.

@Test
@StandardTierHubOnlyTest
public void serviceClientTokenRenewalWithAzureSasCredential() throws Exception {
    if (testInstance.protocol != IotHubClientProtocol.AMQPS || testInstance.clientType != ClientType.DEVICE_CLIENT || testInstance.authenticationType != AuthenticationType.SAS) {
        // This test is for the service client, so no need to rerun it for all the different client types or device protocols
        return;
    }
    super.setUpNewDeviceAndModule();
    IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(iotHubConnectionString);
    IotHubServiceSasToken serviceSasToken = new IotHubServiceSasToken(iotHubConnectionStringObj);
    String sasToken = serviceSasToken.toString();
    AzureSasCredential sasCredential = new AzureSasCredential(sasToken);
    this.testInstance.twinServiceClient = new DeviceTwin(iotHubConnectionStringObj.getHostName(), sasCredential, DeviceTwinClientOptions.builder().httpReadTimeout(HTTP_READ_TIMEOUT).build());
    // add first device just to make sure that the first credential update worked
    super.testGetDeviceTwin();
    // deliberately expire the SAS token to provoke a 401 to ensure that the twin client is using the shared
    // access signature that is set here.
    sasCredential.update(SasTokenTools.makeSasTokenExpired(sasToken));
    try {
        super.testGetDeviceTwin();
        fail("Expected get twin call to throw unauthorized exception since an expired SAS token was used, but no exception was thrown");
    } catch (IotHubUnathorizedException e) {
        log.debug("IotHubUnauthorizedException was thrown as expected, continuing test");
    }
    // Renew the expired shared access signature
    serviceSasToken = new IotHubServiceSasToken(iotHubConnectionStringObj);
    sasCredential.update(serviceSasToken.toString());
    // adding third device should succeed since the shared access signature has been renewed
    super.testGetDeviceTwin();
}
Also used : IotHubServiceSasToken(com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken) AzureSasCredential(com.azure.core.credential.AzureSasCredential) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubUnathorizedException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubUnathorizedException) DeviceTwin(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) IotHubTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) Test(org.junit.Test)

Example 40 with StandardTierHubOnlyTest

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

the class QueryTwinTests method testRawQueryTwinWithAzureSasCredential.

@Test
@StandardTierHubOnlyTest
public void testRawQueryTwinWithAzureSasCredential() throws IOException, InterruptedException, IotHubException, GeneralSecurityException, URISyntaxException, ModuleClientException {
    IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(iotHubConnectionString);
    IotHubServiceSasToken serviceSasToken = new IotHubServiceSasToken(iotHubConnectionStringObj);
    AzureSasCredential sasCredential = new AzureSasCredential(serviceSasToken.toString());
    testInstance.twinServiceClient = new DeviceTwin(iotHubConnectionStringObj.getHostName(), sasCredential);
    testRawQueryTwin();
}
Also used : IotHubServiceSasToken(com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken) AzureSasCredential(com.azure.core.credential.AzureSasCredential) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) DeviceTwin(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin) 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