use of com.microsoft.azure.sdk.iot.device.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class DeviceClientConfigTest method getAndSetDeviceMethodAndTwinMessageCallbackAndContextsMatch.
@Test
public void getAndSetDeviceMethodAndTwinMessageCallbackAndContextsMatch(@Mocked final MessageCallback mockCallback) throws URISyntaxException {
final String iotHubHostname = "test.iothubhostname";
final String deviceId = "test-deviceid";
final String deviceKey = "test-devicekey";
final String sharedAccessToken = null;
final IotHubConnectionString iotHubConnectionString = Deencapsulation.newInstance(IotHubConnectionString.class, new Class[] { String.class, String.class, String.class, String.class }, iotHubHostname, deviceId, deviceKey, sharedAccessToken);
DeviceClientConfig config = new DeviceClientConfig(iotHubConnectionString);
Object dMContext = new Object();
config.setDeviceMethodMessageCallback(mockCallback, dMContext);
Object testContextDM = config.getDeviceMethodMessageContext();
Object dTcontext = new Object();
config.setDeviceTwinMessageCallback(mockCallback, dTcontext);
Object testContextDT = config.getDeviceTwinMessageContext();
final Object expectedDTContext = dTcontext;
assertThat(testContextDT, is(expectedDTContext));
assertEquals(config.getDeviceTwinMessageCallback(), mockCallback);
final Object expectedDMContext = dMContext;
assertThat(testContextDM, is(expectedDMContext));
assertEquals(config.getDeviceMethodMessageCallback(), mockCallback);
}
use of com.microsoft.azure.sdk.iot.device.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class DeviceClientConfigTest method getAndSetMessageCallbackContextsMatch.
// Tests_SRS_DEVICECLIENTCONFIG_11_006: [The function shall set the message callback, with its associated context.]
// Tests_SRS_DEVICECLIENTCONFIG_11_011: [The function shall return the current message context.]
@Test
public void getAndSetMessageCallbackContextsMatch(@Mocked final MessageCallback mockCallback) throws URISyntaxException {
final String iotHubHostname = "test.iothubhostname";
final String deviceId = "test-deviceid";
final String deviceKey = "test-devicekey";
final String sharedAccessToken = null;
final IotHubConnectionString iotHubConnectionString = Deencapsulation.newInstance(IotHubConnectionString.class, new Class[] { String.class, String.class, String.class, String.class }, iotHubHostname, deviceId, deviceKey, sharedAccessToken);
DeviceClientConfig config = new DeviceClientConfig(iotHubConnectionString);
Object context = new Object();
config.setMessageCallback(mockCallback, context);
Object testContext = config.getMessageContext();
final Object expectedContext = context;
assertThat(testContext, is(expectedContext));
}
use of com.microsoft.azure.sdk.iot.device.IotHubConnectionString 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 com.microsoft.azure.sdk.iot.device.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class IotHubSasTokenTest method doesNotSetSASTokenWithoutSr.
// Tests_SRS_IOTHUBSASTOKEN_25_008: [**The required format for the SAS Token shall be verified and IllegalArgumentException is thrown if unmatched.**]**
//Tests_SRS_IOTHUBSASTOKEN_11_001: [**The SAS token shall have the format `SharedAccessSignature sig=<signature >&se=<expiryTime>&sr=<resourceURI>`. The params can be in any order.**]**
@Test(expected = IllegalArgumentException.class)
public void doesNotSetSASTokenWithoutSr() throws URISyntaxException {
String sastoken = "SharedAccessSignature sig=S3%2flPidfBF48B7%2fOFAxMOYH8rpOneq68nu61D%2fBP6fo%3d&se=1469813873";
;
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", null, sastoken);
IotHubSasToken token = new IotHubSasToken(new DeviceClientConfig(iotHubConnectionString), 0);
String tokenStr = token.toString();
assertTrue(tokenStr != sastoken);
}
use of com.microsoft.azure.sdk.iot.device.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class IotHubSasTokenTest method doesNotSetSASTokenWithoutSe.
// Tests_SRS_IOTHUBSASTOKEN_25_008: [**The required format for the SAS Token shall be verified and IllegalArgumentException is thrown if unmatched.**]**
//Tests_SRS_IOTHUBSASTOKEN_11_001: [**The SAS token shall have the format `SharedAccessSignature sig=<signature >&se=<expiryTime>&sr=<resourceURI>`. The params can be in any order.**]**
@Test(expected = IllegalArgumentException.class)
public void doesNotSetSASTokenWithoutSe() throws URISyntaxException {
String sastoken = "SharedAccessSignature sr=sample-iothub-hostname.net%2fdevices%2fsample-device-ID&sig=S3%2flPidfBF48B7%2fOFAxMOYH8rpOneq68nu61D%2fBP6fo%3d";
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", null, sastoken);
IotHubSasToken token = new IotHubSasToken(new DeviceClientConfig(iotHubConnectionString), 0);
String tokenStr = token.toString();
assertTrue(tokenStr != sastoken);
}
Aggregations