use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class AmqpReceiveTest method receive_with_timout_zero_call_flow_ok.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPRECEIVE_12_005: [The function shall initialize the Proton reactor object]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPRECEIVE_12_006: [The function shall start the Proton reactor object]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPRECEIVE_12_008: [The function shall stop and free the Proton reactor object ]
@Test
public void receive_with_timout_zero_call_flow_ok() throws IOException, InterruptedException {
// Arrange
String hostName = "aaa";
String userName = "bbb";
String sasToken = "ccc";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
int timeoutMs = 0;
AmqpReceive amqpReceive = new AmqpReceive(hostName, userName, sasToken, iotHubServiceClientProtocol);
amqpReceive.open();
// Assert
new Expectations() {
{
reactor = proton.reactor(amqpReceive);
reactor.start();
reactor.stop();
reactor.process();
reactor.free();
}
};
// Act
amqpReceive.receive(timeoutMs);
}
use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class AmqpReceiveTest method receiveWithTimout_non_zero_call_ok.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPRECEIVE_12_005: [The function shall initialize the Proton reactor object]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPRECEIVE_12_006: [The function shall start the Proton reactor object]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPRECEIVE_12_008: [The function shall stop and free the Proton reactor object ]
@Test
public void receiveWithTimout_non_zero_call_ok() throws IOException, InterruptedException {
// Arrange
String hostName = "aaa";
String userName = "bbb";
String sasToken = "ccc";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
int timeoutMs = 1;
AmqpReceive amqpReceive = new AmqpReceive(hostName, userName, sasToken, iotHubServiceClientProtocol);
amqpReceive.open();
// Assert
new Expectations() {
{
reactor = proton.reactor(amqpReceive);
reactor.start();
reactor.stop();
reactor.process();
reactor.free();
}
};
// Act
amqpReceive.receive(timeoutMs);
}
use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class AmqpSendHandlerTest method constructor_copies_params_to_members.
// Test_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_001: [The constructor shall copy all input parameters to private member variables for event processing]
// Test_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_002: [The constructor shall concatenate the host name with the port]
// Test_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_003: [The constructor shall initialize a new Handshaker (Proton) object to handle communication handshake]
@Test
public void constructor_copies_params_to_members() {
// Arrange
String hostName = "aaa";
String userName = "bbb";
String sasToken = "ccc";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
new Expectations() {
{
handshaker = new Handshaker();
}
};
// Act
AmqpSendHandler amqpSendHandler = new AmqpSendHandler(hostName, userName, sasToken, iotHubServiceClientProtocol);
String _hostName = Deencapsulation.getField(amqpSendHandler, "hostName");
String _userName = Deencapsulation.getField(amqpSendHandler, "userName");
String _sasToken = Deencapsulation.getField(amqpSendHandler, "sasToken");
IotHubServiceClientProtocol _ioIotHubServiceClientProtocol = Deencapsulation.getField(amqpSendHandler, "iotHubServiceClientProtocol");
// Assert
assertEquals(hostName + ":5671", _hostName);
assertEquals(userName, _userName);
assertEquals(sasToken, _sasToken);
assertEquals(iotHubServiceClientProtocol, _ioIotHubServiceClientProtocol);
}
use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class AmqpSendHandlerTest method onConnectionInit_creates_Session_and_open_Connection.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_011: [The event handler shall set the host name on the connection]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_012: [The event handler shall create a Session (Proton) object from the connection]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_013: [The event handler shall create a Sender (Proton) object and set the protocol tag on it to a predefined constant]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_014: [The event handler shall open the Connection, the Session and the Sender object]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_15_023: [The Sender object shall have the properties set to service client version identifier.]
@Test
public void onConnectionInit_creates_Session_and_open_Connection() {
// Arrange
String hostName = "aaa";
String userName = "bbb";
String sasToken = "ccc";
String hostAddr = hostName + ":5671";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
AmqpSendHandler amqpSendHandler = new AmqpSendHandler(hostName, userName, sasToken, iotHubServiceClientProtocol);
// Assert
new Expectations() {
{
connection = event.getConnection();
connection.setHostname(hostAddr);
session = connection.session();
sender = session.sender(anyString);
connection.open();
session.open();
sender.open();
sender.setProperties((Map<Symbol, Object>) any);
}
};
// Act
amqpSendHandler.onConnectionInit(event);
}
use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class AmqpSendHandlerTest method onLinkInit_call_flow_ok.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_015: [The event handler shall create a new Target (Proton) object using the given endpoint address]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_016: [The event handler shall get the Link (Proton) object and set its target to the created Target (Proton) object]
@Test
public void onLinkInit_call_flow_ok() {
// Arrange
String hostName = "aaa";
String userName = "bbb";
String sasToken = "ccc";
String hostAddr = hostName + ":5671";
String endpoint = "/messages/devicebound";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
AmqpSendHandler amqpSendHandler = new AmqpSendHandler(hostName, userName, sasToken, iotHubServiceClientProtocol);
// Assert
new Expectations() {
{
link = event.getLink();
target = new Target();
target.setAddress(endpoint);
}
};
// Act
amqpSendHandler.onLinkInit(event);
}
Aggregations