use of com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol in project azure-iot-sdk-java by Azure.
the class ServiceClientTest method constructor_input_null.
// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_004: [The constructor shall throw IllegalArgumentException if the input object is null]
// Assert
@Test(expected = IllegalArgumentException.class)
public void constructor_input_null() throws Exception {
// Arrange
IotHubConnectionString iotHubConnectionString = null;
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
// Act
ServiceClient serviceClient = Deencapsulation.newInstance(ServiceClient.class, iotHubConnectionString, iotHubServiceClientProtocol);
}
use of com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol in project azure-iot-sdk-java by Azure.
the class ServiceClientTest method send_sender_null.
// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_0012: [The function shall throw IOException if the member AMQP sender object has not been initialized]
// Assert
@Test(expected = IOException.class)
public void send_sender_null() 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);
Deencapsulation.setField(serviceClient, "amqpMessageSender", null);
// Act
serviceClient.send(deviceId, iotMessage);
}
use of com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol in project azure-iot-sdk-java by Azure.
the class ServiceClientTest method open_call_amqpsender_open.
// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_009: [The function shall call open() on the member AMQP sender object]
@Test
public void open_call_amqpsender_open() 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;
ServiceClient serviceClient = ServiceClient.createFromConnectionString(connectionString, iotHubServiceClientProtocol);
// Assert
new Expectations() {
{
amqpSend.open();
}
};
// Act
serviceClient.open();
}
use of com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol in project azure-iot-sdk-java by Azure.
the class AmqpFileUploadNotificationReceivedHandlerTest method amqpReceiveHandlerEmptySasTokenThrows.
@Test(expected = IllegalArgumentException.class)
public void amqpReceiveHandlerEmptySasTokenThrows() {
// Arrange
final String hostName = "abc";
final String userName = "bbb";
final String sasToken = "";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
// Act
Object amqpReceiveHandler = Deencapsulation.newInstance(AmqpFileUploadNotificationReceivedHandler.class, hostName, userName, sasToken, iotHubServiceClientProtocol, amqpFeedbackReceivedEvent);
}
use of com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol in project azure-iot-sdk-java by Azure.
the class AmqpFileUploadNotificationReceivedHandlerTest method onConnectionInitCallFlowAndInitOk.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_011: [The event handler shall set the host name on the connection]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_012: [The event handler shall create a Session (Proton) object from the connection]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_013: [The event handler shall create a Receiver (Proton) object and set the protocol tag on it to a predefined constant]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_014: [The event handler shall open the Connection, the Session and the Receiver object]
// Tests_SRS_SERVICE_SDK_JAVA_AmqpFileUploadNotificationReceivedHandler_15_017: [The Receiver object shall have the properties set to service client version identifier.]
@Test
public void onConnectionInitCallFlowAndInitOk() {
// Arrange
final String hostName = "aaa";
final String userName = "bbb";
final String sasToken = "ccc";
final String hostAddr = hostName + ":5671";
final String receiver_tag = "filenotificationreceiver";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
Object amqpReceiveHandler = Deencapsulation.newInstance(AmqpFileUploadNotificationReceivedHandler.class, hostName, userName, sasToken, iotHubServiceClientProtocol, amqpFeedbackReceivedEvent);
// Assert
new Expectations() {
{
connection = event.getConnection();
connection.setHostname(hostAddr);
session = connection.session();
receiver = session.receiver(receiver_tag);
connection.open();
session.open();
receiver.open();
receiver.setProperties((Map<Symbol, Object>) any);
}
};
// Act
Deencapsulation.invoke(amqpReceiveHandler, "onConnectionInit", event);
}
Aggregations