-
Notifications
You must be signed in to change notification settings - Fork 1
/
AzureDeviceClientManualTest.java
48 lines (41 loc) · 1.9 KB
/
AzureDeviceClientManualTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package no.cantara.realestate.azure.iot;
import no.cantara.config.ApplicationProperties;
import no.cantara.realestate.azure.AzureObservationDistributionClient;
import org.slf4j.Logger;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.slf4j.LoggerFactory.getLogger;
class AzureDeviceClientManualTest {
private static final Logger log = getLogger(AzureDeviceClientManualTest.class);
public static void main(String[] args) throws InterruptedException {
boolean useConfig = true;
AzureDeviceClient deviceClient;
ApplicationProperties config;
if (useConfig) {
config = ApplicationProperties.builder()
.defaults()
.buildAndSetStaticSingleton();
deviceClient = new AzureDeviceClient(config.get(AzureObservationDistributionClient.CONNECTIONSTRING_KEY));
} else {
if (args.length < 1) {
log.error("You need to provide \"primary connection string\" from a Device registered in Azure IoTHub.\n" +
"Enter this string as the first argument when running this class.");
System.exit(0);
}
String connectionString = args[0];
log.debug("ConnectionString {}", connectionString);
deviceClient = new AzureDeviceClient(connectionString);
}
deviceClient.openConnection();
assertTrue(deviceClient.isConnectionEstablished());
log.info("Establishing and verifying connection.");
Thread.sleep(500);
if (deviceClient.isConnectionEstablished()) {
log.info("Sleeping for 10 seconds.");
Thread.sleep(10000);
deviceClient.closeConnection();
assertFalse(deviceClient.isConnectionEstablished());
log.info("DONE-Connection is closed.");
}
}
}