Package org.springframework.mock.jndi

Examples of org.springframework.mock.jndi.SimpleNamingContextBuilder


  /**
   * Demonstrates how emptyActivatedContextBuilder() method can be
   * used repeatedly, and how it affects creating a new InitialContext()
   */
  public void testCreateInitialContext() throws Exception {
    SimpleNamingContextBuilder builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
    String name = "foo";
    Object o = new Object();
    builder.bind(name, o);
    // Check it affects JNDI
    Context ctx = new InitialContext();
    assertTrue(ctx.lookup(name) == o);
    // Check it returns mutable contexts
    ctx.unbind(name);
    try {
      ctx = new InitialContext();
      ctx.lookup(name);
      fail("Should have thrown NamingException");
    }
    catch (NamingException ex) {
      // expected
    }
   
    // Check the same call will work again, but the context is empty
    builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
    try {
      ctx = new InitialContext();
      ctx.lookup(name);
      fail("Should have thrown NamingException");
    }
    catch (NamingException ex) {
      // expected
    }
    Object o2 = new Object();
    builder.bind(name, o2);
    assertEquals(ctx.lookup(name), o2);
  }
View Full Code Here


  private static final String EX_FILE_3 = "src/test/resources/data/docs/test.xmi";

  @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();
  }
View Full Code Here

*/
public class SpringContextLoaderTest {

  @Before
  public final void setUp() throws Exception {
    SimpleNamingContextBuilder jndi = SimpleNamingContextBuilder
        .emptyActivatedContextBuilder();
    DataSource ds = new DriverManagerDataSource();
    jndi.bind("java:comp/env/jdbc/RecordShopDS", ds);

    JtaTransactionManager jtam = new JtaTransactionManager();
    jtam.setUserTransaction(EasyMock.createMock(UserTransaction.class));
    jndi.bind(JtaTransactionManager.DEFAULT_USER_TRANSACTION_NAME, jtam
        .getUserTransaction());
  }
View Full Code Here

            synchronized (JNDISetup.class) {

                if (!setup) {
                    try {
                        NamingManager
                                .setInitialContextFactoryBuilder(new SimpleNamingContextBuilder());
                    }
                    catch (NamingException e) {
                        logger.error("Can't perform JNDI setup, ignoring...", e);
                    }
View Full Code Here

*/
public class CdiObjectFactoryTest {

    @Before
    public void setUp() throws Exception {
        SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
        builder.activate();

        StartMain sm = new StartMain(new String[0]);
        WeldContainer weldContainer = sm.go();
        builder.bind(CdiObjectFactory.CDI_JNDIKEY_BEANMANAGER_COMP, weldContainer.getBeanManager());
    }
View Full Code Here

        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(e);
        } catch (NoSuchProviderException e) {
            logger.error(e);
        }
View Full Code Here

    @BeforeClass
    public static void setupJNDI() throws IllegalStateException, NamingException {
        if (SimpleNamingContextBuilder.getCurrentContextBuilder() == null) {
            LOGGER.info("Setting up new Context");
            SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();

            ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(getTestContext());
            builder.bind("java:comp/env/jdbc/ptcollectDS", context.getBean("ptcollectDS"));
            builder.activate();
        }
    }
View Full Code Here

TOP

Related Classes of org.springframework.mock.jndi.SimpleNamingContextBuilder

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.