use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class FeedbackReceiverTest method receive_call_receive_timeout.
// Tests_SRS_SERVICE_SDK_JAVA_FEEDBACKRECEIVER_12_008: [The function shall call receive(long timeoutMs) function with the default timeout]
@Test
public void receive_call_receive_timeout() 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"));
}
};
// Act
feedbackReceiver.receive();
}
use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class FeedbackReceiverTest method close_call_receiver_close_without_deviceId.
// Tests_SRS_SERVICE_SDK_JAVA_FEEDBACKRECEIVER_12_007: [The function shall call close() on the member AMQPReceive object]
@Test
public void close_call_receiver_close_without_deviceId() throws Exception {
// Arrange
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.close();
}
};
// Act
feedbackReceiver.close();
}
use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class IotHubServiceSasTokenTest method constructor_good_case_flow_check.
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBSERVICESASTOKEN_12_002: [The constructor shall create a target uri from the url encoded host name)]
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBSERVICESASTOKEN_12_003: [The constructor shall create a string to sign by concatenating the target uri and the expiry time string]
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBSERVICESASTOKEN_12_004: [The constructor shall create a key from the shared access key signing with HmacSHA256]
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBSERVICESASTOKEN_12_005: [The constructor shall compute the final signature by url encoding the signed key]
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBSERVICESASTOKEN_12_006: [The constructor shall concatenate the target uri, the signature, the expiry time and the key name using the format: "SharedAccessSignature sr=%s&sig=%s&se=%s&skn=%s"]
@Test
public void constructor_good_case_flow_check() throws Exception {
// Arrange
String cryptoProvider = "HmacSHA256";
String charset = "UTF-8";
String iotHubName = "b.c.d";
String hostName = "HOSTNAME." + iotHubName;
String sharedAccessKeyName = "ACCESSKEYNAME";
String policyName = "SharedAccessKey";
String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
String connectionString = "HostName=" + hostName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
String expectedToken = "SharedAccessSignature sr=hostname.b.c.d&sig=M%2FT5oCM8WWs%2B%2FMv7okAVmfrzVM%2FGUyA7EIp%2FfKo8BeQ%3D&se=1474065852&skn=ACCESSKEYNAME";
IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
// Assert
new Expectations() {
URLEncoder urlEncoder;
Base64 base64;
System system;
SecretKeySpec secretKeySpec;
Mac mac;
{
urlEncoder.encode(hostName.toLowerCase(), String.valueOf(StandardCharsets.UTF_8));
system.currentTimeMillis();
Base64.decodeBase64(sharedAccessKey.getBytes(charset));
byte[] body = { 1 };
secretKeySpec = new SecretKeySpec(body, cryptoProvider);
mac.getInstance(cryptoProvider);
}
};
// Act
IotHubServiceSasToken iotHubServiceSasToken = new IotHubServiceSasToken(iotHubConnectionString);
}
use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class AmqpSendHandlerTest method onConnectionBound_call_flow_and_init_ok_amqp_ws.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_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_AMQPSENDHANDLER_12_010: [The event handler shall set ANONYMUS_PEER authentication mode on the domain of the Transport]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_024: [The event handler shall initialize WebSocket if the protocol is AMQP_WS]
@Test
public void onConnectionBound_call_flow_and_init_ok_amqp_ws() {
// Arrange
String hostName = "aaa";
String userName = "bbb";
String sasToken = "ccc";
String hostAddr = hostName + ":443";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS_WS;
AmqpSendHandler amqpSendHandler = new AmqpSendHandler(hostName, userName, sasToken, iotHubServiceClientProtocol);
// 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
amqpSendHandler.onConnectionBound(event);
}
use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class AmqpSendHandlerTest method onLinkFlowBufferOverflow_call_flow_ok.
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_017: [The event handler shall get the Sender (Proton) object from the link]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_018: [The event handler shall encode the message and copy to the byte buffer]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_019: [The event handler shall set the delivery tag on the Sender (Proton) object]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_020: [The event handler shall send the encoded bytes]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_021: [The event handler shall close the Sender, Session and Connection]
@Test
public void onLinkFlowBufferOverflow_call_flow_ok() throws UnsupportedEncodingException {
// Arrange
String hostName = "aaa";
String userName = "bbb";
String sasToken = "ccc";
String hostAddr = hostName + ":5671";
String deviceId = "deviceId";
String content = "abcdefghijklmnopqrst";
com.microsoft.azure.sdk.iot.service.Message iotMessage = new com.microsoft.azure.sdk.iot.service.Message(content);
String endpoint = "/messages/devicebound";
exceptionCount = 0;
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
createProtonObjects();
AmqpSendHandler amqpSendHandler = new AmqpSendHandler(hostName, userName, sasToken, iotHubServiceClientProtocol);
Queue<Message> testMessagesToBeSent = new LinkedBlockingQueue<>();
testMessagesToBeSent.add(messageWithException);
Deencapsulation.setField(amqpSendHandler, "messagesToBeSent", testMessagesToBeSent);
// Assert
new Expectations() {
{
link = event.getLink();
link.getCredit();
}
};
// Act
amqpSendHandler.onLinkFlow(event);
}
Aggregations