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