use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.
the class IotHubSasTokenTest method expiryTimeSetCorrectly.
// Tests_SRS_IOTHUBSASTOKEN_11_002: [The expiry time shall be the given expiry time, where it is a UNIX timestamp and indicates the time after which the token becomes invalid.]
@Test
public void expiryTimeSetCorrectly() throws URISyntaxException {
final long expiryTime = 100;
final String signature = "sample-sig";
final IotHubConnectionString iotHubConnectionString = Deencapsulation.newInstance(IotHubConnectionString.class, new Class[] { String.class, String.class, String.class, String.class }, "iothub.sample-iothub-hostname.net", "sample-device-ID", "sample-device-key", null);
new NonStrictExpectations() {
{
mockSig.toString();
result = signature;
}
};
IotHubSasToken token = new IotHubSasToken(new DeviceClientConfig(iotHubConnectionString), expiryTime);
String tokenStr = token.toString();
// extract the value assigned to se.
int expiryTimeKeyIdx = tokenStr.indexOf("se=");
int expiryTimeStartIdx = expiryTimeKeyIdx + 3;
int expiryTimeEndIdx = tokenStr.indexOf("&", expiryTimeStartIdx);
if (expiryTimeEndIdx == -1) {
expiryTimeEndIdx = tokenStr.length();
}
String testExpiryTimeStr = tokenStr.substring(expiryTimeStartIdx, expiryTimeEndIdx);
String expectedExpiryTimeStr = Long.toString(expiryTime);
assertThat(testExpiryTimeStr, is(expectedExpiryTimeStr));
}
use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.
the class IotHubAbandonUriTest method toStringIsCorrect.
// Tests_SRS_IOTHUBABANDONURI_11_002: [The string representation of the IoT Hub event URI shall be constructed with the format "[iotHubHostname]/devices/[deviceId]/messages/devicebound/[eTag]/abandon?api-version=2016-02-03".]
@Test
public void toStringIsCorrect() throws URISyntaxException {
final String iotHubHostname = "test.iothub";
final String deviceId = "test-deviceid";
final String eTag = "test-etag";
final String uriStr = "test-uri-str";
new NonStrictExpectations() {
{
mockIotHubUri.toString();
result = uriStr;
}
};
IotHubAbandonUri abandonUri = new IotHubAbandonUri(iotHubHostname, deviceId, eTag);
String testUriStr = abandonUri.toString();
final String expectedUriStr = uriStr;
assertThat(testUriStr, is(expectedUriStr));
}
use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.
the class MessageTest method setPropertyRejectsIllegalValue.
// Tests_SRS_MESSAGE_11_031: [If value name contains a character not specified in RFC 2047, the function shall throw an IllegalArgumentException.]
@Test(expected = IllegalArgumentException.class)
public void setPropertyRejectsIllegalValue(@Mocked final MessageProperty mockProperty) {
final byte[] body = { 0x61, 0x62, 0x63 };
final String name = "test-name";
final String invalidValue = "test-value@";
new NonStrictExpectations() {
{
new MessageProperty(name, invalidValue);
result = new IllegalArgumentException();
}
};
Message msg = new Message(body);
msg.setProperty(name, invalidValue);
}
use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.
the class MessageTest method getPropertiesReturnsCopyOfProperties.
// Tests_SRS_MESSAGE_11_033: [The function shall return a copy of the message properties.]
@Test
public void getPropertiesReturnsCopyOfProperties(@Mocked final MessageProperty mockProperty) {
final byte[] body = { 0x61, 0x62, 0x63 };
final String name = "test-name";
final String value = "test-value";
final String httpsName = "test-https-name";
new NonStrictExpectations() {
{
new MessageProperty(name, value);
result = mockProperty;
mockProperty.hasSameName(name);
result = true;
mockProperty.getValue();
result = value;
mockProperty.getName();
result = httpsName;
}
};
Message msg = new Message(body);
msg.setProperty(name, value);
MessageProperty[] testProperties = msg.getProperties();
int expectedNumProperties = 1;
assertThat(testProperties.length, is(expectedNumProperties));
assertThat(testProperties[0], is(not(mockProperty)));
}
use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.
the class MessageTest method setPropertyAndGetPropertyMatch.
// Tests_SRS_MESSAGE_11_026: [The function shall set the message property to the given value.]
// Tests_SRS_MESSAGE_11_032: [The function shall return the value associated with the message property name, where the name can be either the HTTPS or AMQPS property name.]
@Test
public void setPropertyAndGetPropertyMatch(@Mocked final MessageProperty mockProperty) {
final byte[] body = { 0x61, 0x62, 0x63 };
final String name = "test-name";
final String value1 = "test-value1";
final String value2 = "test-value2";
new NonStrictExpectations() {
{
new MessageProperty(name, value1);
result = mockProperty;
mockProperty.hasSameName(name);
result = true;
mockProperty.getValue();
result = value1;
}
};
Message msg = new Message(body);
msg.setProperty(name, value1);
String testValue = msg.getProperty(name);
String expectedValue = value1;
assertThat(testValue, is(expectedValue));
new NonStrictExpectations() {
{
new MessageProperty(name, value2);
result = mockProperty;
mockProperty.hasSameName(name);
result = true;
mockProperty.getValue();
result = value2;
}
};
msg.setProperty(name, value2);
testValue = msg.getProperty(name);
expectedValue = value2;
assertThat(testValue, is(expectedValue));
}
Aggregations