use of com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl in project azure-iot-sdk-java by Azure.
the class SaslListenerImplTest method onSaslOutcomeSkippedTest.
// Tests_SRS_SASLLISTENERIMPL_34_010: [If the sasl outcome is PN_SASL_SYS or PN_SASL_SKIPPED, this function shall tell the saved saslHandler to handleOutcome with SYS.]
@Test
public void onSaslOutcomeSkippedTest() throws Exception {
// arrange
SaslListener saslListener = new SaslListenerImpl(mockedSaslHandler);
new NonStrictExpectations() {
{
mockedSasl.getOutcome();
result = PN_SASL_SKIPPED;
}
};
// act
saslListener.onSaslOutcome(mockedSasl, mockedTransport);
// assert
new Verifications() {
{
mockedSaslHandler.handleOutcome(SaslHandler.SaslOutcome.SYS);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl in project azure-iot-sdk-java by Azure.
the class SaslListenerImplTest method onBuildInitHandlerThrowsDoesNotSendInit.
// Tests_SRS_SASLLISTENERIMPL_34_013: [If any exception is thrown while the saslHandler builds the init payload, this function shall save that exception and shall not send the returned init payload.]
@Test
public void onBuildInitHandlerThrowsDoesNotSendInit() throws Exception {
// arrange
final String[] remoteMechanisms = new String[] { "1", "2" };
final String chosenMechanism = "1";
final byte[] initPayload = new byte[] { 0, 0, 0 };
SaslListenerImpl saslListener = new SaslListenerImpl(mockedSaslHandler);
new NonStrictExpectations() {
{
mockedSasl.getRemoteMechanisms();
result = remoteMechanisms;
mockedSaslHandler.chooseSaslMechanism(remoteMechanisms);
result = remoteMechanisms;
mockedSaslHandler.getInitPayload(chosenMechanism);
result = new SecurityException();
}
};
// act
saslListener.onSaslMechanisms(mockedSasl, mockedTransport);
// assert
assertNotNull("Expected a saved exception", saslListener.getSavedException());
assertEquals(SecurityException.class, saslListener.getSavedException().getClass());
new Verifications() {
{
mockedSaslHandler.chooseSaslMechanism(remoteMechanisms);
times = 1;
mockedSaslHandler.getInitPayload(chosenMechanism);
times = 1;
mockedSasl.send(initPayload, 0, initPayload.length);
times = 0;
}
};
}
use of com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl in project azure-iot-sdk-java by Azure.
the class SaslListenerImplTest method constructorSavesProvidedHandler.
// Tests_SRS_SASLLISTENERIMPL_34_001: [This constructor shall save the provided handler.]
@Test
public void constructorSavesProvidedHandler() {
// act
SaslListenerImpl saslListener = new SaslListenerImpl(mockedSaslHandler);
// assert
SaslHandler actualSaslHandler = Deencapsulation.getField(saslListener, "saslHandler");
assertEquals(mockedSaslHandler, actualSaslHandler);
}
use of com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl in project azure-iot-sdk-java by Azure.
the class SaslListenerImplTest method onSaslMechanismsTest.
// Tests_SRS_SASLLISTENERIMPL_34_002: [This function shall retrieve the remote mechanisms and give them to the saved saslHandler object to decide which mechanism to use.]
// Tests_SRS_SASLLISTENERIMPL_34_003: [This function shall ask the saved saslHandler object to create the init payload for the chosen sasl mechanism and then send that payload if the init payload is larger than 0 bytes.]
@Test
public void onSaslMechanismsTest() throws Exception {
// arrange
final String[] remoteMechanisms = new String[] { "1", "2" };
final String chosenMechanism = "1";
final byte[] initPayload = new byte[] { 0, 0, 0 };
SaslListener saslListener = new SaslListenerImpl(mockedSaslHandler);
new NonStrictExpectations() {
{
mockedSasl.getRemoteMechanisms();
result = remoteMechanisms;
mockedSaslHandler.chooseSaslMechanism(remoteMechanisms);
result = chosenMechanism;
mockedSaslHandler.getInitPayload(chosenMechanism);
result = initPayload;
}
};
// act
saslListener.onSaslMechanisms(mockedSasl, mockedTransport);
// assert
new Verifications() {
{
mockedSaslHandler.chooseSaslMechanism(remoteMechanisms);
times = 1;
mockedSaslHandler.getInitPayload(chosenMechanism);
times = 1;
mockedSasl.send(initPayload, 0, initPayload.length);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl in project azure-iot-sdk-java by Azure.
the class SaslListenerImplTest method onSaslMechanismsTestWithoutInit.
// Tests_SRS_SASLLISTENERIMPL_34_003: [This function shall ask the saved saslHandler object to create the init payload for the chosen sasl mechanism and then send that payload if the init payload is larger than 0 bytes.]
@Test
public void onSaslMechanismsTestWithoutInit() throws Exception {
// arrange
final String[] remoteMechanisms = new String[] { "1", "2" };
final String chosenMechanism = "1";
final byte[] initPayload = new byte[0];
SaslListener saslListener = new SaslListenerImpl(mockedSaslHandler);
new NonStrictExpectations() {
{
mockedSasl.getRemoteMechanisms();
result = remoteMechanisms;
mockedSaslHandler.chooseSaslMechanism(remoteMechanisms);
result = chosenMechanism;
mockedSaslHandler.getInitPayload(chosenMechanism);
result = initPayload;
}
};
// act
saslListener.onSaslMechanisms(mockedSasl, mockedTransport);
// assert
new Verifications() {
{
mockedSaslHandler.chooseSaslMechanism(remoteMechanisms);
times = 1;
mockedSaslHandler.getInitPayload(chosenMechanism);
times = 1;
mockedSasl.send(initPayload, 0, initPayload.length);
times = 0;
}
};
}
Aggregations