Search in sources :

Example 11 with ConfigContext

use of com.nexblocks.authguard.config.ConfigContext in project AuthGuard by AuthGuard.

the class AuthenticationServiceImplTest method setup.

@BeforeAll
void setup() {
    exchangeService = Mockito.mock(ExchangeService.class);
    accountLocksService = Mockito.mock(AccountLocksService.class);
    final ConfigContext configContext = Mockito.mock(ConfigContext.class);
    final AuthenticationConfig config = AuthenticationConfig.builder().generateToken("accessToken").build();
    Mockito.when(exchangeService.supportsExchange("basic", "accessToken")).thenReturn(true);
    Mockito.when(configContext.asConfigBean(AuthenticationConfig.class)).thenReturn(config);
    authenticationService = new AuthenticationServiceImpl(exchangeService, accountLocksService, configContext);
}
Also used : ExchangeService(com.nexblocks.authguard.service.ExchangeService) AccountLocksService(com.nexblocks.authguard.service.AccountLocksService) AuthenticationConfig(com.nexblocks.authguard.service.config.AuthenticationConfig) ConfigContext(com.nexblocks.authguard.config.ConfigContext) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 12 with ConfigContext

use of com.nexblocks.authguard.config.ConfigContext in project AuthGuard by AuthGuard.

the class OtpServiceImplTest method setup.

void setup(final OtpConfig otpConfig) {
    mockExchangeService = Mockito.mock(ExchangeService.class);
    final ConfigContext configContext = Mockito.mock(ConfigContext.class);
    Mockito.when(configContext.asConfigBean(OtpConfig.class)).thenReturn(otpConfig);
    otpService = new OtpServiceImpl(mockExchangeService, configContext);
}
Also used : ExchangeService(com.nexblocks.authguard.service.ExchangeService) ConfigContext(com.nexblocks.authguard.config.ConfigContext)

Example 13 with ConfigContext

use of com.nexblocks.authguard.config.ConfigContext in project AuthGuard by AuthGuard.

the class AutoSubscribersTest method subscribe.

@Test
void subscribe() {
    final ObjectNode configRoot = new ObjectNode(JsonNodeFactory.instance);
    final ArrayNode allowed = new ArrayNode(JsonNodeFactory.instance).add("com.nexblocks.authguard.emb.AutoSubscribersTest.ToBeSubscribed").add("com.nexblocks.authguard.emb.AutoSubscribersTest.NotToBeSubscribed");
    configRoot.set("subscribers", allowed);
    final MessageBus messageBus = Mockito.mock(MessageBus.class);
    final ToBeSubscribed toBeSubscribed = new ToBeSubscribed();
    final NotToBeSubscribed notToBeSubscribed = new NotToBeSubscribed();
    final ConfigContext configContext = new JacksonConfigContext(configRoot);
    final AutoSubscribers autoSubscribers = new AutoSubscribers(messageBus, ImmutableSet.of(toBeSubscribed, notToBeSubscribed), configContext);
    autoSubscribers.subscribe();
    Mockito.verify(messageBus, Mockito.times(1)).subscribe("test", toBeSubscribed);
    Mockito.verify(messageBus, Mockito.never()).subscribe(Mockito.any(), Mockito.eq(notToBeSubscribed));
}
Also used : JacksonConfigContext(com.nexblocks.authguard.config.JacksonConfigContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) JacksonConfigContext(com.nexblocks.authguard.config.JacksonConfigContext) ConfigContext(com.nexblocks.authguard.config.ConfigContext) Test(org.junit.jupiter.api.Test)

Example 14 with ConfigContext

use of com.nexblocks.authguard.config.ConfigContext in project AuthGuard by AuthGuard.

the class OtpProviderTest method setup.

void setup(final OtpConfig otpConfig) {
    mockOtpRepository = Mockito.mock(OtpRepository.class);
    messageBus = Mockito.mock(MessageBus.class);
    final ConfigContext configContext = Mockito.mock(ConfigContext.class);
    Mockito.when(configContext.asConfigBean(OtpConfig.class)).thenReturn(otpConfig);
    otpProvider = new OtpProvider(mockOtpRepository, new ServiceMapperImpl(), messageBus, configContext);
}
Also used : OtpRepository(com.nexblocks.authguard.dal.cache.OtpRepository) MessageBus(com.nexblocks.authguard.emb.MessageBus) ServiceMapperImpl(com.nexblocks.authguard.service.mappers.ServiceMapperImpl) ConfigContext(com.nexblocks.authguard.config.ConfigContext)

Example 15 with ConfigContext

use of com.nexblocks.authguard.config.ConfigContext in project AuthGuard by AuthGuard.

the class ExchangesBinderTest method exchangesInjected.

@Test
void exchangesInjected() {
    final ConfigContext rootContext = Mockito.mock(ConfigContext.class);
    final ConfigContext exchangeContext = Mockito.mock(ConfigContext.class);
    final ExchangesBinder.ExchangeConfig allowedExchange = new ExchangesBinder.ExchangeConfig();
    allowedExchange.setFrom("basic");
    allowedExchange.setTo("random");
    Mockito.when(rootContext.getSubContext("exchange")).thenReturn(exchangeContext);
    Mockito.when(exchangeContext.getAsCollection("allowed", ExchangesBinder.ExchangeConfig.class)).thenReturn(Collections.singletonList(allowedExchange));
    final Collection<String> searchPackages = Collections.singletonList("com.nexblocks.authguard.bindings");
    final Injector injector = Guice.createInjector(new ExchangesBinder(rootContext, searchPackages));
    final NeedsExchanges needsExchanges = injector.getInstance(NeedsExchanges.class);
    assertThat(needsExchanges.exchanges).hasSize(1);
    assertThat(needsExchanges.exchanges.get(0)).isInstanceOf(FirstExchange.class);
}
Also used : Injector(com.google.inject.Injector) ConfigContext(com.nexblocks.authguard.config.ConfigContext) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigContext (com.nexblocks.authguard.config.ConfigContext)16 Test (org.junit.jupiter.api.Test)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 JacksonConfigContext (com.nexblocks.authguard.config.JacksonConfigContext)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 ServiceMapperImpl (com.nexblocks.authguard.service.mappers.ServiceMapperImpl)3 Injector (com.google.inject.Injector)2 OtpRepository (com.nexblocks.authguard.dal.cache.OtpRepository)2 MessageBus (com.nexblocks.authguard.emb.MessageBus)2 EmailProvider (com.nexblocks.authguard.external.email.EmailProvider)2 ExchangeService (com.nexblocks.authguard.service.ExchangeService)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 CreationException (com.google.inject.CreationException)1 Guice (com.google.inject.Guice)1 ProvisionException (com.google.inject.ProvisionException)1 Named (com.google.inject.name.Named)1 com.nexblocks.authguard.bindings (com.nexblocks.authguard.bindings)1 BootstrapRunner (com.nexblocks.authguard.bootstrap.BootstrapRunner)1 EmptyConfigContext (com.nexblocks.authguard.config.EmptyConfigContext)1