Package org.springframework.mock.jndi

Examples of org.springframework.mock.jndi.SimpleNamingContextBuilder


    jtam.setUserTransaction(ut);
    jtam.setTransactionManager(tm);
    jtam.setRollbackOnCommitFailure(true);
    jtam.afterPropertiesSet();

    SimpleNamingContextBuilder jndiEnv = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
    jndiEnv.bind(JtaTransactionManager.DEFAULT_USER_TRANSACTION_NAME, ut2);
    JtaTransactionManager serializedJtatm =
        (JtaTransactionManager) SerializationTestUtils.serializeAndDeserialize(jtam);
   
    // should do client-side lookup
    assertNotNull("Logger must survive serialization", serializedJtatm.logger);
View Full Code Here


    assertNull(info[0].getJtaDataSource());
    assertNull(info[0].getNonJtaDataSource());
  }

  public void testExample4() throws Exception {
    SimpleNamingContextBuilder builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
    DataSource ds = new DriverManagerDataSource();
    builder.bind("java:comp/env/jdbc/MyDB", ds);

    PersistenceUnitReader reader = new PersistenceUnitReader(
        new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
    String resource = "/org/springframework/orm/jpa/persistence-example4.xml";
    PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);

    assertNotNull(info);
    assertEquals(1, info.length);
    assertEquals("OrderManagement4", info[0].getPersistenceUnitName());

    assertEquals(1, info[0].getMappingFileNames().size());
    assertEquals("order-mappings.xml", info[0].getMappingFileNames().get(0));

    assertEquals(3, info[0].getManagedClassNames().size());
    assertEquals("com.acme.Order", info[0].getManagedClassNames().get(0));
    assertEquals("com.acme.Customer", info[0].getManagedClassNames().get(1));
    assertEquals("com.acme.Item", info[0].getManagedClassNames().get(2));

    assertTrue(info[0].excludeUnlistedClasses());

    assertSame(PersistenceUnitTransactionType.RESOURCE_LOCAL, info[0].getTransactionType());
    assertEquals(0, info[0].getProperties().keySet().size());

    // TODO this is undefined as yet. Do we look up Spring datasource?
    // assertNotNull(info[0].getNonJtaDataSource());
    //
    // assertEquals(ds .toString(),
    // info[0].getNonJtaDataSource().toString());

    builder.clear();
  }
View Full Code Here

        }
    }
   
    public static void setupJndiDataSourceContext(String jndiPath, Logger logger) throws Exception {
        setup();
        SimpleNamingContextBuilder builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
        DriverManagerDataSource ds = new DriverManagerDataSource();
        Map<String, String> jndiValuesMap = getJndiProperties( logger );
        ds.setDriverClassName( jndiValuesMap.get( "hibernate.connection.driver_class" ) );
        ds.setUrl( jndiValuesMap.get( "hibernate.connection.url" ) );
        ds.setUsername( jndiValuesMap.get( "hibernate.connection.username" ) );
        ds.setPassword( jndiValuesMap.get( "hibernate.connection.password" ) );
        builder.bind( jndiPath, ds );
        builder.bind( "java:/TransactionManager", new MockTransactionManager() );
    }
