use of com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken in project azure-iot-sdk-java by Azure.
the class AmqpsIotHubConnectionTest method openCreatesSasToken.
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_008: [The function shall create a new sasToken valid for the duration
// specified in config to be used for the communication with IoTHub.]
@Test
public void openCreatesSasToken() throws IOException, InterruptedException {
baseExpectations();
AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
connection.open();
new Verifications() {
{
new IotHubSasToken(mockConfig, anyLong);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken in project azure-iot-sdk-java by Azure.
the class AmqpsIotHubConnectionTest method openTriggersProtonReactor.
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_009: [The function shall trigger the Reactor (Proton) to begin running.]
@Test
public void openTriggersProtonReactor() throws IOException, InterruptedException {
baseExpectations();
new NonStrictExpectations() {
{
new IotHubReactor((Reactor) any);
result = mockIotHubReactor;
mockIotHubReactor.run();
mockOpenLock.waitLock(anyLong);
}
};
AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
Deencapsulation.setField(connection, "openLock", mockOpenLock);
connection.open();
new Verifications() {
{
new IotHubSasToken(mockConfig, anyLong);
times = 1;
new IotHubReactor((Reactor) any);
times = 1;
mockOpenLock.waitLock(anyLong);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken in project azure-iot-sdk-java by Azure.
the class AmqpsIotHubConnectionTest method openDoesNothingIfTheConnectionIsAlreadyOpen.
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_007: [If the AMQPS connection is already open, the function shall do nothing.]
@Test
public void openDoesNothingIfTheConnectionIsAlreadyOpen() throws IOException, InterruptedException {
baseExpectations();
AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
Deencapsulation.setField(connection, "state", State.OPEN);
connection.open();
new Verifications() {
{
new IotHubSasToken(mockConfig, anyLong);
times = 0;
}
};
}
use of com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken in project azure-iot-sdk-java by Azure.
the class MqttIotHubConnectionTest method openThrowsIOExceptionIfConnectionFailsInTwin.
@Test(expected = IOException.class)
public void openThrowsIOExceptionIfConnectionFailsInTwin() throws IOException {
baseExpectations();
new NonStrictExpectations() {
{
new IotHubSasToken(mockConfig, anyLong);
result = mockToken;
new MqttMessaging(sslPrefix + iotHubHostName + sslPortSuffix, deviceId, anyString, anyString, mockIotHubSSLContext);
result = mockDeviceMessaging;
new MqttDeviceMethod();
result = mockDeviceMethods;
new MqttDeviceTwin();
result = new IOException(anyString);
}
};
try {
MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
connection.open();
} catch (Exception e) {
new Verifications() {
{
mockDeviceMessaging.stop();
times = 1;
mockDeviceMethods.stop();
times = 1;
}
};
throw e;
}
}
use of com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken in project azure-iot-sdk-java by Azure.
the class MqttIotHubConnectionTest method openThrowsIOExceptionIfConnectionFailsInMethod.
@Test(expected = IOException.class)
public void openThrowsIOExceptionIfConnectionFailsInMethod() throws IOException {
baseExpectations();
new NonStrictExpectations() {
{
new IotHubSasToken(mockConfig, anyLong);
result = mockToken;
new MqttMessaging(sslPrefix + iotHubHostName + sslPortSuffix, deviceId, anyString, anyString, mockIotHubSSLContext);
result = mockDeviceMessaging;
new MqttDeviceMethod();
result = new IOException(anyString);
}
};
try {
MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
connection.open();
} catch (Exception e) {
new Verifications() {
{
mockDeviceMessaging.stop();
times = 1;
}
};
throw e;
}
}
Aggregations