Package org.springframework.core.env

Examples of org.springframework.core.env.Environment


@PrepareForTest({DataSources.class, EmbeddedDatabaseBuilder.class })
public class DataSourcesTest {

  @Test
  public void mem() throws Exception {
    Environment env = createMock(Environment.class);
    expect(env.getRequiredProperty("db")).andReturn("mem");

    EmbeddedDatabase datasource = createMock(EmbeddedDatabase.class);

    EmbeddedDatabaseBuilder embeddedDatabaseBuilder =
        PowerMock.createMockAndExpectNew(EmbeddedDatabaseBuilder.class);
View Full Code Here


  }

  @SuppressWarnings("unchecked")
  @Test
  public void fs() throws Exception {
    Environment env = createMock(Environment.class);
    expect(env.getRequiredProperty("db")).andReturn("fs");
    expect(env.getProperty("application.name", "testdb")).andReturn("fsdb");

    SimpleDriverDataSource dataSource =
        PowerMock.createMockAndExpectNew(SimpleDriverDataSource.class);
    dataSource.setDriverClass((Class<? extends Driver>) Class
        .forName("org.h2.Driver"));
View Full Code Here

    String database = "jdbc:real:db";
    String dbDriver = "com.my.Driver";
    String dbUser = "user";
    String dbPass = "pass";

    Environment env = createMock(Environment.class);
    expect(env.getRequiredProperty("db")).andReturn(database);
    expect(env.getProperty(DataSources.DB_DRIVER, "com.mysql.jdbc.Driver"))
        .andReturn(dbDriver);
    expect(env.getRequiredProperty(DataSources.DB_USER))
        .andReturn(dbUser);
    expect(env.getRequiredProperty(DataSources.DB_PASSWORD))
        .andReturn(dbPass);
    expect(
        env.getProperty(DataSources.DB_IDDLE_CONNECTION_TEST_PERIOD,
            Integer.class, 14400))
        .andReturn(14400);
    expect(env.getProperty(DataSources.DB_IDDLE_MAX_AGE, Integer.class, 3600))
        .andReturn(3600);
    expect(
        env.getProperty(DataSources.DB_MAX_CONNECTIONS_PER_PARTITION,
            Integer.class, 30))
        .andReturn(30);
    expect(
        env.getProperty(DataSources.DB_MIN_CONNECTIONS_PER_PARTITION,
            Integer.class, 10))
        .andReturn(10);
    expect(
        env.getProperty(DataSources.DB_PARTITION_COUNT,
            Integer.class, 3))
        .andReturn(3);
    expect(
        env.getProperty(DataSources.DB_ACQUIRE_INCREMENT,
            Integer.class, 5))
        .andReturn(5);
    expect(
        env.getProperty(DataSources.DB_STATEMENTS_CACHE_SIZE,
            Integer.class, 20))
        .andReturn(20);

    BoneCPDataSource dataSource =
        PowerMock.createMockAndExpectNew(BoneCPDataSource.class);
View Full Code Here

    try {
      List<Resource> properties = findResources(propertySources());
      if (properties.size() == 0) {
        logger.warn("No property files were found.");
      }
      final Environment env = context.getEnvironment();

      // Special properties
      Map<String, Object> specialProps = new HashMap<String, Object>();
      String appName = env.getProperty(APP_NAME);
      if (appName == null) {
        // No set, defaults to contextPath
        appName = getClass().getSimpleName();
        specialProps.put(APP_NAME, appName);
      }
View Full Code Here

   * @return A new {@link CamelContext}.
   */
  @Bean(destroyMethod = "stop")
  public DefaultCamelContext camelContext(final ApplicationContext applicationContext) {
    notNull(applicationContext, "The application's context is required.");
    Environment env = applicationContext.getEnvironment();

    final DefaultCamelContext camelContext = new DefaultCamelContext(
        new ApplicationContextRegistry(applicationContext));

    // Runtime configuration
    Long delayer = env.getProperty("camel.delayer", Long.class);
    camelContext.setDelayer(delayer);

    Boolean handleFault = env.getProperty("camel.handleFault", Boolean.class, Boolean.FALSE);
    camelContext.setHandleFault(handleFault);

    String shutdownRoute = env.getProperty("camel.shutdownRoute", ShutdownRoute.Default.name());
    camelContext.setShutdownRoute(ShutdownRoute.valueOf(shutdownRoute));

    String shutdownRunningTask = env.getProperty("camel.shutdownRunningTask",
        ShutdownRunningTask.CompleteCurrentTaskOnly.name());
    camelContext.setShutdownRunningTask(ShutdownRunningTask.valueOf(shutdownRunningTask));

    Boolean streamCaching = env.getProperty("camel.streamCaching", Boolean.class, Boolean.FALSE);
    camelContext.setStreamCaching(streamCaching);

    Boolean tracing = env.getProperty("camel.tracing", Boolean.class, Boolean.FALSE);
    camelContext.setTracing(tracing);

    camelContext.addComponent("properties", camelProperties(applicationContext));

    return camelContext;
View Full Code Here

   */
  @Bean
  public static CoreContainer solrCores(final ApplicationContext context)
      throws IOException, ParserConfigurationException, SAXException {
    notNull(context, "The application's context is required.");
    Environment env = context.getEnvironment();

    final File solrHome = findSolrHome(context);
    File solrXml = new File(solrHome, "solr.xml");
    isTrue(solrXml.exists(), "File not found: {}", solrXml);

View Full Code Here

   * is: true.
   * </ul>
   */
  @PostConstruct
  public void runFixtures() {
    Environment env = applicationContext.getEnvironment();
    boolean runFixtures = env.getProperty(SOLR_FIXTURES, boolean.class, true);
    if (runFixtures) {
      Map<String, SolrServer> servers = applicationContext.getBeansOfType(SolrServer.class);
      CoreContainer cores = applicationContext.getBean(CoreContainer.class);
      String solrHome = cores.getSolrHome();

      boolean async = env.getProperty(SOLR_FIXTURES_ASYNC, boolean.class, true);

      for (Entry<String, SolrServer> server : servers.entrySet()) {
        String coreName = server.getKey();
        File coreHome = new File(solrHome, coreName);
        File fixtures = new File(coreHome, "fixtures");
View Full Code Here

   * @return The solr's home directory.
   * @throws IOException If the solr.home cannot be resolve.
   */
  private static File findSolrHome(final ApplicationContext context)
      throws IOException {
    Environment env = context.getEnvironment();
    String solrHome = env.getRequiredProperty(SOLR_HOME);
    File solrHomeDir = new File(solrHome);
    if (!solrHomeDir.exists()) {
      // Ask Spring for it
      Resource resource = context.getResource(solrHome);
      if (!resource.exists()) {
View Full Code Here

  @Test
  public void dataSource() throws Exception {
    DataSource dataSource = createMock(DataSource.class);

    Environment env = createMock(Environment.class);

    PowerMock.mockStatic(DataSources.class);
    expect(DataSources.build(env)).andReturn(dataSource);

    PowerMock.replay(DataSources.class);
View Full Code Here

  @Test
  public void entityManagerFactoryMemDB() throws Exception {
    DataSource dataSource = createMock(DataSource.class);

    final Environment env = createMock(Environment.class);
    String mode = "create";

    expect(env.getRequiredProperty(DataSources.DATABASE)).andReturn("mem");
    expect(env.getRequiredProperty("application.ns", String[].class)).andReturn(
        new String[]{JpaModuleTest.class.getPackage().getName() });
    expect(env.getProperty(JpaModule.DB_SCHEMA, "update")).andReturn(mode);

    ReflectionUtils.doWithFields(AvailableSettings.class, new FieldCallback() {
      @Override
      public void doWith(final Field field) throws IllegalArgumentException,
          IllegalAccessException {
        String propertyName = (String) field.get(null);
        expect(env.getProperty(propertyName)).andReturn(null);
      }
    });

    ApplicationContext context = createMock(ApplicationContext.class);
    expect(context.getEnvironment()).andReturn(env);
View Full Code Here

TOP

Related Classes of org.springframework.core.env.Environment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.