Search in sources :

Example 1 with BrokerMsalController

use of com.microsoft.identity.common.internal.controllers.BrokerMsalController in project microsoft-authentication-library-common-for-android by AzureAD.

the class HelloCacheTests method testHelloShouldOnlyTriggerOnce.

@Test
public void testHelloShouldOnlyTriggerOnce() {
    final String minimumVer = "1.0";
    final String negotiatedVer = "2.5";
    class MockStrategy implements IIpcStrategy {

        int triggered = 0;

        @Nullable
        @Override
        public Bundle communicateToBroker(@NonNull BrokerOperationBundle bundle) throws BrokerCommunicationException {
            triggered += 1;
            if (triggered == 2) {
                Assert.fail("Should never be triggered");
            }
            final Bundle resultBundle = new Bundle();
            resultBundle.putString(NEGOTIATED_BP_VERSION_KEY, negotiatedVer);
            return resultBundle;
        }

        @Override
        public Type getType() {
            return Type.CONTENT_PROVIDER;
        }
    }
    class MockController extends BrokerMsalController {

        public MockController(Context applicationContext) {
            super(applicationContext);
        }

        @Override
        public HelloCache getHelloCache() {
            return HelloCacheTests.this.getHelloCache(protocolA);
        }

        @Override
        public String getActiveBrokerPackageName() {
            return brokerAppName;
        }
    }
    final MockController controller = new MockController(ApplicationProvider.getApplicationContext());
    final MockStrategy strategy = new MockStrategy();
    final CommandParameters parameters = CommandParameters.builder().requiredBrokerProtocolVersion(minimumVer).build();
    try {
        final String negotiatedProtocolVersion = controller.hello(strategy, parameters.getRequiredBrokerProtocolVersion());
        final String negotiatedProtocolVersion2 = controller.hello(strategy, parameters.getRequiredBrokerProtocolVersion());
        Assert.assertEquals(negotiatedProtocolVersion, negotiatedProtocolVersion2);
    } catch (BaseException e) {
        Assert.fail();
    }
}
Also used : Context(android.content.Context) BaseException(com.microsoft.identity.common.exception.BaseException) BrokerOperationBundle(com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle) Bundle(android.os.Bundle) BrokerOperationBundle(com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle) NonNull(androidx.annotation.NonNull) IIpcStrategy(com.microsoft.identity.common.internal.broker.ipc.IIpcStrategy) CommandParameters(com.microsoft.identity.common.internal.commands.parameters.CommandParameters) BrokerMsalController(com.microsoft.identity.common.internal.controllers.BrokerMsalController) Test(org.junit.Test)

Aggregations

Context (android.content.Context)1 Bundle (android.os.Bundle)1 NonNull (androidx.annotation.NonNull)1 BaseException (com.microsoft.identity.common.exception.BaseException)1 BrokerOperationBundle (com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle)1 IIpcStrategy (com.microsoft.identity.common.internal.broker.ipc.IIpcStrategy)1 CommandParameters (com.microsoft.identity.common.internal.commands.parameters.CommandParameters)1 BrokerMsalController (com.microsoft.identity.common.internal.controllers.BrokerMsalController)1 Test (org.junit.Test)1