Example usage for org.springframework.mock.jndi SimpleNamingContextBuilder bind

List of usage examples for org.springframework.mock.jndi SimpleNamingContextBuilder bind

Introduction

In this page you can find the example usage for org.springframework.mock.jndi SimpleNamingContextBuilder bind.

Prototype

public void bind(String name, Object obj) 

Source Link

Document

Bind the given object under the given name, for all naming contexts that this context builder will generate.

Usage

From source file:edu.cmu.hcii.stepgreen.data.SpringWiringTest.java

@BeforeClass
public static void setUp() throws NamingException {
    DataSource dataSource = mock(DataSource.class);

    SimpleNamingContextBuilder builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
    builder.bind("java:comp/env/jdbc/app-energy-labeler", dataSource);
}

From source file:fi.nls.fileservice.web.IntegrationTest.java

@BeforeClass
public static void setUp() throws IllegalStateException, NamingException {
    // Register in mock JNDI
    // an embedded HSQLDB with PostgreSQL syntax enabled
    DataSource dataSource = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL)
            .setName("tiepaldb;sql.syntax_pgs=true").addScript("file:../resources/sql/create-tables.sql")
            .addScript("file:../resources/sql/data-hsql.sql").build();

    SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
    builder.bind("java:comp/env/jdbc/tiepaldb", dataSource);
    builder.activate();//from  www  .  jav  a 2s.co  m

}

From source file:com.redhat.rhtracking.persistance.unittest.JPATestUtils.java

public static void mockJndiDatasource() throws PropertyVetoException, NamingException, IllegalStateException {
    SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();

    ComboPooledDataSource pool = new ComboPooledDataSource();
    pool.setDriverClass("org.postgresql.Driver");
    pool.setJdbcUrl("jdbc:postgresql://localhost:5432/rhtracking");
    pool.setUser("dev02");
    pool.setPassword("abcd");
    builder.bind("java:comp/env/jdbc/rhtracking", pool);
    builder.bind("java:/jdbc/rhtracking", pool);
    builder.activate();/*from ww  w .jav a 2  s. c  o m*/
}

From source file:org.uimafit.factory.ExternalResourceFactoryTest.java

@BeforeClass
public static void initJNDI() throws Exception {
    // Set up JNDI context to test the JndiResourceLocator
    final SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
    Properties deDict = new Properties();
    deDict.setProperty("Hans", "proper noun");
    builder.bind("dictionaries/german", deDict);
    builder.activate();//from   ww w  . j a v a 2 s  .c o  m
}

From source file:sk.lazyman.gizmo.JndiH2DataSource.java

public void init() throws NamingException {
    SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
    builder.bind("java:comp/env/jdbc/GizmoDB", dataSource);
    builder.activate();//from w w  w  .j  a  v  a 2 s  . c  o  m
}

From source file:org.devgateway.toolkit.persistence.spring.DatabaseConfiguration.java

/**
 * 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// ww w  .  j  a v  a  2 s  .com
 * 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;
}

From source file:example.app.config.support.NamingContextBuilderFactoryBean.java

@Override
public void afterPropertiesSet() throws Exception {
    SimpleNamingContextBuilder namingContextBuilder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();

    for (Map.Entry<String, Object> boundObject : boundObjects.entrySet()) {
        namingContextBuilder.bind(boundObject.getKey(), boundObject.getValue());
    }/*from   w  ww. j  a  v a 2  s  .c  om*/
}

From source file:dk.teachus.backend.test.SpringTestCase.java

@Override
protected String[] getConfigLocations() {
    final List<String> configLocations = new ArrayList<String>();

    configLocations.add("/dk/teachus/backend/applicationContext.xml");
    configLocations.add("/dk/teachus/backend/dao/hibernate/applicationContext-hibernate.xml");
    configLocations.add("/dk/teachus/frontend/applicationContext-frontend.xml");

    DataSource dataSource = null;
    if (SpringTestCase.useMysql) {
        final MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource();
        ds.setUrl("jdbc:mysql://localhost/teachus_test");
        ds.setUser("teachus_build");
        ds.setPassword("teachus_build");
        dataSource = ds;//from  w  w  w.  j  a  v a  2s .co  m
        configLocations.add("/dk/teachus/backend/test/applicationContext-test-mysql.xml");
    } else {
        dataSource = new SimpleDriverDataSource(new jdbcDriver(), "jdbc:hsqldb:mem:teachus", "sa", "");
        configLocations.add("/dk/teachus/backend/test/applicationContext-test-hsqldb.xml");
    }

    final SimpleNamingContextBuilder contextBuilder = new SimpleNamingContextBuilder();
    contextBuilder.bind("java:comp/env/jdbc/teachus", dataSource);
    try {
        contextBuilder.activate();
    } catch (final IllegalStateException e) {
        throw new RuntimeException(e);
    } catch (final NamingException e) {
        throw new RuntimeException(e);
    }

    addConfigLocations(configLocations);

    return configLocations.toArray(new String[configLocations.size()]);
}

