use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class AmqpReceiveHandlerTest method onConnectionBound_call_flow_and_init_ok_amqp.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_009: [The event handler shall set the SASL PLAIN authentication on the Transport using the given user name and sas token]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_010: [The event handler shall set ANONYMUS_PEER authentication mode on the domain of the Transport]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_017: [The event handler shall not initialize WebSocket if the protocol is AMQP]
@Test
public void onConnectionBound_call_flow_and_init_ok_amqp() {
// Arrange
final String hostName = "aaa";
final String userName = "bbb";
final String sasToken = "ccc";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
AmqpFeedbackReceivedHandler amqpReceiveHandler = new AmqpFeedbackReceivedHandler(hostName, userName, sasToken, iotHubServiceClientProtocol, null);
// Assert
new Expectations() {
{
connection = event.getConnection();
transport = connection.getTransport();
sasl.plain(anyString, anyString);
sslDomain = Proton.sslDomain();
sslDomain.init(SslDomain.Mode.CLIENT);
sslDomain.setPeerAuthentication(SslDomain.VerifyMode.ANONYMOUS_PEER);
transport.ssl(sslDomain);
}
};
// Act
amqpReceiveHandler.onConnectionBound(event);
}
use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class AmqpFileUploadNotificationReceiveTest method receiveWithTimeoutNonZeroCallOk.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVE_25_005: [The function shall initialize the Proton reactor object]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVE_25_006: [The function shall start the Proton reactor object]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVE_25_008: [The function shall stop and free the Proton reactor object ]
@Test
public void receiveWithTimeoutNonZeroCallOk() throws IOException, InterruptedException {
// Arrange
final String hostName = "aaa";
final String userName = "bbb";
final String sasToken = "ccc";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
int timeoutMs = 1;
AmqpFileUploadNotificationReceive amqpFileUploadNotificationReceive = new AmqpFileUploadNotificationReceive(hostName, userName, sasToken, iotHubServiceClientProtocol);
amqpFileUploadNotificationReceive.open();
// Assert
new Expectations() {
{
reactor = proton.reactor(amqpFileUploadNotificationReceive);
reactor.start();
reactor.stop();
reactor.process();
reactor.free();
}
};
// Act
amqpFileUploadNotificationReceive.receive(timeoutMs);
}
use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class AmqpFileUploadNotificationReceiveTest method receiveWithTimoutZeroCallFlowOk.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVE_25_005: [The function shall initialize the Proton reactor object]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVE_25_006: [The function shall start the Proton reactor object]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVE_25_008: [The function shall stop and free the Proton reactor object ]
@Test
public void receiveWithTimoutZeroCallFlowOk() throws IOException, InterruptedException {
// Arrange
final String hostName = "aaa";
final String userName = "bbb";
final String sasToken = "ccc";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
int timeoutMs = 0;
AmqpFileUploadNotificationReceive amqpFileUploadNotificationReceive = new AmqpFileUploadNotificationReceive(hostName, userName, sasToken, iotHubServiceClientProtocol);
amqpFileUploadNotificationReceive.open();
// Assert
new Expectations() {
{
reactor = proton.reactor(amqpFileUploadNotificationReceive);
reactor.start();
reactor.stop();
reactor.process();
reactor.free();
}
};
// Act
amqpFileUploadNotificationReceive.receive(timeoutMs);
}
use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class AmqpFileUploadNotificationReceivedHandlerTest method onLinkInitCallFlowAndInitOk.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_015: [The event handler shall create a new Target (Proton) object using the given endpoint address]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_016: [The event handler shall get the Link (Proton) object and set its target to the created Target (Proton) object]
@Test
public void onLinkInitCallFlowAndInitOk() {
// Arrange
final String hostName = "aaa";
final String userName = "bbb";
final String sasToken = "ccc";
final String hostAddr = hostName + ":5671";
final String endpoint = "/messages/serviceBound/filenotifications";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
Object amqpReceiveHandler = Deencapsulation.newInstance(AmqpFileUploadNotificationReceivedHandler.class, hostName, userName, sasToken, iotHubServiceClientProtocol, amqpFeedbackReceivedEvent);
// Assert
new Expectations() {
{
link = event.getLink();
link.getName();
result = Deencapsulation.getField(amqpReceiveHandler, "FILE_NOTIFICATION_RECEIVE_TAG");
target = new Target();
target.setAddress(endpoint);
source = new Source();
source.setAddress(endpoint);
link.setTarget(target);
link.setSource(source);
}
};
// Act
Deencapsulation.invoke(amqpReceiveHandler, "onLinkInit", event);
}
use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class AmqpFileUploadNotificationReceivedHandlerTest method onDeliveryCallFlowAndInitOk.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_004: [The event handler shall get the Link, Receiver and Delivery (Proton) objects from the event]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_005: [The event handler shall read the received buffer]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_006: [The event handler shall create a Message (Proton) object from the decoded buffer]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_007: [The event handler shall settle the Delivery with the Accepted outcome ]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_008: [The event handler shall close the Session and Connection (Proton)]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_009: [The event handler shall call the FeedbackReceived callback if it has been initialized]
@Test
public void onDeliveryCallFlowAndInitOk(@Mocked Data mockData) {
// Arrange
final String hostName = "aaa";
final String userName = "bbb";
final String sasToken = "ccc";
final String hostAddr = hostName + ":5671";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
createProtonObjects();
Object amqpReceiveHandler = Deencapsulation.newInstance(AmqpFileUploadNotificationReceivedHandler.class, hostName, userName, sasToken, iotHubServiceClientProtocol, amqpFeedbackReceivedEvent);
// Assert
new Expectations() {
{
event.getLink();
receiver.current();
delivery.isReadable();
delivery.isPartial();
delivery.getLink();
delivery.pending();
byte[] buffer = new byte[1024];
receiver.recv(buffer, 0, buffer.length);
message.decode(withAny(buffer), 0, anyInt);
// send disposition frame and settle the outcome
delivery.disposition(Accepted.getInstance());
delivery.settle();
session = receiver.getSession();
session.close();
connection = session.getConnection();
connection.close();
message.getBody();
result = mockData;
}
};
// Act
Deencapsulation.invoke(amqpReceiveHandler, "onDelivery", event);
}
Aggregations