Пример #1
0
 /** Test of isNullOrEmpty method, of class Tools. Input: null Expected: true */
 @Test
 public void testIsNullOrEmptyInputNull() {
   String value = null;
   Boolean expResult = true;
   Boolean result = Tools.isNullOrEmpty(value);
   assertEquals(expResult, result);
 }
Пример #2
0
 /** Test of isNullOrEmpty method, of class Tools. Input: valid string Expected: true */
 @Test
 public void testIsNullOrEmptyInputNotEmpty() {
   String value = "XXX";
   Boolean expResult = false;
   Boolean result = Tools.isNullOrEmpty(value);
   assertEquals(expResult, result);
 }
Пример #3
0
 /**
  * Create ServiceClient from the specified connection string
  *
  * @param connectionString - Connection string for the IotHub
  * @return
  */
 public static ServiceClient createFromConnectionString(String connectionString) throws Exception {
   if (Tools.isNullOrEmpty(connectionString)) {
     throw new IllegalArgumentException(connectionString);
   }
   IotHubConnectionString iotHubConnectionString =
       IotHubConnectionStringBuilder.createConnectionString(connectionString);
   IotHubServiceClient iotServiceClient = new IotHubServiceClient(iotHubConnectionString);
   return iotServiceClient;
 }
  @Test
  public void service_client_e2e() throws Exception {
    if (Tools.isNullOrEmpty(connectionString)) {
      throw new IllegalArgumentException(
          "Environment variable is not set: " + connectionStringEnvVarName);
    }

    // Arrange

    // We remove and recreate the device for a clean start
    RegistryManager registryManager = RegistryManager.createFromConnectionString(connectionString);

    try {
      registryManager.removeDevice(deviceId);
    } catch (IOException | IotHubException e) {
    }

    Device deviceAdded = Device.createFromId(deviceId);
    registryManager.addDevice(deviceAdded);

    Device deviceGetBefore = registryManager.getDevice(deviceId);

    // Act

    // Create service client
    ServiceClient serviceClient = ServiceClient.createFromConnectionString(connectionString);
    CompletableFuture<Void> futureOpen = serviceClient.openAsync();
    futureOpen.get();

    CompletableFuture<Void> completableFuture = serviceClient.sendAsync(deviceId, message);
    completableFuture.get();

    Device deviceGetAfter = registryManager.getDevice(deviceId);

    CompletableFuture<Void> futureClose = serviceClient.closeAsync();
    futureClose.get();

    registryManager.removeDevice(deviceId);

    // Assert
    assertEquals(deviceGetBefore.getDeviceId(), deviceGetAfter.getDeviceId());
    assertEquals(0, deviceGetBefore.getCloudToDeviceMessageCount());
    assertEquals(1, deviceGetAfter.getCloudToDeviceMessageCount());
  }