Search in sources :

Example 1 with SaslListener

use of org.apache.qpid.proton.engine.SaslListener in project azure-iot-sdk-java by Azure.

the class SaslListenerImplTest method onSaslOutcomeTempTest.

// Tests_SRS_SASLLISTENERIMPL_34_006: [If the sasl outcome is PN_SASL_TEMP, this function shall tell the saved saslHandler to handleOutcome with SYS_TEMP.]
@Test
public void onSaslOutcomeTempTest() throws Exception {
    // arrange
    SaslListener saslListener = new SaslListenerImpl(mockedSaslHandler);
    new NonStrictExpectations() {

        {
            mockedSasl.getOutcome();
            result = PN_SASL_TEMP;
        }
    };
    // act
    saslListener.onSaslOutcome(mockedSasl, mockedTransport);
    // assert
    new Verifications() {

        {
            mockedSaslHandler.handleOutcome(SaslHandler.SaslOutcome.SYS_TEMP);
            times = 1;
        }
    };
}
Also used : SaslListenerImpl(com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) SaslListener(org.apache.qpid.proton.engine.SaslListener) Test(org.junit.Test)

Example 2 with SaslListener

use of org.apache.qpid.proton.engine.SaslListener in project azure-iot-sdk-java by Azure.

the class SaslListenerImplTest method onSaslMechanismsWithPlainMechanism.

// Tests_SRS_SASLLISTENERIMPL_34_015: [If the chosen mechanism is PLAIN, this function shall call sasl.plain(...) with the inputs given by the saslhandler.]
@Test
public void onSaslMechanismsWithPlainMechanism() throws Exception {
    // arrange
    final String[] remoteMechanisms = new String[] { "PLAIN" };
    final String chosenMechanism = "PLAIN";
    final byte[] initPayload = new byte[0];
    SaslListener saslListener = new SaslListenerImpl(mockedSaslHandler);
    final String expectedUsername = "1234";
    final String expectedPass = "5678";
    new NonStrictExpectations() {

        {
            mockedSasl.getRemoteMechanisms();
            result = remoteMechanisms;
            mockedSaslHandler.chooseSaslMechanism(remoteMechanisms);
            result = chosenMechanism;
            mockedSaslHandler.getInitPayload(chosenMechanism);
            result = initPayload;
            mockedSaslHandler.getPlainUsername();
            result = expectedUsername;
            mockedSaslHandler.getPlainPassword();
            result = expectedPass;
        }
    };
    // 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;
            mockedSasl.plain(expectedUsername, expectedPass);
            times = 1;
        }
    };
}
Also used : SaslListenerImpl(com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) SaslListener(org.apache.qpid.proton.engine.SaslListener) Test(org.junit.Test)

Example 3 with SaslListener

use of org.apache.qpid.proton.engine.SaslListener in project azure-iot-sdk-java by Azure.

the class SaslListenerImplTest method onSaslOutcomePermTest.

// Tests_SRS_SASLLISTENERIMPL_34_007: [If the sasl outcome is PN_SASL_PERM, this function shall tell the saved saslHandler to handleOutcome with SYS_PERM.]
@Test
public void onSaslOutcomePermTest() throws Exception {
    // arrange
    SaslListener saslListener = new SaslListenerImpl(mockedSaslHandler);
    new NonStrictExpectations() {

        {
            mockedSasl.getOutcome();
            result = PN_SASL_PERM;
        }
    };
    // act
    saslListener.onSaslOutcome(mockedSasl, mockedTransport);
    // assert
    new Verifications() {

        {
            mockedSaslHandler.handleOutcome(SaslHandler.SaslOutcome.SYS_PERM);
            times = 1;
        }
    };
}
Also used : SaslListenerImpl(com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) SaslListener(org.apache.qpid.proton.engine.SaslListener) Test(org.junit.Test)

Example 4 with SaslListener

use of org.apache.qpid.proton.engine.SaslListener in project azure-iot-sdk-java by Azure.

the class SaslListenerImplTest method onSaslOutcomeOkTest.

// Tests_SRS_SASLLISTENERIMPL_34_009: [If the sasl outcome is PN_SASL_OK, this function shall tell the saved saslHandler to handleOutcome with OK.]
@Test
public void onSaslOutcomeOkTest() throws Exception {
    // arrange
    SaslListener saslListener = new SaslListenerImpl(mockedSaslHandler);
    new NonStrictExpectations() {

        {
            mockedSasl.getOutcome();
            result = PN_SASL_OK;
        }
    };
    // act
    saslListener.onSaslOutcome(mockedSasl, mockedTransport);
    // assert
    new Verifications() {

        {
            mockedSaslHandler.handleOutcome(SaslHandler.SaslOutcome.OK);
            times = 1;
        }
    };
}
Also used : SaslListenerImpl(com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) SaslListener(org.apache.qpid.proton.engine.SaslListener) Test(org.junit.Test)

Example 5 with SaslListener

use of org.apache.qpid.proton.engine.SaslListener in project azure-iot-sdk-java by Azure.

the class SaslListenerImplTest method onSaslOutcomeAuthTest.

// Tests_SRS_SASLLISTENERIMPL_34_008: [If the sasl outcome is PN_SASL_AUTH, this function shall tell the saved saslHandler to handleOutcome with AUTH.]
@Test
public void onSaslOutcomeAuthTest() throws Exception {
    // arrange
    SaslListener saslListener = new SaslListenerImpl(mockedSaslHandler);
    new NonStrictExpectations() {

        {
            mockedSasl.getOutcome();
            result = PN_SASL_AUTH;
        }
    };
    // act
    saslListener.onSaslOutcome(mockedSasl, mockedTransport);
    // assert
    new Verifications() {

        {
            mockedSaslHandler.handleOutcome(SaslHandler.SaslOutcome.AUTH);
            times = 1;
        }
    };
}
Also used : SaslListenerImpl(com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) SaslListener(org.apache.qpid.proton.engine.SaslListener) Test(org.junit.Test)

Aggregations

SaslListenerImpl (com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl)10 NonStrictExpectations (mockit.NonStrictExpectations)10 Verifications (mockit.Verifications)10 SaslListener (org.apache.qpid.proton.engine.SaslListener)10 Test (org.junit.Test)10