use of com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol in project azure-iot-sdk-java by Azure.
the class ServiceClientTest method createFromConnectionString_input_null.
// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_001: [The constructor shall throw IllegalArgumentException if the input string is empty or null]
// Assert
@Test(expected = IllegalArgumentException.class)
public void createFromConnectionString_input_null() throws Exception {
// Arrange
String connectionString = null;
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
// Act
ServiceClient.createFromConnectionString(connectionString, iotHubServiceClientProtocol);
}
use of com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol in project azure-iot-sdk-java by Azure.
the class ServiceClientTest method constructor_create_sas_token.
// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_005: [The constructor shall create a SAS token object using the IotHubConnectionString]
// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_006: [The constructor shall store connection string, hostname, username and sasToken]
// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_007: [The constructor shall create a new instance of AmqpSend object]
@Test
public void constructor_create_sas_token() throws Exception {
// Arrange
String iotHubName = "IOTHUBNAME";
String hostName = "HOSTNAME";
String sharedAccessKeyName = "ACCESSKEYNAME";
String policyName = "SharedAccessKey";
String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
String connectionString = "HostName=" + hostName + "." + iotHubName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
new Expectations() {
{
iotHubServiceSasToken = new IotHubServiceSasToken(withNotNull());
amqpSend = new AmqpSend(anyString, anyString, anyString, iotHubServiceClientProtocol);
}
};
// Act
ServiceClient serviceClient = ServiceClient.createFromConnectionString(connectionString, iotHubServiceClientProtocol);
// Assert
assertNotEquals(hostName, Deencapsulation.getField(serviceClient, "hostName"));
assertEquals(iotHubConnectionString.getUserString(), Deencapsulation.getField(serviceClient, "userName"));
}
use of com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol in project azure-iot-sdk-java by Azure.
the class ServiceClientTest method send_async_future_return_ok.
// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_016: [The function shall create an async wrapper around the send() function call, handle the return value or delegate exception]
@Test
public void send_async_future_return_ok() throws Exception {
// Arrange
String iotHubName = "IOTHUBNAME";
String hostName = "HOSTNAME";
String sharedAccessKeyName = "ACCESSKEYNAME";
String policyName = "SharedAccessKey";
String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
String connectionString = "HostName=" + hostName + "." + iotHubName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
String deviceId = "XXX";
String content = "HELLO";
Message iotMessage = new Message(content);
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
ServiceClient serviceClient = ServiceClient.createFromConnectionString(connectionString, iotHubServiceClientProtocol);
// Assert
new Expectations() {
{
amqpSend.send(deviceId, iotMessage);
serviceClient.send(deviceId, iotMessage);
}
};
// Act
CompletableFuture<Void> completableFuture = serviceClient.sendAsync(deviceId, iotMessage);
completableFuture.get();
}
use of com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol in project azure-iot-sdk-java by Azure.
the class ServiceClientTest method close_async_future_throw.
// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_015: [The function shall create an async wrapper around the close() function call, handle the return value or delegate exception]
// Assert
@Test(expected = Exception.class)
public void close_async_future_throw() throws Exception {
// Arrange
new MockUp<ServiceClient>() {
@Mock
public void close() throws IOException {
throw new IOException();
}
};
String iotHubName = "IOTHUBNAME";
String hostName = "HOSTNAME";
String sharedAccessKeyName = "ACCESSKEYNAME";
String policyName = "SharedAccessKey";
String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
String connectionString = "HostName=" + hostName + "." + iotHubName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
ServiceClient serviceClient = ServiceClient.createFromConnectionString(connectionString, iotHubServiceClientProtocol);
// Act
CompletableFuture<Void> completableFuture = serviceClient.closeAsync();
completableFuture.get();
}
use of com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol in project azure-iot-sdk-java by Azure.
the class ServiceClientTest method send_async_future_throw.
// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_016: [The function shall create an async wrapper around the send() function call, handle the return value or delegate exception]
// Assert
@Test(expected = Exception.class)
public void send_async_future_throw() throws Exception {
// Arrange
new MockUp<ServiceClient>() {
@Mock
public void send(String deviceId, String message) throws IOException {
throw new IOException();
}
};
String iotHubName = "IOTHUBNAME";
String hostName = "HOSTNAME";
String sharedAccessKeyName = "ACCESSKEYNAME";
String policyName = "SharedAccessKey";
String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
String connectionString = "HostName=" + hostName + "." + iotHubName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
String deviceId = "XXX";
String content = "HELLO";
Message iotMessage = new Message(content);
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
ServiceClient serviceClient = ServiceClient.createFromConnectionString(connectionString, iotHubServiceClientProtocol);
// Act
CompletableFuture<Void> completableFuture = serviceClient.sendAsync(deviceId, iotMessage);
completableFuture.get();
}
Aggregations