View Full Code Here

        }
    }

    public static void setupJndiDataSourceContext(String jndiPath, Logger logger) throws Exception {
        JNDIHelper.setup();
        SimpleNamingContextBuilder builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
        DriverManagerDataSource ds = new DriverManagerDataSource();
        Map<String, String> jndiValuesMap = JNDIHelper.getJndiProperties( logger );
        ds.setDriverClassName( jndiValuesMap.get( "hibernate.connection.driver_class" ) );
        ds.setUrl( jndiValuesMap.get( "hibernate.connection.url" ) );
        ds.setUsername( jndiValuesMap.get( "hibernate.connection.username" ) );
        ds.setPassword( jndiValuesMap.get( "hibernate.connection.password" ) );
        builder.bind( jndiPath, ds );
        builder.bind( "java:/TransactionManager", new MockTransactionManager() );
    }
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

      assertTrue(ex.getMessage().indexOf(BEAN_FACTORY_PATH_ENVIRONMENT_KEY) != -1);
    }
  }

  public void testBeanFactoryPathFromJndiEnvironmentNotFound() throws Exception  {
    SimpleNamingContextBuilder sncb = SimpleNamingContextBuilder.emptyActivatedContextBuilder();

    String bogusPath = "RUBBISH/com/xxxx/framework/server/test1.xml";

    // Set up initial context
    sncb.bind(BEAN_FACTORY_PATH_ENVIRONMENT_KEY, bogusPath);

    ContextJndiBeanFactoryLocator jbfl = new ContextJndiBeanFactoryLocator();
    try {
      jbfl.useBeanFactory(BEAN_FACTORY_PATH_ENVIRONMENT_KEY);
      fail();
View Full Code Here

      assertTrue(ex.getMessage().indexOf(bogusPath) != -1);
    }
  }

  public void testBeanFactoryPathFromJndiEnvironmentNotValidXml() throws Exception {
    SimpleNamingContextBuilder sncb = SimpleNamingContextBuilder.emptyActivatedContextBuilder();

    String nonXmlPath = "com/xxxx/framework/server/SlsbEndpointBean.class";

    // Set up initial context
    sncb.bind(BEAN_FACTORY_PATH_ENVIRONMENT_KEY, nonXmlPath);

    ContextJndiBeanFactoryLocator jbfl = new ContextJndiBeanFactoryLocator();
    try {
      jbfl.useBeanFactory(BEAN_FACTORY_PATH_ENVIRONMENT_KEY);
      fail();
View Full Code Here

      assertTrue(ex.getMessage().indexOf(nonXmlPath) != -1);
    }
  }

  public void testBeanFactoryPathFromJndiEnvironmentWithSingleFile() throws Exception {
    SimpleNamingContextBuilder sncb = SimpleNamingContextBuilder.emptyActivatedContextBuilder();

    String path = "org/springframework/beans/factory/xml/collections.xml";

    // Set up initial context
    sncb.bind(BEAN_FACTORY_PATH_ENVIRONMENT_KEY, path);

    ContextJndiBeanFactoryLocator jbfl = new ContextJndiBeanFactoryLocator();
    BeanFactory bf = jbfl.useBeanFactory(BEAN_FACTORY_PATH_ENVIRONMENT_KEY).getFactory();
    assertTrue(bf.containsBean("rod"));
    assertTrue(bf instanceof ApplicationContext);
View Full Code Here

    assertTrue(bf.containsBean("rod"));
    assertTrue(bf instanceof ApplicationContext);
  }

  public void testBeanFactoryPathFromJndiEnvironmentWithMultipleFiles() throws Exception {
    SimpleNamingContextBuilder sncb = SimpleNamingContextBuilder.emptyActivatedContextBuilder();

    String path = "/org/springframework/beans/factory/xml/collections.xml /org/springframework/beans/factory/xml/parent.xml";

    // Set up initial context
    sncb.bind(BEAN_FACTORY_PATH_ENVIRONMENT_KEY, path);

    ContextJndiBeanFactoryLocator jbfl = new ContextJndiBeanFactoryLocator();
    BeanFactory bf = jbfl.useBeanFactory(BEAN_FACTORY_PATH_ENVIRONMENT_KEY).getFactory();
    assertTrue(bf.containsBean("rod"));
    assertTrue(bf.containsBean("inheritedTestBean"));
View Full Code Here

* @author Juergen Hoeller
*/
public class SimpleNamingContextTests extends TestCase {

  public void testNamingContextBuilder() throws NamingException {
    SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
    InitialContextFactory factory = builder.createInitialContextFactory(null);

    DataSource ds = new DriverManagerDataSource();
    builder.bind("java:comp/env/jdbc/myds", ds);
    Object obj = new Object();
    builder.bind("myobject", obj);

    Context context1 = factory.getInitialContext(null);
    assertTrue("Correct DataSource registered", context1.lookup("java:comp/env/jdbc/myds") == ds);
    assertTrue("Correct Object registered", context1.lookup("myobject") == obj);

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.