use of com.microsoft.azure.sdk.iot.service.RegistryManager in project azure-iot-sdk-java by Azure.
the class RegistryManagerTests method getDeviceStatisticsTest.
// TODO what is this testing?
@Test
@ContinuousIntegrationTest
public void getDeviceStatisticsTest() throws Exception {
RegistryManager registryManager = RegistryManager.createFromConnectionString(iotHubConnectionString, RegistryManagerOptions.builder().httpReadTimeout(HTTP_READ_TIMEOUT).build());
Tools.getStatisticsWithRetry(registryManager);
}
use of com.microsoft.azure.sdk.iot.service.RegistryManager in project azure-iot-sdk-java by Azure.
the class RegistryManagerTests method buildRegistryManagerWithAzureSasCredential.
private static RegistryManager buildRegistryManagerWithAzureSasCredential() {
IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(iotHubConnectionString);
IotHubServiceSasToken serviceSasToken = new IotHubServiceSasToken(iotHubConnectionStringObj);
AzureSasCredential azureSasCredential = new AzureSasCredential(serviceSasToken.toString());
RegistryManagerOptions options = RegistryManagerOptions.builder().httpReadTimeout(HTTP_READ_TIMEOUT).build();
return new RegistryManager(iotHubConnectionStringObj.getHostName(), azureSasCredential, options);
}
use of com.microsoft.azure.sdk.iot.service.RegistryManager in project azure-iot-sdk-java by Azure.
the class ServiceClientTests method cloudToDeviceTelemetry.
public void cloudToDeviceTelemetry(boolean withProxy, boolean withPayload, boolean withLargestPayload, boolean withCustomSSLContext, boolean withAzureSasCredential) throws Exception {
// We remove and recreate the device for a clean start
RegistryManager registryManager = RegistryManager.createFromConnectionString(iotHubConnectionString, RegistryManagerOptions.builder().httpReadTimeout(HTTP_READ_TIMEOUT).build());
TestDeviceIdentity testDeviceIdentity = Tools.getTestDevice(iotHubConnectionString, IotHubClientProtocol.AMQPS, AuthenticationType.SAS, false);
Device device = testDeviceIdentity.getDevice();
Device deviceGetBefore = registryManager.getDevice(device.getDeviceId());
// Create service client
ProxyOptions proxyOptions = null;
if (withProxy) {
Proxy testProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(testProxyHostname, testProxyPort));
proxyOptions = new ProxyOptions(testProxy);
}
SSLContext sslContext = null;
if (withCustomSSLContext) {
sslContext = new IotHubSSLContext().getSSLContext();
}
ServiceClientOptions serviceClientOptions = ServiceClientOptions.builder().proxyOptions(proxyOptions).sslContext(sslContext).build();
ServiceClient serviceClient;
if (withAzureSasCredential) {
serviceClient = buildServiceClientWithAzureSasCredential(testInstance.protocol, serviceClientOptions);
} else {
serviceClient = new ServiceClient(iotHubConnectionString, testInstance.protocol, serviceClientOptions);
}
serviceClient.open();
Message message;
if (withPayload) {
if (withLargestPayload) {
message = new Message(LARGEST_PAYLOAD);
} else {
message = new Message(SMALL_PAYLOAD);
}
} else {
message = new Message();
}
serviceClient.send(device.getDeviceId(), message);
Device deviceGetAfter = registryManager.getDevice(device.getDeviceId());
serviceClient.close();
Tools.disposeTestIdentity(testDeviceIdentity, iotHubConnectionString);
// Assert
assertEquals(buildExceptionMessage("", hostName), deviceGetBefore.getDeviceId(), deviceGetAfter.getDeviceId());
assertEquals(buildExceptionMessage("", hostName), 0, deviceGetBefore.getCloudToDeviceMessageCount());
assertEquals(buildExceptionMessage("", hostName), 1, deviceGetAfter.getCloudToDeviceMessageCount());
registryManager.close();
}
use of com.microsoft.azure.sdk.iot.service.RegistryManager 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();
}
use of com.microsoft.azure.sdk.iot.service.RegistryManager in project azure-iot-sdk-java by Azure.
the class RegistryStatisticsTests method gettersSucceeds.
@Test
public void gettersSucceeds(@Mocked RegistryManager mockedRegistryManager) throws IOException, IotHubException {
//arrange
String connectionString = "HostName=aaa.bbb.ccc;SharedAccessKeyName=XXX;SharedAccessKey=YYY";
RegistryManager registryManager = RegistryManager.createFromConnectionString(connectionString);
RegistryStatistics statistics = registryManager.getStatistics();
//act
final long disabledDeviceCount = statistics.getDisabledDeviceCount();
final long enabledDeviceCount = statistics.getEnabledDeviceCount();
final long totalDeviceCount = statistics.getTotalDeviceCount();
//assert
assertEquals(disabledDeviceCount, 0);
assertEquals(enabledDeviceCount, 0);
assertEquals(totalDeviceCount, 0);
}
Aggregations