use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend 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.transport.amqps.AmqpSend in project azure-iot-sdk-java by Azure.
the class AmqpSendTest method constructor_copies_params_to_members_amqps_ws.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSEND_12_002: [The constructor shall copy all input parameters to private member variables for event processing]
@Test
public void constructor_copies_params_to_members_amqps_ws() {
// Arrange
String hostName = "aaa";
String userName = "bbb";
String sasToken = "ccc";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS_WS;
// Act
AmqpSend amqpSend = new AmqpSend(hostName, userName, sasToken, iotHubServiceClientProtocol);
String _hostName = Deencapsulation.getField(amqpSend, "hostName");
String _userName = Deencapsulation.getField(amqpSend, "userName");
String _sasToken = Deencapsulation.getField(amqpSend, "sasToken");
IotHubServiceClientProtocol _ioIotHubServiceClientProtocol = Deencapsulation.getField(amqpSend, "iotHubServiceClientProtocol");
// Assert
assertEquals(hostName, _hostName);
assertEquals(userName, _userName);
assertEquals(sasToken, _sasToken);
assertEquals(iotHubServiceClientProtocol, _ioIotHubServiceClientProtocol);
}
use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend in project azure-iot-sdk-java by Azure.
the class AmqpSendTest method send_throwsIOException_when_open_has_not_been_called.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSEND_12_009: [The event handler shall throw IOException if the send handler object is not initialized]
// Assert
@Test(expected = IOException.class)
public void send_throwsIOException_when_open_has_not_been_called() throws Exception {
// Arrange
String hostName = "aaa";
String userName = "bbb";
String sasToken = "ccc";
String deviceId = "deviceId";
String content = "abcdefghijklmnopqrst";
Message message = new Message(content);
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
AmqpSend amqpSend = new AmqpSend(hostName, userName, sasToken, iotHubServiceClientProtocol);
// Act
amqpSend.send(deviceId, message);
}
use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend in project azure-iot-sdk-java by Azure.
the class AmqpSendTest method constructor_checks_if_hostName_null.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSEND_12_001: [The constructor shall throw IllegalArgumentException if any of the input parameter is null or empty]
// Assert
@Test(expected = IllegalArgumentException.class)
public void constructor_checks_if_hostName_null() {
// Arrange
String hostName = null;
String userName = "bbb";
String sasToken = "ccc";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
// Act
AmqpSend amqpSend = new AmqpSend(hostName, userName, sasToken, iotHubServiceClientProtocol);
}
use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend in project azure-iot-sdk-java by Azure.
the class AmqpSendTest method send_creates_ProtonMessage.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSEND_12_006: [The event handler shall create a Proton message with the given content]
@Test
public void send_creates_ProtonMessage() throws Exception {
// Arrange
String hostName = "aaa";
String userName = "bbb";
String sasToken = "ccc";
String deviceId = "deviceId";
String content = "abcdefghijklmnopqrst";
Message message = new Message(content);
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
AmqpSend amqpSend = new AmqpSend(hostName, userName, sasToken, iotHubServiceClientProtocol);
amqpSend.open();
AmqpSendHandler handler = Deencapsulation.getField(amqpSend, "amqpSendHandler");
// Assert
new Expectations() {
{
Deencapsulation.invoke(handler, "createProtonMessage", deviceId, message);
}
};
// Act
amqpSend.send(deviceId, message);
}
Aggregations