use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class AmqpFileUploadNotificationReceivedHandlerTest method onConnectionBoundCallFlowAndInitOkAmqps.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_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_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_010: [The event handler shall set ANONYMUS_PEER authentication mode on the domain of the Transport]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_018: [The event handler shall initialize WebSocket if the protocol is AMQP_WS]
@Test
public void onConnectionBoundCallFlowAndInitOkAmqps() {
// Arrange
final String hostName = "aaa";
final String userName = "bbb";
final String sasToken = "ccc";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS_WS;
Object amqpReceiveHandler = Deencapsulation.newInstance(AmqpFileUploadNotificationReceivedHandler.class, hostName, userName, sasToken, iotHubServiceClientProtocol, amqpFeedbackReceivedEvent);
// Assert
new Expectations() {
{
event.getConnection();
result = connection;
connection.getTransport();
result = transportInternal;
new WebSocketImpl();
result = webSocket;
webSocket.configure(anyString, anyString, 0, anyString, null, null);
transportInternal.addTransportLayer(webSocket);
sasl.plain(anyString, anyString);
Proton.sslDomain();
result = sslDomain;
sslDomain.init(SslDomain.Mode.CLIENT);
sslDomain.setPeerAuthentication(SslDomain.VerifyMode.ANONYMOUS_PEER);
transportInternal.ssl(sslDomain);
}
};
// Act
Deencapsulation.invoke(amqpReceiveHandler, "onConnectionBound", event);
}
use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class DeviceTest method createFromId_good_case.
// Tests_SRS_SERVICE_SDK_JAVA_DEVICE_12_003: [The constructor shall create a new instance of Device using the given deviceId and return with it]
@Test
public void createFromId_good_case() throws NoSuchAlgorithmException {
// Arrange
String deviceId = "xxx-device";
new Expectations() {
{
Deencapsulation.newInstance(Device.class, deviceId, DeviceStatus.class, SymmetricKey.class);
}
};
// Act
Device device = Device.createFromId(deviceId, null, null);
// Assert
assertNotEquals(device, null);
}
use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class FeedbackReceiverTest method receive_async.
// Tests_SRS_SERVICE_SDK_JAVA_FEEDBACKRECEIVER_12_013: [The function shall create an async wrapper around the receive() function call]
@Test
public void receive_async() throws Exception {
// Arrange
String hostName = "xxx";
String userName = "xxx";
String sasToken = "xxx";
String deviceId = "xxx";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
FeedbackReceiver feedbackReceiver = new FeedbackReceiver(hostName, userName, sasToken, iotHubServiceClientProtocol, deviceId);
// Assert
new Expectations() {
{
amqpReceive.receive(Deencapsulation.getField(feedbackReceiver, "DEFAULT_TIMEOUT_MS"));
feedbackReceiver.receive();
}
};
// Act
CompletableFuture<FeedbackBatch> completableFuture = feedbackReceiver.receiveAsync();
completableFuture.get();
}
use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class FeedbackReceiverTest method receive_with_timout_async_without_deviceId.
// Tests_SRS_SERVICE_SDK_JAVA_FEEDBACKRECEIVER_12_014: [The function shall create an async wrapper around the receive(long timeoutMs) function call]
@Test
public void receive_with_timout_async_without_deviceId() throws Exception {
// Arrange
long timeoutMs = 1000;
String hostName = "xxx";
String userName = "xxx";
String sasToken = "xxx";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
FeedbackReceiver feedbackReceiver = new FeedbackReceiver(hostName, userName, sasToken, iotHubServiceClientProtocol);
// Assert
new Expectations() {
{
amqpReceive.receive(timeoutMs);
feedbackReceiver.receive(anyLong);
}
};
// Act
CompletableFuture<FeedbackBatch> completableFuture = feedbackReceiver.receiveAsync(timeoutMs);
completableFuture.get();
}
use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class FeedbackReceiverTest method receive_with_timout_call_receive_timeout.
// Tests_SRS_SERVICE_SDK_JAVA_FEEDBACKRECEIVER_12_010: [The function shall call receive() on the member AMQPReceive object and return with the result]
@Test
public void receive_with_timout_call_receive_timeout() throws Exception {
// Arrange
long timeoutMs = 1000;
String hostName = "xxx";
String userName = "xxx";
String sasToken = "xxx";
String deviceId = "xxx";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
FeedbackReceiver feedbackReceiver = new FeedbackReceiver(hostName, userName, sasToken, iotHubServiceClientProtocol, deviceId);
// Assert
new Expectations() {
{
amqpReceive.receive(timeoutMs);
}
};
// Act
feedbackReceiver.receive(timeoutMs);
}
Aggregations