org.springframework.tests.mock.jndi.SimpleNamingContextBuilder Java Examples
The following examples show how to use
org.springframework.tests.mock.jndi.SimpleNamingContextBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StandardServletEnvironmentTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void propertySourceOrder() throws Exception { SimpleNamingContextBuilder.emptyActivatedContextBuilder(); ConfigurableEnvironment env = new StandardServletEnvironment(); MutablePropertySources sources = env.getPropertySources(); assertThat(sources.precedenceOf(PropertySource.named( StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), equalTo(0)); assertThat(sources.precedenceOf(PropertySource.named( StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)), equalTo(1)); assertThat(sources.precedenceOf(PropertySource.named( StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME)), equalTo(2)); assertThat(sources.precedenceOf(PropertySource.named( StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)), equalTo(3)); assertThat(sources.precedenceOf(PropertySource.named( StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)), equalTo(4)); assertThat(sources.size(), is(5)); }
Example #2
Source File: StandardServletEnvironmentTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void propertySourceOrder() throws Exception { SimpleNamingContextBuilder.emptyActivatedContextBuilder(); ConfigurableEnvironment env = new StandardServletEnvironment(); MutablePropertySources sources = env.getPropertySources(); assertThat(sources.precedenceOf(PropertySource.named( StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), equalTo(0)); assertThat(sources.precedenceOf(PropertySource.named( StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)), equalTo(1)); assertThat(sources.precedenceOf(PropertySource.named( StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME)), equalTo(2)); assertThat(sources.precedenceOf(PropertySource.named( StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)), equalTo(3)); assertThat(sources.precedenceOf(PropertySource.named( StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)), equalTo(4)); assertThat(sources.size(), is(5)); }
Example #3
Source File: ContextJndiBeanFactoryLocatorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void beanFactoryPathFromJndiEnvironmentNotFound() 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(); } catch (BeansException ex) { // Check for helpful JNDI message assertTrue(ex.getMessage().indexOf(bogusPath) != -1); } }
Example #4
Source File: ContextJndiBeanFactoryLocatorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void beanFactoryPathFromJndiEnvironmentNotValidXml() 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(); } catch (BeansException ex) { // Check for helpful JNDI message assertTrue(ex.getMessage().indexOf(nonXmlPath) != -1); } }
Example #5
Source File: PersistenceXmlParsingTests.java From spring-analysis-note with MIT License | 5 votes |
@Test 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("Exclude unlisted should be true when no value.", info[0].excludeUnlistedClasses()); assertSame(PersistenceUnitTransactionType.RESOURCE_LOCAL, info[0].getTransactionType()); assertEquals(0, info[0].getProperties().keySet().size()); builder.clear(); }
Example #6
Source File: JtaTransactionManagerSerializationTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void serializable() throws Exception { UserTransaction ut1 = mock(UserTransaction.class); UserTransaction ut2 = mock(UserTransaction.class); TransactionManager tm = mock(TransactionManager.class); JtaTransactionManager jtam = new JtaTransactionManager(); jtam.setUserTransaction(ut1); 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); assertTrue("UserTransaction looked up on client", serializedJtatm .getUserTransaction() == ut2); assertNull("TransactionManager didn't survive", serializedJtatm .getTransactionManager()); assertEquals(true, serializedJtatm.isRollbackOnCommitFailure()); }
Example #7
Source File: PersistenceXmlParsingTests.java From java-technology-stack with MIT License | 5 votes |
@Test 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("Exclude unlisted should be true when no value.", info[0].excludeUnlistedClasses()); assertSame(PersistenceUnitTransactionType.RESOURCE_LOCAL, info[0].getTransactionType()); assertEquals(0, info[0].getProperties().keySet().size()); builder.clear(); }
Example #8
Source File: JtaTransactionManagerSerializationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void serializable() throws Exception { UserTransaction ut1 = mock(UserTransaction.class); UserTransaction ut2 = mock(UserTransaction.class); TransactionManager tm = mock(TransactionManager.class); JtaTransactionManager jtam = new JtaTransactionManager(); jtam.setUserTransaction(ut1); 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); assertTrue("UserTransaction looked up on client", serializedJtatm .getUserTransaction() == ut2); assertNull("TransactionManager didn't survive", serializedJtatm .getTransactionManager()); assertEquals(true, serializedJtatm.isRollbackOnCommitFailure()); }
Example #9
Source File: ContextJndiBeanFactoryLocatorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void beanFactoryPathRequiredFromJndiEnvironment() throws Exception { // Set up initial context but don't bind anything SimpleNamingContextBuilder.emptyActivatedContextBuilder(); ContextJndiBeanFactoryLocator jbfl = new ContextJndiBeanFactoryLocator(); try { jbfl.useBeanFactory(BEAN_FACTORY_PATH_ENVIRONMENT_KEY); fail(); } catch (BootstrapException ex) { // Check for helpful JNDI message assertTrue(ex.getMessage().indexOf(BEAN_FACTORY_PATH_ENVIRONMENT_KEY) != -1); } }
Example #10
Source File: ContextJndiBeanFactoryLocatorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void beanFactoryPathFromJndiEnvironmentWithSingleFile() throws Exception { SimpleNamingContextBuilder sncb = SimpleNamingContextBuilder.emptyActivatedContextBuilder(); // Set up initial context sncb.bind(BEAN_FACTORY_PATH_ENVIRONMENT_KEY, COLLECTIONS_CONTEXT); ContextJndiBeanFactoryLocator jbfl = new ContextJndiBeanFactoryLocator(); BeanFactory bf = jbfl.useBeanFactory(BEAN_FACTORY_PATH_ENVIRONMENT_KEY).getFactory(); assertTrue(bf.containsBean("rod")); assertTrue(bf instanceof ApplicationContext); }
Example #11
Source File: ContextJndiBeanFactoryLocatorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void beanFactoryPathFromJndiEnvironmentWithMultipleFiles() throws Exception { SimpleNamingContextBuilder sncb = SimpleNamingContextBuilder.emptyActivatedContextBuilder(); String path = String.format("%s %s", COLLECTIONS_CONTEXT, PARENT_CONTEXT); // 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")); }
Example #12
Source File: PersistenceXmlParsingTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test 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("Exclude unlisted should be true when no value.", info[0].excludeUnlistedClasses()); assertSame(PersistenceUnitTransactionType.RESOURCE_LOCAL, info[0].getTransactionType()); assertEquals(0, info[0].getProperties().keySet().size()); builder.clear(); }
Example #13
Source File: JtaTransactionManagerSerializationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void serializable() throws Exception { UserTransaction ut1 = mock(UserTransaction.class); UserTransaction ut2 = mock(UserTransaction.class); TransactionManager tm = mock(TransactionManager.class); JtaTransactionManager jtam = new JtaTransactionManager(); jtam.setUserTransaction(ut1); 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); assertTrue("UserTransaction looked up on client", serializedJtatm .getUserTransaction() == ut2); assertNull("TransactionManager didn't survive", serializedJtatm .getTransactionManager()); assertEquals(true, serializedJtatm.isRollbackOnCommitFailure()); }
Example #14
Source File: StandardServletEnvironmentTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void propertySourceOrder() throws Exception { SimpleNamingContextBuilder.emptyActivatedContextBuilder(); ConfigurableEnvironment env = new StandardServletEnvironment(); MutablePropertySources sources = env.getPropertySources(); assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), equalTo(0)); assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)), equalTo(1)); assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME)), equalTo(2)); assertThat(sources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)), equalTo(3)); assertThat(sources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)), equalTo(4)); assertThat(sources.size(), is(5)); }