Java Code Examples for org.springframework.mock.jndi.SimpleNamingContextBuilder#bind()
The following examples show how to use
org.springframework.mock.jndi.SimpleNamingContextBuilder#bind() .
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: StdJndiLoaderTest.java From andhow with Apache License 2.0 | 6 votes |
@Test public void testValidationIsEnforcedWhenExactTypeUsed() throws Exception { SimpleNamingContextBuilder jndi = getJndi(); CaseInsensitiveNaming bns = new CaseInsensitiveNaming(); jndi.bind("java:" + NameUtil.getAndHowName(ValidParams.class, ValidParams.INT_TEN), Integer.parseInt("9")); jndi.bind("java:" + bns.getUriName(NameUtil.getAndHowName(ValidParams.class, ValidParams.STR_XXX)), "YYY"); jndi.activate(); try { AndHowConfiguration config = AndHowCoreTestConfig.instance() .group(ValidParams.class); AndHow.instance(config); fail("Should not reach this point"); } catch (AppFatalException e) { List<Problem> vps = e.getProblems(); assertEquals(2, vps.size()); } }
Example 2
Source File: TestEntandoJndiUtils.java From entando-core with GNU Lesser General Public License v3.0 | 6 votes |
private static void createDatasource(String dsNameControlKey, SimpleNamingContextBuilder builder, Properties testConfig) { String beanName = testConfig.getProperty("jdbc." + dsNameControlKey + ".beanName"); try { String className = testConfig.getProperty("jdbc." + dsNameControlKey + ".driverClassName"); String url = testConfig.getProperty("jdbc." + dsNameControlKey + ".url"); String username = testConfig.getProperty("jdbc." + dsNameControlKey + ".username"); String password = testConfig.getProperty("jdbc." + dsNameControlKey + ".password"); Class.forName(className); BasicDataSource ds = new BasicDataSource(); ds.setUrl(url); ds.setUsername(username); ds.setPassword(password); ds.setMaxTotal(12); ds.setMaxIdle(4); ds.setDriverClassName(className); builder.bind("java:comp/env/jdbc/" + beanName, ds); } catch (Throwable t) { throw new RuntimeException("Error on creation datasource '" + beanName + "'", t); } logger.debug("created datasource {}", beanName); }
Example 3
Source File: TestEntandoJndiUtils.java From entando-core with GNU Lesser General Public License v3.0 | 6 votes |
private static void buildContextProperties(SimpleNamingContextBuilder builder, Properties testConfig) { builder.bind("java:comp/env/logName", testConfig.getProperty("logName")); builder.bind("java:comp/env/logFileRotatePattern", testConfig.getProperty("logFileRotatePattern")); 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")); builder.bind("java:comp/env/portDataSourceClassName", testConfig.getProperty("portDataSourceClassName")); builder.bind("java:comp/env/servDataSourceClassName", testConfig.getProperty("servDataSourceClassName")); 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()); logger.trace("{} : {}", entry.getKey(), entry.getValue()); } }
Example 4
Source File: AndHow_AliasInTest.java From andhow with Apache License 2.0 | 6 votes |
@Test public void testInAliasesViaJndiRootUrlNames() throws Exception { SimpleNamingContextBuilder jndi = getJndi(); CaseInsensitiveNaming bns = new CaseInsensitiveNaming(); jndi.bind("java:" + bns.getUriName(STR_PROP1_IN), STR1); jndi.bind("java:" + bns.getUriName(STR_PROP2_ALIAS), STR2); jndi.bind("java:" + bns.getUriName(INT_PROP1_ALIAS), INT1.toString()); jndi.activate(); AndHowConfiguration config = AndHowCoreTestConfig.instance() .setLoaders(new StdJndiLoader()) .group(AliasGroup1.class); AndHow.instance(config); assertEquals(STR1, AliasGroup1.strProp1.getValue()); assertEquals(STR2, AliasGroup1.strProp2.getValue()); assertEquals(INT1, AliasGroup1.intProp1.getValue()); assertEquals(INT2, AliasGroup1.intProp2.getValue()); //default should still come thru }
Example 5
Source File: AndHow_AliasInTest.java From andhow with Apache License 2.0 | 6 votes |
@Test public void testInAliasesViaJndiCompEnvUrlNames() throws Exception { SimpleNamingContextBuilder jndi = getJndi(); CaseInsensitiveNaming bns = new CaseInsensitiveNaming(); jndi.bind("java:comp/env/" + bns.getUriName(STR_PROP1_IN), STR1); jndi.bind("java:comp/env/" + bns.getUriName(STR_PROP2_ALIAS), STR2); jndi.bind("java:comp/env/" + bns.getUriName(INT_PROP1_ALIAS), INT1.toString()); jndi.activate(); AndHowConfiguration config = AndHowCoreTestConfig.instance() .setLoaders(new StdJndiLoader()) .group(AliasGroup1.class); AndHow.instance(config); assertEquals(STR1, AliasGroup1.strProp1.getValue()); assertEquals(STR2, AliasGroup1.strProp2.getValue()); assertEquals(INT1, AliasGroup1.intProp1.getValue()); assertEquals(INT2, AliasGroup1.intProp2.getValue()); //default should still come thru }
Example 6
Source File: AndHow_AliasInTest.java From andhow with Apache License 2.0 | 6 votes |
@Test public void testInAliasesViaJndiRootClassPath() throws Exception { SimpleNamingContextBuilder jndi = getJndi(); jndi.bind("java:" + STR_PROP1_IN_AND_OUT_ALIAS, STR1); jndi.bind("java:" + STR_PROP2_IN_ALT1_ALIAS, STR2); jndi.bind("java:" + INT_PROP1_ALT_IN1_ALIAS, INT1.toString()); jndi.activate(); AndHowConfiguration config = AndHowCoreTestConfig.instance() .setLoaders(new StdJndiLoader()) .group(AliasGroup1.class); AndHow.instance(config); assertEquals(STR1, AliasGroup1.strProp1.getValue()); assertEquals(STR2, AliasGroup1.strProp2.getValue()); assertEquals(INT1, AliasGroup1.intProp1.getValue()); assertEquals(INT2, AliasGroup1.intProp2.getValue()); //default should still come thru }
Example 7
Source File: AndHow_AliasInTest.java From andhow with Apache License 2.0 | 6 votes |
@Test public void testInAliasesViaJndiCompEnvClassPath() throws Exception { SimpleNamingContextBuilder jndi = getJndi(); jndi.bind("java:comp/env/" + STR_PROP1_IN, STR1); jndi.bind("java:comp/env/" + STR_PROP2_ALIAS, STR2); jndi.bind("java:comp/env/" + INT_PROP1_ALIAS, INT1.toString()); jndi.activate(); AndHowConfiguration config = AndHowCoreTestConfig.instance() .setLoaders(new StdJndiLoader()) .group(AliasGroup1.class); AndHow.instance(config); assertEquals(STR1, AliasGroup1.strProp1.getValue()); assertEquals(STR2, AliasGroup1.strProp2.getValue()); assertEquals(INT1, AliasGroup1.intProp1.getValue()); assertEquals(INT2, AliasGroup1.intProp2.getValue()); //default should still come thru }
Example 8
Source File: StdJndiLoaderTest.java From andhow with Apache License 2.0 | 6 votes |
@Test public void testValidationIsEnforcedWhenConvertsionUsed() throws Exception { SimpleNamingContextBuilder jndi = getJndi(); CaseInsensitiveNaming bns = new CaseInsensitiveNaming(); jndi.bind("java:" + NameUtil.getAndHowName(ValidParams.class, ValidParams.INT_TEN), "9"); jndi.activate(); try { AndHowConfiguration config = AndHowCoreTestConfig.instance() .group(ValidParams.class); AndHow.instance(config); fail("Should not reach this point"); } catch (AppFatalException e) { List<Problem> vps = e.getProblems(); assertEquals(1, vps.size()); assertTrue(vps.get(0) instanceof ValueProblem); assertEquals(ValidParams.INT_TEN, ((ValueProblem)(vps.get(0))).getBadValueCoord().getProperty()); } }
Example 9
Source File: ConfigTestUtils.java From entando-core with GNU Lesser General Public License v3.0 | 6 votes |
private void createDatasource(String dsNameControlKey, SimpleNamingContextBuilder builder, Properties testConfig) { String beanName = testConfig.getProperty("jdbc." + dsNameControlKey + ".beanName"); try { String className = testConfig.getProperty("jdbc." + dsNameControlKey + ".driverClassName"); String url = testConfig.getProperty("jdbc." + dsNameControlKey + ".url"); String username = testConfig.getProperty("jdbc." + dsNameControlKey + ".username"); String password = testConfig.getProperty("jdbc." + dsNameControlKey + ".password"); Class.forName(className); BasicDataSource ds = new BasicDataSource(); ds.setUrl(url); ds.setUsername(username); ds.setPassword(password); ds.setMaxTotal(12); ds.setMaxIdle(4); ds.setDriverClassName(className); builder.bind("java:comp/env/jdbc/" + beanName, ds); } catch (Throwable t) { throw new RuntimeException("Error on creation datasource '" + beanName + "'", t); } }
Example 10
Source File: StdJndiLoaderTest.java From andhow with Apache License 2.0 | 5 votes |
@Test public void testObjectConversionErrors() throws Exception { SimpleNamingContextBuilder jndi = getJndi(); CaseInsensitiveNaming bns = new CaseInsensitiveNaming(); jndi.bind("java:" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.INT_TEN), new Long(-9999)); jndi.bind("java:" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.INT_NULL)), new Float(22)); jndi.bind("java:" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.LNG_TEN), new Integer(-9999)); jndi.activate(); try { AndHowConfiguration config = AndHowCoreTestConfig.instance() .group(SimpleParams.class); AndHow.instance(config); fail("Should not reach this point"); } catch (AppFatalException e) { List<LoaderProblem> lps = e.getProblems().filter(LoaderProblem.class); assertEquals(3, lps.size()); assertTrue(lps.get(0) instanceof LoaderProblem.ObjectConversionValueProblem); assertEquals(SimpleParams.INT_TEN, lps.get(0).getBadValueCoord().getProperty()); assertTrue(lps.get(1) instanceof LoaderProblem.ObjectConversionValueProblem); assertEquals(SimpleParams.INT_NULL, lps.get(1).getBadValueCoord().getProperty()); assertTrue(lps.get(2) instanceof LoaderProblem.ObjectConversionValueProblem); assertEquals(SimpleParams.LNG_TEN, lps.get(2).getBadValueCoord().getProperty()); } }
Example 11
Source File: StdJndiLoaderTest.java From andhow with Apache License 2.0 | 5 votes |
@Test public void testStringConversionErrors() throws Exception { SimpleNamingContextBuilder jndi = getJndi(); CaseInsensitiveNaming bns = new CaseInsensitiveNaming(); jndi.bind("java:" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.INT_TEN), "234.567"); jndi.bind("java:" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.INT_NULL)), "Apple"); jndi.bind("java:" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.LNG_TEN), "234.567"); jndi.activate(); try { AndHowConfiguration config = AndHowCoreTestConfig.instance() .group(SimpleParams.class); AndHow.instance(config); fail("Should not reach this point"); } catch (AppFatalException e) { List<LoaderProblem> vps = e.getProblems().filter(LoaderProblem.class); assertEquals(3, vps.size()); assertTrue(vps.get(0) instanceof LoaderProblem.StringConversionLoaderProblem); assertEquals(SimpleParams.INT_TEN, vps.get(0).getBadValueCoord().getProperty()); assertTrue(vps.get(1) instanceof LoaderProblem.StringConversionLoaderProblem); assertEquals(SimpleParams.INT_NULL, vps.get(1).getBadValueCoord().getProperty()); assertTrue(vps.get(2) instanceof LoaderProblem.StringConversionLoaderProblem); assertEquals(SimpleParams.LNG_TEN, vps.get(2).getBadValueCoord().getProperty()); } }
Example 12
Source File: ConfigTestUtils.java From entando-core with GNU Lesser General Public License v3.0 | 5 votes |
protected SimpleNamingContextBuilder createNamingContext() { SimpleNamingContextBuilder builder = null; try { 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/logFileRotatePattern", testConfig.getProperty("logFileRotatePattern")); 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; }
Example 13
Source File: StdJndiLoaderTest.java From andhow with Apache License 2.0 | 5 votes |
@Test public void testHappyPathFromObjectsRoot() throws Exception { SimpleNamingContextBuilder jndi = getJndi(); CaseInsensitiveNaming bns = new CaseInsensitiveNaming(); //switching values slightly to make sure we are reading the correct ones jndi.bind("java:" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.STR_BOB), "test2"); jndi.bind("java:" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.STR_NULL)), "not_null2"); jndi.bind("java:" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.FLAG_TRUE), Boolean.FALSE); jndi.bind("java:" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.FLAG_FALSE)), Boolean.TRUE); jndi.bind("java:" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.FLAG_NULL), Boolean.TRUE); jndi.bind("java:" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.INT_TEN), new Integer(-9999)); jndi.bind("java:" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.INT_NULL)), new Integer(9999)); jndi.activate(); AndHowConfiguration config = AndHowCoreTestConfig.instance() .group(SimpleParams.class); AndHow.instance(config); assertEquals("test2", SimpleParams.STR_BOB.getValue()); assertEquals("not_null2", SimpleParams.STR_NULL.getValue()); assertEquals(false, SimpleParams.FLAG_TRUE.getValue()); assertEquals(true, SimpleParams.FLAG_FALSE.getValue()); assertEquals(true, SimpleParams.FLAG_NULL.getValue()); assertEquals(new Integer(-9999), SimpleParams.INT_TEN.getValue()); assertEquals(new Integer(9999), SimpleParams.INT_NULL.getValue()); }
Example 14
Source File: JndiRule.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@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(); } }; }
Example 15
Source File: StdJndiLoaderTest.java From andhow with Apache License 2.0 | 5 votes |
@Test public void testHappyPathFromStringsFromAddedAndReplacementNonStdPaths() throws Exception { SimpleNamingContextBuilder jndi = getJndi(); CaseInsensitiveNaming bns = new CaseInsensitiveNaming(); jndi.bind("java:zip/" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.STR_BOB)), "test"); jndi.bind("java:xy/z/" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.STR_NULL), "not_null"); jndi.bind("java:/test/" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.FLAG_TRUE)), "false"); jndi.bind("java:test/" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.FLAG_FALSE), "true"); jndi.bind("java:test/" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.FLAG_NULL), "TRUE"); jndi.bind("java:myapp/root/" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.INT_TEN), "-999"); //This should NOT work jndi.bind("java:comp/env/" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.INT_NULL), "999"); jndi.activate(); AndHowConfiguration config = AndHowCoreTestConfig.instance() .addFixedValue(StdJndiLoader.CONFIG.STANDARD_JNDI_ROOTS, "java:zip/,java:xy/z/") .addFixedValue(StdJndiLoader.CONFIG.ADDED_JNDI_ROOTS, "java:/test/ , ,java:test/ , java:myapp/root/") .group(SimpleParams.class); AndHow.instance(config); assertEquals("test", SimpleParams.STR_BOB.getValue()); assertEquals("not_null", SimpleParams.STR_NULL.getValue()); assertEquals(false, SimpleParams.FLAG_TRUE.getValue()); assertEquals(true, SimpleParams.FLAG_FALSE.getValue()); assertEquals(true, SimpleParams.FLAG_NULL.getValue()); assertEquals(new Integer(-999), SimpleParams.INT_TEN.getValue()); assertNull(SimpleParams.INT_NULL.getValue()); }
Example 16
Source File: StdJndiLoaderTest.java From andhow with Apache License 2.0 | 5 votes |
@Test public void testHappyPathFromStringsFromAddedNonStdPaths() throws Exception { SimpleNamingContextBuilder jndi = getJndi(); CaseInsensitiveNaming bns = new CaseInsensitiveNaming(); jndi.bind("java:/test/" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.STR_BOB)), "test"); jndi.bind("java:/test/" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.STR_NULL), "not_null"); jndi.bind("java:test/" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.FLAG_TRUE), "false"); jndi.bind("java:test/" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.FLAG_FALSE)), "true"); jndi.bind("java:test/" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.FLAG_NULL), "TRUE"); jndi.bind("java:myapp/root/" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.INT_TEN), "-999"); //This should still work jndi.bind("java:comp/env/" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.INT_NULL), "999"); jndi.activate(); AndHowConfiguration config = AndHowCoreTestConfig.instance() .addFixedValue(StdJndiLoader.CONFIG.ADDED_JNDI_ROOTS, "java:/test/, java:test/ , java:myapp/root/") .group(SimpleParams.class); AndHow.instance(config); assertEquals("test", SimpleParams.STR_BOB.getValue()); assertEquals("not_null", SimpleParams.STR_NULL.getValue()); assertEquals(false, SimpleParams.FLAG_TRUE.getValue()); assertEquals(true, SimpleParams.FLAG_FALSE.getValue()); assertEquals(true, SimpleParams.FLAG_NULL.getValue()); assertEquals(new Integer(-999), SimpleParams.INT_TEN.getValue()); assertEquals(new Integer(999), SimpleParams.INT_NULL.getValue()); }
Example 17
Source File: MarsMapMakerTest.java From andhow with Apache License 2.0 | 5 votes |
@Test public void testOrderOfLoading() throws Exception { System.setProperty("com.dep2.MarsMapMaker.MAP_NAME", "SysPropMapName"); System.setProperty("com.dep2.MarsMapMaker.EAST_BOUND", "-99"); SimpleNamingContextBuilder jndi = getJndi(); jndi.bind("java:" + "com.dep2.MarsMapMaker.MAP_NAME", "JndiPropMapName"); jndi.bind("java:" + "com.dep2.MarsMapMaker.SOUTH_BOUND", "7"); jndi.bind("java:comp/env/" + "org.dataprocess.ExternalServiceConnector.ConnectionConfig.SERVICE_URL", "test/"); jndi.activate(); //VALUES IN THE PROPS FILE //org.dataprocess.ExternalServiceConnector.ConnectionConfig.SERVICE_URL = http://forwardcorp.com/service/ //org.dataprocess.ExternalServiceConnector.ConnectionConfig.TIMEOUT = 60 //com.dep2.MarsMapMaker.EAST_BOUND = -65 //com.dep2.MarsMapMaker.MAP_NAME = My Map //com.dep2.MarsMapMaker.NORTH_BOUND = 51 //com.dep2.MarsMapMaker.SOUTH_BOUND = 23 //com.dep2.MarsMapMaker.WEST_BOUND = -125 ExternalServiceConnector esc = new ExternalServiceConnector(); assertEquals("test/", esc.getConnectionUrl()); assertEquals(60, esc.getConnectionTimeout()); MarsMapMaker mmm = new MarsMapMaker(); assertEquals("SysPropMapName", mmm.getMapName()); assertEquals(-125, mmm.getWestBound()); assertEquals(51, mmm.getNorthBound()); assertEquals(-99, mmm.getEastBound()); assertEquals(7, mmm.getSouthBound()); }
Example 18
Source File: EarthMapMakerTest.java From andhow with Apache License 2.0 | 5 votes |
@Test public void testOrderOfLoading() throws Exception { System.setProperty("com.dep1.EarthMapMaker.MAP_NAME", "SysPropMapName"); System.setProperty("com.dep1.EarthMapMaker.EAST_BOUND", "-99"); SimpleNamingContextBuilder jndi = getJndi(); jndi.bind("java:" + "com.dep1.EarthMapMaker.MAP_NAME", "JndiPropMapName"); jndi.bind("java:" + "com.dep1.EarthMapMaker.SOUTH_BOUND", "7"); jndi.bind("java:comp/env/" + "org.dataprocess.ExternalServiceConnector.ConnectionConfig.SERVICE_URL", "test/"); jndi.activate(); //VALUES IN THE PROPS FILE //org.dataprocess.ExternalServiceConnector.ConnectionConfig.SERVICE_URL = http://forwardcorp.com/service/ //org.dataprocess.ExternalServiceConnector.ConnectionConfig.TIMEOUT = 60 //com.dep1.EarthMapMaker.EAST_BOUND = -65 //com.dep1.EarthMapMaker.MAP_NAME = My Map //com.dep1.EarthMapMaker.NORTH_BOUND = 51 //com.dep1.EarthMapMaker.SOUTH_BOUND = 23 //com.dep1.EarthMapMaker.WEST_BOUND = -125 ExternalServiceConnector esc = new ExternalServiceConnector(); assertEquals("test/", esc.getConnectionUrl()); assertEquals(60, esc.getConnectionTimeout()); EarthMapMaker emm = new EarthMapMaker(); assertEquals("SysPropMapName", emm.getMapName()); assertEquals(-125, emm.getWestBound()); assertEquals(51, emm.getNorthBound()); assertEquals(-99, emm.getEastBound()); assertEquals(7, emm.getSouthBound()); }
Example 19
Source File: ExternalResourceFactoryTest.java From uima-uimafit with Apache License 2.0 | 5 votes |
@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(); }
Example 20
Source File: StdJndiLoaderTest.java From andhow with Apache License 2.0 | 3 votes |
@Test public void testDuplicateValues() throws Exception { SimpleNamingContextBuilder jndi = getJndi(); CaseInsensitiveNaming bns = new CaseInsensitiveNaming(); //switching values slightly to make sure we are reading the correct ones jndi.bind("java:" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.STR_BOB), "test2"); jndi.bind("java:" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.STR_BOB)), "not_null2"); jndi.activate(); try { AndHowConfiguration config = AndHowCoreTestConfig.instance() .group(SimpleParams.class); AndHow.instance(config); fail("Should not reach this point"); } catch (AppFatalException e) { List<LoaderProblem> lps = e.getProblems().filter(LoaderProblem.class); assertEquals(1, lps.size()); assertTrue(lps.get(0) instanceof LoaderProblem.DuplicatePropertyLoaderProblem); } }