Search in sources :

Example 1 with SimpleNamingContextBuilder

use of org.springframework.mock.jndi.SimpleNamingContextBuilder in project Activiti by Activiti.

the class JndiEmailTest method setUp.

@BeforeClass
public void setUp() {
    Properties props = new Properties();
    props.put("mail.transport.protocol", "smtp");
    props.put("mail.smtp.provider.class", MockEmailTransport.class.getName());
    props.put("mail.smtp.class", MockEmailTransport.class.getName());
    props.put("mail.smtp.provider.vendor", "test");
    props.put("mail.smtp.provider.version", "0.0.0");
    Provider provider = new Provider(Type.TRANSPORT, "smtp", MockEmailTransport.class.getName(), "test", "1.0");
    Session mailSession = Session.getDefaultInstance(props);
    SimpleNamingContextBuilder builder = null;
    try {
        mailSession.setProvider(provider);
        builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
        builder.bind("java:comp/env/Session", mailSession);
    } catch (NamingException e) {
        logger.error("Naming error in email setup", e);
    } catch (NoSuchProviderException e) {
        logger.error("provider error in email setup", e);
    }
}
Also used : SimpleNamingContextBuilder(org.springframework.mock.jndi.SimpleNamingContextBuilder) NamingException(javax.naming.NamingException) Properties(java.util.Properties) NoSuchProviderException(javax.mail.NoSuchProviderException) Provider(javax.mail.Provider) Session(javax.mail.Session) BeforeClass(org.junit.BeforeClass)

Example 2 with SimpleNamingContextBuilder

use of org.springframework.mock.jndi.SimpleNamingContextBuilder in project midpoint by Evolveum.

the class JNDIMock method setObjects.

public void setObjects(Map<String, Object> objects) throws NamingException {
    LOGGER.info("Loading fake JNDI context.");
    if (SimpleNamingContextBuilder.getCurrentContextBuilder() != null) {
        SimpleNamingContextBuilder.getCurrentContextBuilder().deactivate();
    }
    SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
    if (objects != null) {
        for (Map.Entry<String, Object> entry : objects.entrySet()) {
            LOGGER.info("Registering '{}' with value '{}'", new Object[] { entry.getKey(), entry.getValue() });
            builder.bind(entry.getKey(), entry.getValue());
        }
    }
    builder.activate();
}
Also used : SimpleNamingContextBuilder(org.springframework.mock.jndi.SimpleNamingContextBuilder) Map(java.util.Map)

Example 3 with SimpleNamingContextBuilder

use of org.springframework.mock.jndi.SimpleNamingContextBuilder in project logging-log4j2 by apache.

the class JndiRule method apply.

@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            final SimpleNamingContextBuilder builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
            for (final Map.Entry<String, Object> entry : initialBindings.entrySet()) {
                builder.bind(entry.getKey(), entry.getValue());
            }
            base.evaluate();
        }
    };
}
Also used : SimpleNamingContextBuilder(org.springframework.mock.jndi.SimpleNamingContextBuilder) Statement(org.junit.runners.model.Statement) Map(java.util.Map)

Example 4 with SimpleNamingContextBuilder

use of org.springframework.mock.jndi.SimpleNamingContextBuilder in project ocvn by devgateway.

the class DatabaseConfiguration method jndiBuilder.

/**
     * This bean creates the JNDI tree and registers the
     * {@link javax.sql.DataSource} to this tree. This allows Pentaho Classic
     * Engine to use a {@link javax.sql.DataSource} ,in our case backed by a
     * connection pool instead of always opening up JDBC connections. Should
     * significantly improve performance of all classic reports. In PRD use
     * connection type=JNDI and name toolkitDS. To use it in PRD you need to add
     * the configuration to the local PRD. Edit
     * ~/.pentaho/simple-jndi/default.properties and add the following:
     * toolkitDS/type=javax.sql.DataSource
     * toolkitDS/driver=org.apache.derby.jdbc.ClientDriver toolkitDS/user=app
     * toolkitDS/password=app
     * toolkitDS/url=jdbc:derby://localhost//derby/toolkit
     * 
     * @return
     */
@Bean
public SimpleNamingContextBuilder jndiBuilder() {
    SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
    builder.bind(datasourceJndiName, dataSource());
    try {
        builder.activate();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NamingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return builder;
}
Also used : SimpleNamingContextBuilder(org.springframework.mock.jndi.SimpleNamingContextBuilder) NamingException(javax.naming.NamingException) Bean(org.springframework.context.annotation.Bean)

Aggregations

SimpleNamingContextBuilder (org.springframework.mock.jndi.SimpleNamingContextBuilder)4 Map (java.util.Map)2 NamingException (javax.naming.NamingException)2 Properties (java.util.Properties)1 NoSuchProviderException (javax.mail.NoSuchProviderException)1 Provider (javax.mail.Provider)1 Session (javax.mail.Session)1 BeforeClass (org.junit.BeforeClass)1 Statement (org.junit.runners.model.Statement)1 Bean (org.springframework.context.annotation.Bean)1