Java 类org.apache.commons.configuration2.ImmutableConfiguration 实例源码

项目:cryptotrader    文件:CryptotraderImpl.java   
@Override
protected void configure() {

    bind(ConfigurationProvider.class).to(ConfigurationProviderImpl.class).asEagerSingleton();
    bind(Configuration.class).toProvider(ConfigurationProvider.class).asEagerSingleton();
    bind(ImmutableConfiguration.class).to(Configuration.class).asEagerSingleton();
    bind(PropertyController.class).to(PropertyManagerImpl.class).asEagerSingleton();
    bind(PropertyManager.class).to(PropertyController.class).asEagerSingleton();
    bind(ServiceFactory.class).to(ServiceFactoryImpl.class).asEagerSingleton();
    bind(ExecutorFactory.class).to(ExecutorFactoryImpl.class).asEagerSingleton();

    bind(Context.class).to(ContextImpl.class).asEagerSingleton();
    bind(Estimator.class).to(EstimatorImpl.class).asEagerSingleton();
    bind(Adviser.class).to(AdviserImpl.class).asEagerSingleton();
    bind(Instructor.class).to(InstructorImpl.class).asEagerSingleton();

    bind(Agent.class).to(AgentImpl.class).asEagerSingleton();
    bind(Pipeline.class).to(PipelineImpl.class).asEagerSingleton();
    bind(Trader.class).to(traderClass).asEagerSingleton();

    bind(Cryptotrader.class).to(CryptotraderImpl.class);

}
项目:cryptotrader    文件:ServiceFactoryImplTest.java   
@Test
public void testLoadMap() throws Exception {

    Map<String, TestInterface> services = target.loadMap(TestInterface.class);
    assertTrue(services.get("TestImpl1") instanceof TestInterface.TestImpl1);
    assertTrue(services.get("TestImpl3") instanceof TestInterface.TestImpl3);
    assertEquals(services.size(), 2, services.toString());

    for (TestInterface s : services.values()) {

        assertNotNull(s.getInjector());

        assertNotNull(s.getInjector().getInstance(ImmutableConfiguration.class));

        try {
            s.getInjector().getInstance(ServiceFactory.class);
            fail();
        } catch (ConfigurationException e) {
            // Success
        }

    }

}
项目:spoofax    文件:ProjectConfig.java   
private static void validateDeps(ImmutableConfiguration config, String key, String name, MessageBuilder mb,
        Collection<IMessage> messages) {
    final List<String> depStrs = config.getList(String.class, key, Lists.<String>newArrayList());
    for(String depStr : depStrs) {
        try {
            LanguageIdentifier.parse(depStr);
        } catch(IllegalArgumentException e) {
            messages.add(mb.withMessage("Invalid " + name + " dependency. " + e.getMessage()).build());
        }
    }
}
项目:spoofax    文件:NaBL2ConfigReaderWriter.java   
public static Collection<IMessage> validate(ImmutableConfiguration config, MessageBuilder mb) {
    final String allFlags = String.join(" ", Arrays.asList(Flag.values()).stream().map(Flag::name)
            .map(String::toLowerCase).collect(Collectors.toList()));
    List<IMessage> messages = Lists.newArrayList();
    for(String flag : splitString(config.getString(PROP_DEBUG, ""))) {
        try {
            Flag.valueOf(flag.toUpperCase());
        } catch(IllegalArgumentException ex) {
            messages.add(mb.withMessage("Invalid NaBL2 debug flag: " + flag + ", must be one of: " + allFlags + ".")
                    .build());
        }
    }
    return messages;
}
项目:airsonic    文件:CommonsConfigurationPropertySource.java   
public CommonsConfigurationPropertySource(String name, ImmutableConfiguration configuration) {
    super(name);
    this.configuration = configuration;
}
项目:cryptotrader    文件:AbstractService.java   
@Inject
@VisibleForTesting
public void setConfiguration(ImmutableConfiguration configuration) {
    this.configuration = configuration;
}
项目:airsonic    文件:CustomPropertySourceConfigurer.java   
public void initialize(ConfigurableWebApplicationContext ctx) {

        ApacheCommonsConfigurationService configurationService = new ApacheCommonsConfigurationService();
        ImmutableConfiguration snapshot = configurationService.getImmutableSnapshot();

        PropertySource ps = new CommonsConfigurationPropertySource("airsonic-pre-init-configs", snapshot);


        ctx.getEnvironment().getPropertySources().addLast(ps);

        addDataSourceProfile(ctx);
    }
项目:cryptotrader    文件:ServiceFactoryImpl.java   
@Inject
public ServiceFactoryImpl(Injector injector) {

    this.injector = Guice.createInjector(new AbstractModule() {
        @Override
        protected void configure() {

            Configuration c = injector.getInstance(Configuration.class);

            bind(ImmutableConfiguration.class).toInstance(c);

        }
    });

}
项目:cryptotrader    文件:TestModule.java   
public TestModule() throws ConfigurationException {

        this.injector = Guice.createInjector();

        ExecutorService service = setMock(ExecutorService.class, newDirectExecutorService());

        when(getMock(ExecutorFactory.class).get(any(Class.class), anyInt())).thenReturn(service);

        Configuration configuration = spy(new Configurations().properties(getResource(CONFIGURATION)));

        setMock(Configuration.class, configuration);

        setMock(ImmutableConfiguration.class, configuration);

    }
项目:cryptotrader    文件:TemplateContextTest.java   
@BeforeMethod
public void setUp() {

    configuration = mock(ImmutableConfiguration.class);

    target = spy(new TestContext());

    target.setConfiguration(configuration);

}
项目:cryptotrader    文件:ServiceFactoryImplTest.java   
@Test
public void testLoad() throws Exception {

    List<TestInterface> services = target.load(TestInterface.class);
    assertEquals(services.size(), 2);

    for (TestInterface s : services) {

        if (s.getClass() == TestInterface.TestImpl1.class ||
                s.getClass() == TestInterface.TestImpl3.class) {

            assertNotNull(s.getInjector());

            assertNotNull(s.getInjector().getInstance(ImmutableConfiguration.class));

            try {
                s.getInjector().getInstance(ServiceFactory.class);
                fail();
            } catch (ConfigurationException e) {
                // Success
            }

            continue;

        }

        fail("Unknown class : " + s.get());

    }

}