use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class IotHubConnectionStringBuilderTest method validate_call_validation_functions.
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRINGBUILDER_12_017: [The function shall call property validation functions for hostname, sharedAccessKeyName, sharedAccessKey, sharedAccessSignature]
@Test
public void validate_call_validation_functions() throws Exception {
// Arrange
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;
IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
// Assert
new Expectations() {
{
Deencapsulation.invoke(iotHubConnectionString, "validateFormat", anyString, HOST_NAME_PROPERTY_NAME, anyString);
Deencapsulation.invoke(iotHubConnectionString, "validateFormatIfSpecified", anyString, SHARED_ACCESS_KEY_NAME_PROPERTY_NAME, anyString);
Deencapsulation.invoke(iotHubConnectionString, "validateFormatIfSpecified", anyString, SHARED_ACCESS_KEY_PROPERTY_NAME, anyString);
Deencapsulation.invoke(iotHubConnectionString, "validateFormatIfSpecified", anyString, SHARED_ACCESS_SIGNATURE_PROPERTY_NAME, anyString);
}
};
// Act
Deencapsulation.invoke(iotHubConnectionString, "validate", iotHubConnectionString);
}
use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class IotHubConnectionStringBuilderTest method setHostName_good_case.
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRINGBUILDER_12_021: [The function shall validate the given hostName]
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRINGBUILDER_12_022: [The function shall parse and set the hostname to the given target iotHubConnectionString object]
@Test
public void setHostName_good_case() throws Exception {
// Arrange
String regex = "[a-zA-Z0-9_\\-\\.]+$";
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;
IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
new Expectations() {
{
Deencapsulation.invoke(iotHubConnectionString, "validateFormat", hostName, HOST_NAME_PROPERTY_NAME, regex);
}
};
// Act
Deencapsulation.invoke(iotHubConnectionString, "setHostName", hostName, iotHubConnectionString);
String actualHostName = Deencapsulation.getField(iotHubConnectionString, "hostName");
// Assert
assertEquals(hostName, actualHostName);
}
use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class IotHubConnectionStringBuilderTest method setAuthenticationMethod_good_case_key.
// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRINGBUILDER_12_023: [The function shall populate and set the authenticationMethod on the given target iotHubConnectionString object]
@Test
public void setAuthenticationMethod_good_case_key() throws Exception {
// Arrange
String regex = "[a-zA-Z0-9_\\-\\.]+$";
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;
IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
String newPolicyName = "XXX";
String newPolicyKey = "YYY";
ServiceAuthenticationWithSharedAccessPolicyKey auth = new ServiceAuthenticationWithSharedAccessPolicyKey(newPolicyName, newPolicyKey);
new Expectations() {
{
Deencapsulation.invoke(iotHubConnectionString, "validateFormat", hostName, HOST_NAME_PROPERTY_NAME, regex);
}
};
// Act
Deencapsulation.invoke(iotHubConnectionString, "setAuthenticationMethod", auth, iotHubConnectionString);
// Assert
assertEquals(newPolicyName, iotHubConnectionString.getSharedAccessKeyName());
assertEquals(newPolicyKey, iotHubConnectionString.getSharedAccessKey());
assertEquals(null, iotHubConnectionString.getSharedAccessSignature());
}
use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class SignatureTest method toStringReturnsCorrectString.
// Tests_SRS_SIGNATURE_11_005: [The function shall return the string representation of the signature.]
@Test
public void toStringReturnsCorrectString() {
final String resourceUri = "test-resource-uri";
final String deviceKey = "test-device-key";
final long expiryTime = 101L;
final String sigStr = "test-signature";
new Expectations() {
{
// this should be the last step of the signature computation.
SignatureHelper.encodeSignatureWebSafe(anyString);
result = sigStr;
}
};
Signature sig = new Signature(resourceUri, expiryTime, deviceKey);
String testSigStr = sig.toString();
final String expectedSigStr = sigStr;
assertThat(testSigStr, is(expectedSigStr));
}
use of mockit.Expectations in project azure-iot-sdk-java by Azure.
the class AmqpReceiveHandlerTest method onConnectionBound_call_flow_and_init_ok_amqps.
// 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_018: [The event handler shall initialize WebSocket if the protocol is AMQP_WS]
@Test
public void onConnectionBound_call_flow_and_init_ok_amqps() {
// Arrange
final String hostName = "aaa";
final String userName = "bbb";
final String sasToken = "ccc";
IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS_WS;
AmqpFeedbackReceivedHandler amqpReceiveHandler = new AmqpFeedbackReceivedHandler(hostName, userName, sasToken, iotHubServiceClientProtocol, null);
// 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
amqpReceiveHandler.onConnectionBound(event);
}
Aggregations