org.springframework.mock.jndi.SimpleNamingContextBuilder Java Examples
The following examples show how to use
org.springframework.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: TestEntandoJndiUtils.java From entando-core with GNU Lesser General Public License v3.0 | 6 votes |
public static void setupJndi() { SimpleNamingContextBuilder builder = null; try { String path = "target/test/conf/contextTestParams.properties"; logger.debug("CREATING JNDI RESOURCES BASED ON {} (test)", path); InputStream in = new FileInputStream(path); builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder(); Properties testConfig = new Properties(); testConfig.load(in); in.close(); buildContextProperties(builder, testConfig); createDatasources(builder, testConfig); builder.activate(); } catch (Throwable t) { t.printStackTrace(); throw new RuntimeException("Error on creation naming context", t); } }
Example #2
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 #3
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 #4
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 #5
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 #6
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 #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: 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 #10
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 #11
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 #12
Source File: AndHowTestBase.java From andhow with Apache License 2.0 | 5 votes |
@AfterClass public static void resetAndHowSnapshotAfterTestClass() { System.setProperties(beforeClassSystemProps); AndHowNonProductionUtil.setAndHowCore(beforeClassCore); //Reset to the log level prior to the test class Logger.getGlobal().setLevel(beforeClassLogLevel); Logger.getLogger(SimpleNamingContextBuilder.class.getCanonicalName()).setLevel(beforeClassLogLevel); }
Example #13
Source File: TestEntandoJndiUtils.java From entando-core with GNU Lesser General Public License v3.0 | 5 votes |
private static void createDatasources(SimpleNamingContextBuilder builder, Properties testConfig) { List<String> dsNameControlKeys = new ArrayList<String>(); Enumeration<Object> keysEnum = testConfig.keys(); while (keysEnum.hasMoreElements()) { String key = (String) keysEnum.nextElement(); if (key.startsWith("jdbc.")) { String[] controlKeys = key.split("\\."); String dsNameControlKey = controlKeys[1]; if (!dsNameControlKeys.contains(dsNameControlKey)) { createDatasource(dsNameControlKey, builder, testConfig); dsNameControlKeys.add(dsNameControlKey); } } } }
Example #14
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 #15
Source File: ConfigTestUtils.java From entando-core with GNU Lesser General Public License v3.0 | 5 votes |
private void createDatasources(SimpleNamingContextBuilder builder, Properties testConfig) { List<String> dsNameControlKeys = new ArrayList<String>(); Enumeration<Object> keysEnum = testConfig.keys(); while (keysEnum.hasMoreElements()) { String key = (String) keysEnum.nextElement(); if (key.startsWith("jdbc.")) { String[] controlKeys = key.split("\\."); String dsNameControlKey = controlKeys[1]; if (!dsNameControlKeys.contains(dsNameControlKey)) { this.createDatasource(dsNameControlKey, builder, testConfig); dsNameControlKeys.add(dsNameControlKey); } } } }
Example #16
Source File: JndiTestUtils.java From flexy-pool with Apache License 2.0 | 5 votes |
public JndiTestUtils() { try { namingContext = SimpleNamingContextBuilder.emptyActivatedContextBuilder(); namingContext.clear(); } catch (NamingException e) { throw new IllegalArgumentException(e); } }
Example #17
Source File: JtaConfigurerTest.java From rice with Educational Community License v2.0 | 5 votes |
private void initializeJtaJndiConfig() throws Exception { this.builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder(); builder.bind(TRANSACTION_MANAGER_JNDI_NAME, transactionManager); builder.bind(USER_TRANSACTION_JNDI_NAME, userTransaction); this.config = new SimpleConfig(); this.config.putProperty(RiceConstants.TRANSACTION_MANAGER_JNDI, TRANSACTION_MANAGER_JNDI_NAME); this.config.putProperty(RiceConstants.USER_TRANSACTION_JNDI, USER_TRANSACTION_JNDI_NAME); ConfigContext.init(this.config); }
Example #18
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 #19
Source File: JndiExceptionsUnitTest.java From tutorials with MIT License | 5 votes |
@Test @Order(2) void givenEmptyContext_whenLookupNotBounds_thenThrowNameNotFound() { assertThrows(NameNotFoundException.class, () -> { SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder(); builder.activate(); JndiTemplate jndiTemplate = new JndiTemplate(); InitialContext ctx = (InitialContext) jndiTemplate.getContext(); ctx.lookup("badJndiName"); }).printStackTrace(); }
Example #20
Source File: JndiUnitTest.java From tutorials with MIT License | 5 votes |
@BeforeAll static void setUp() throws Exception { SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder(); ds = new DriverManagerDataSource("jdbc:h2:mem:mydb"); builder.activate(); JndiTemplate jndiTemplate = new JndiTemplate(); ctx = (InitialContext) jndiTemplate.getContext(); }
Example #21
Source File: DatabaseTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { conn = mockConnection( mock( DatabaseMetaData.class ) ); when( log.getLogLevel() ).thenReturn( LogLevel.NOTHING ); when( dbMetaMock.getDatabaseInterface() ).thenReturn( databaseInterface ); if ( !NamingManager.hasInitialContextFactoryBuilder() ) { // If JNDI is not initialized, use simpleJNDI System.setProperty( Context.INITIAL_CONTEXT_FACTORY, "org.osjava.sj.memory.MemoryContextFactory" ); // pentaho#simple-jndi;1.0.0 System.setProperty( "org.osjava.sj.jndi.shared", "true" ); InitialContextFactoryBuilder simpleBuilder = new SimpleNamingContextBuilder(); NamingManager.setInitialContextFactoryBuilder( simpleBuilder ); } }
Example #22
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 #23
Source File: BigDecPropTest.java From andhow with Apache License 2.0 | 5 votes |
@Test public void happyPathTest_JndiProp() throws NamingException { SimpleNamingContextBuilder jndi = getJndi(); jndi.bind("java:" + GREATER_THAN_JNDI_PATH, JNDI_VALUE); jndi.activate(); this.buildConfig(this, "_happyPath", BigDecGroup.class); assertEquals(JNDI_VALUE, BigDecGroup.GREATER_THAN.getValue()); }
Example #24
Source File: AndHowTestBase.java From andhow with Apache License 2.0 | 5 votes |
@BeforeClass public static void andHowSnapshotBeforeTestClass() throws Exception { //The SimpleNamingContextBuilder uses Commons Logging, which defaults to //using Java logging. It spews a bunch of stuff the console during tests, //so this turns that off. beforeClassLogLevel = Logger.getGlobal().getLevel(); //store log level before class Logger.getGlobal().setLevel(Level.SEVERE); Logger.getLogger(SimpleNamingContextBuilder.class.getCanonicalName()).setLevel(Level.SEVERE); beforeClassCore = AndHowNonProductionUtil.getAndHowCore(); beforeClassSystemProps = AndHowNonProductionUtil.clone(System.getProperties()); }
Example #25
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 #26
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 #27
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 #28
Source File: StdJndiLoaderTest.java From andhow with Apache License 2.0 | 5 votes |
@Test public void testHappyPathFromStringsCompEnvAsClasspath() throws Exception { SimpleNamingContextBuilder jndi = getJndi(); jndi.bind("java:comp/env/" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.STR_BOB), "test"); jndi.bind("java:" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.STR_NULL), "not_null"); jndi.bind("" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.FLAG_TRUE), "false"); jndi.bind("java:comp/env/" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.FLAG_FALSE), "true"); jndi.bind("java:" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.FLAG_NULL), "TRUE"); jndi.bind("" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.INT_TEN), "-999"); jndi.bind("java:comp/env/" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.INT_NULL), "999"); jndi.bind("java:comp/env/" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.LNG_TEN), "-999"); jndi.bind("java:comp/env/" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.LNG_NULL), "999"); jndi.bind("java:comp/env/" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.LDT_2007_10_01), "2007-11-02T00:00"); jndi.bind("java:comp/env/" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.LDT_NULL), "2007-11-02T00:00"); jndi.activate(); AndHowConfiguration config = AndHowCoreTestConfig.instance() .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()); assertEquals(new Long(-999), SimpleParams.LNG_TEN.getValue()); assertEquals(new Long(999), SimpleParams.LNG_NULL.getValue()); assertEquals(new Long(-999), SimpleParams.LNG_TEN.getValue()); assertEquals(new Long(999), SimpleParams.LNG_NULL.getValue()); assertEquals(LocalDateTime.parse("2007-11-02T00:00"), SimpleParams.LDT_2007_10_01.getValue()); assertEquals(LocalDateTime.parse("2007-11-02T00:00"), SimpleParams.LDT_NULL.getValue()); }
Example #29
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 #30
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()); }