Package org.springframework.core.env

Examples of org.springframework.core.env.Environment


        springSecurityFilter.setAsyncSupported(true);

        initAtmosphereServlet(servletContext);

        Environment env = rootContext.getBean(Environment.class);
        if (env.acceptsProfiles(Constants.SPRING_PROFILE_METRICS)) {
            initMetricsServlet(servletContext, disps, dispatcherServlet);
            springSecurityFilter.addMappingForServletNames(disps, true, "dispatcher", "atmosphereServlet", "metricsAdminServlet");
        } else {
            springSecurityFilter.addMappingForServletNames(disps, true, "dispatcher", "atmosphereServlet");
        }
View Full Code Here


*/
public class MorphiaModuleTest {

  @Test
  public void morphia() {
    Environment env = createMock(Environment.class);
    expect(env.getProperty(APP_NAMESPACE, String[].class)).andReturn(
        new String[]{getClass().getPackage().getName() });

    replay(env);

    Morphia morphia = new MorphiaModule().morphia(env);
View Full Code Here

@PrepareForTest({MailModule.class, JavaMailSenderImpl.class })
public class MailModuleTest {

  @Test
  public void mailSender() throws Exception {
    Environment env = createMock(Environment.class);
    String host = "mail.server.com";
    String sendpartial = "true";

    expect(env.getRequiredProperty(SMTP_HOST)).andReturn(host);
    expect(env.getProperty(SMTP_SENDPARTIAL, sendpartial)).andReturn("true");
    expect(env.getProperty(SMTP_PORT)).andReturn("");
    expect(env.getProperty(SMTP_START_TLS)).andReturn(null);
    expect(env.getProperty(MAIL_USER)).andReturn(null);
    expect(env.getProperty(SMTP_ALLOW_8BIT_MIME)).andReturn("");
    expect(env.getProperty(SMTP_DSN_NOTIFY)).andReturn(null);
    expect(env.getProperty(SMTP_DSN_RET)).andReturn(null);
    expect(env.getProperty(SMTP_ENVELOP_FROM)).andReturn(null);

    JavaMailSenderImpl mailSender =
        PowerMock.createMockAndExpectNew(JavaMailSenderImpl.class);
    Capture<Properties> properties = new Capture<Properties>();
    mailSender.setJavaMailProperties(capture(properties));
View Full Code Here

    String sendpartial = "true";
    String startTls = "true";
    String user = "user@gmail.com";
    String pass = "pass";

    Environment env = createMock(Environment.class);
    expect(env.getRequiredProperty(SMTP_HOST)).andReturn(host);
    expect(env.getProperty(SMTP_SENDPARTIAL, "true")).andReturn(sendpartial);
    expect(env.getProperty(SMTP_PORT)).andReturn(port);
    expect(env.getProperty(SMTP_START_TLS)).andReturn(startTls);
    expect(env.getProperty(MAIL_USER)).andReturn(user);
    expect(env.getRequiredProperty(MAIL_PASSWORD)).andReturn(pass);
    expect(env.getProperty(SMTP_ALLOW_8BIT_MIME)).andReturn("");
    expect(env.getProperty(SMTP_DSN_NOTIFY)).andReturn(null);
    expect(env.getProperty(SMTP_DSN_RET)).andReturn(null);
    expect(env.getProperty(SMTP_ENVELOP_FROM)).andReturn(null);

    JavaMailSenderImpl mailSender =
        PowerMock.createMockAndExpectNew(JavaMailSenderImpl.class);
    Capture<Properties> properties = new Capture<Properties>();
    mailSender.setJavaMailProperties(capture(properties));
View Full Code Here

  @Bean
  public EntityManagerFactoryBean jpaEntityManagerFactory(
      final ApplicationContext applicationContext) throws ClassNotFoundException {
    EntityManagerFactoryBean emf = new EntityManagerFactoryBean(applicationContext);
    logger.info("Starting service: {}", EntityManagerFactory.class.getSimpleName());
    final Environment env = applicationContext.getEnvironment();
    String[] namespace = env
        .getRequiredProperty(ApplicationConstants.APP_NAMESPACE, String[].class);

    String hbm2ddl = env.getProperty(DB_SCHEMA, "update");
    final Map<String, String> properties = new HashMap<String, String>();
    logger.info("  schema's mode: {}", hbm2ddl);
    properties.put(AvailableSettings.HBM2DDL_AUTO, hbm2ddl);

    // default dialect
    Class<?> dialect = DefaultDialect.dialect(env.getRequiredProperty(DataSources.DATABASE));
    if (dialect != null) {
      properties.put(AvailableSettings.DIALECT, dialect.getName());
    }

    /**
     * Looks for Hibernate properties and set them all.
     */
    ReflectionUtils.doWithFields(AvailableSettings.class, new FieldCallback() {
      @Override
      public void doWith(final Field field) throws IllegalAccessException {
        String propertyName = (String) field.get(null);
        String propertyValue = env.getProperty(propertyName);
        if (!StringUtils.isEmpty(propertyValue)) {
          properties.put(propertyName, propertyValue);
        }
      }
    }, new FieldFilter() {
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);

    final File dataDir = findSolrDataDir(env);

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

   */
  protected void configure(final HibernateEntityManagerFactory emf,
      final SessionFactoryImplementor sessionFactory) {
    // load fixtures
    Map<String, ClassMetadata> metadata = sessionFactory.getAllClassMetadata();
    Environment env = applicationContext.getEnvironment();
    String baseDir = env.getProperty(JpaModule.DB_FIXTURES, JpaModule.DB_DEFAULT_FIXTURES);
    notEmpty(baseDir, "{} isn't set", JpaModule.DB_FIXTURES);
    JpaFixtures.load(applicationContext, emf, baseDir, metadata);

    // configure
    configure(sessionFactory.getServiceRegistry());
View Full Code Here

@PrepareForTest({MongoModule.class, SimpleMongoDbFactory.class })
public class MongoModuleTest {

  @Test
  public void mongoURI() throws Exception {
    Environment env = createMock(Environment.class);
    expect(env.getRequiredProperty("db")).andReturn("mongodb://localhost/mydb");

    replay(env);

    MongoURI mongoURI = new MongoModule().mongoURI(env);
    assertNotNull(mongoURI);
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.