From source file:org.ow2.authzforce.upgrader.test.UpgradedDataLoadTest.java

/**
 * Test parameters from testng.xml are ignored when executing with maven surefire plugin, so we use default values for all.
 * /*from ww w .  j a v  a2s  .  c  om*/
 * WARNING: the BeforeTest-annotated method must be in the test class, not in a super class although the same method logic is used in other test class
 * 
 * @param serverRootDir
 * 
 * @param domainSyncIntervalSec
 * @throws Exception
 */
@Parameters({ "server.root.dir", "org.ow2.authzforce.domains.sync.interval" })
@BeforeTest
public void beforeTest(String serverRootDir, @Optional("-1") int domainSyncIntervalSec) throws Exception {
    System.out.println("Testing data in directory: " + serverRootDir);
    final File targetDir = new File("target");
    // set catalina.base property in server's logback.xml
    System.setProperty("catalina.base", targetDir.toURI().toString());

    final File confDir = new File(serverRootDir + "/conf");
    final String confURI = confDir.toURI().toString();
    final File dataDir = new File(serverRootDir + "/data");
    final String dataURI = dataDir.toURI().toString();

    // Set some server properties via JNDI
    try {
        final SimpleNamingContextBuilder jndiCtxFactoryBuilder = SimpleNamingContextBuilder
                .emptyActivatedContextBuilder();
        jndiCtxFactoryBuilder.bind("java:comp/env/org.ow2.authzforce.config.dir", confURI);
        jndiCtxFactoryBuilder.bind("java:comp/env/org.ow2.authzforce.data.dir", dataURI);
        jndiCtxFactoryBuilder.bind("java:comp/env/org.ow2.authzforce.uuid.gen.randomMulticastAddressBased",
                Boolean.TRUE);
        jndiCtxFactoryBuilder.bind("java:comp/env/org.ow2.authzforce.domains.sync.interval", new Integer(-1));
    } catch (NamingException ex) {
        throw new RuntimeException("Error setting property via JNDI", ex);
    }

    /*
     * Workaround for: http://stackoverflow.com/questions/10184602/accessing -spring-context-in-testngs -beforetest https://jira.spring.io/browse/SPR-4072
     * https://jira.spring.io/browse/SPR-5404 (duplicate of previous issue) springTestContextPrepareTestInstance() happens in
     * 
     * @BeforeClass before no access to Autowired beans by default in
     * 
     * @BeforeTest
     */
    super.springTestContextPrepareTestInstance();
    testDomainId = domainsResourceBean.getDomains(null).getLinks().get(0).getHref();
    testDomain = domainsResourceBean.getDomainResource(testDomainId);
}

From source file:com.agiletec.ConfigTestUtils.java

protected SimpleNamingContextBuilder createNamingContext() {
    SimpleNamingContextBuilder builder = null;
    try {/*from  ww  w .  j a v  a  2  s  . c o m*/
        builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
        InputStream in = new FileInputStream("target/test/conf/contextTestParams.properties");
        Properties testConfig = new Properties();
        testConfig.load(in);
        in.close();

        builder.bind("java:comp/env/logName", testConfig.getProperty("logName"));
        builder.bind("java:comp/env/logFilePrefix", testConfig.getProperty("logFilePrefix"));
        builder.bind("java:comp/env/logLevel", testConfig.getProperty("logLevel"));
        builder.bind("java:comp/env/logFileSize", testConfig.getProperty("logFileSize"));
        builder.bind("java:comp/env/logFilesCount", testConfig.getProperty("logFilesCount"));

        builder.bind("java:comp/env/configVersion", testConfig.getProperty("configVersion"));

        builder.bind("java:comp/env/applicationBaseURL", testConfig.getProperty("applicationBaseURL"));
        builder.bind("java:comp/env/resourceRootURL", testConfig.getProperty("resourceRootURL"));
        builder.bind("java:comp/env/protectedResourceRootURL",
                testConfig.getProperty("protectedResourceRootURL"));
        builder.bind("java:comp/env/resourceDiskRootFolder", testConfig.getProperty("resourceDiskRootFolder"));
        builder.bind("java:comp/env/protectedResourceDiskRootFolder",
                testConfig.getProperty("protectedResourceDiskRootFolder"));

        builder.bind("java:comp/env/indexDiskRootFolder", testConfig.getProperty("indexDiskRootFolder"));

        Iterator<Entry<Object, Object>> configIter = testConfig.entrySet().iterator();
        while (configIter.hasNext()) {
            Entry<Object, Object> entry = configIter.next();
            builder.bind("java:comp/env/" + (String) entry.getKey(), (String) entry.getValue());
        }

        this.createDatasources(builder, testConfig);
    } catch (Throwable t) {
        t.printStackTrace();
        throw new RuntimeException("Error on creation naming context", t);
    }
    return builder;
}