Java Code Examples for org.springframework.mock.jndi.SimpleNamingContextBuilder#activate()
The following examples show how to use
org.springframework.mock.jndi.SimpleNamingContextBuilder#activate() .
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: 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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
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 14
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 15
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 16
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 17
Source File: SampleRestClientAppTest.java From andhow with Apache License 2.0 | 4 votes |
@Test public void testInvalidValues() throws Exception { SimpleNamingContextBuilder jndi = getJndi(); jndi.activate(); cmdLineArgs = new String[] { GROUP_PATH + ".CLASSPATH_PROP_FILE" + KeyValuePairLoader.KVP_DELIMITER + "/org/yarnandtail/andhow/example/restclient/invalid.properties" }; try { //Error expected b/c some values are invalid AndHowConfiguration config = AndHowCoreTestConfig.instance() .group(SampleRestClientGroup.class) .setCmdLineArgs(cmdLineArgs) .setClasspathPropFilePath(SampleRestClientGroup.CLASSPATH_PROP_FILE) .classpathPropertiesRequired(); AndHow.instance(config); } catch (AppFatalException e) { //Value Problems (validation) //Due to loading from a prop file, the order of the file is not preserved, //so we cannot know the order that problems were encountered. ArrayList<Property<?>> expectedProblemPoints = new ArrayList(); expectedProblemPoints.add(SampleRestClientGroup.REST_HOST); expectedProblemPoints.add(SampleRestClientGroup.REST_PORT); expectedProblemPoints.add(SampleRestClientGroup.REST_SERVICE_NAME); assertEquals(3, e.getProblems().filter(ValueProblem.class).size()); assertTrue(expectedProblemPoints.contains(e.getProblems().filter(ValueProblem.class).get(0).getBadValueCoord().getProperty())); assertTrue(expectedProblemPoints.contains(e.getProblems().filter(ValueProblem.class).get(1).getBadValueCoord().getProperty())); assertTrue(expectedProblemPoints.contains(e.getProblems().filter(ValueProblem.class).get(2).getBadValueCoord().getProperty())); // // Loader problems assertEquals(1, e.getProblems().filter(LoaderProblem.class).size()); assertEquals(SampleRestClientGroup.RETRY_COUNT, e.getProblems().filter(LoaderProblem.class).get(0).getBadValueCoord().getProperty()); } }
Example 18
Source File: StdJndiLoaderTest.java From andhow with Apache License 2.0 | 4 votes |
@Test public void testHappyPathFromObjectsCompEnv() throws Exception { SimpleNamingContextBuilder jndi = getJndi(); CaseInsensitiveNaming bns = new CaseInsensitiveNaming(); jndi.bind("java:comp/env/" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.STR_BOB)), "test"); jndi.bind("java:comp/env/" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.STR_NULL)), "not_null"); jndi.bind("java:comp/env/" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.FLAG_TRUE), Boolean.FALSE); jndi.bind("java:comp/env/" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.FLAG_FALSE), Boolean.TRUE); jndi.bind("java:comp/env/" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.FLAG_NULL)), Boolean.TRUE); jndi.bind("java:comp/env/" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.INT_TEN)), new Integer(-999)); jndi.bind("java:comp/env/" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.INT_NULL), new Integer(999)); jndi.bind("java:comp/env/" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.LNG_TEN)), new Long(-999)); jndi.bind("java:comp/env/" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.LNG_NULL), new Long(999)); jndi.bind("java:comp/env/" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.LDT_2007_10_01)), LocalDateTime.parse("2007-11-02T00:00")); jndi.bind("java:comp/env/" + NameUtil.getAndHowName(SimpleParams.class, SimpleParams.LDT_NULL), LocalDateTime.parse("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(LocalDateTime.parse("2007-11-02T00:00"), SimpleParams.LDT_2007_10_01.getValue()); assertEquals(LocalDateTime.parse("2007-11-02T00:00"), SimpleParams.LDT_NULL.getValue()); }
Example 19
Source File: StdJndiLoaderTest.java From andhow with Apache License 2.0 | 4 votes |
@Test public void testHappyPathFromStringsCompEnvAsURIs() throws Exception { SimpleNamingContextBuilder jndi = getJndi(); CaseInsensitiveNaming bns = new CaseInsensitiveNaming(); jndi.bind("java:comp/env/" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.STR_BOB)), "test"); jndi.bind("java:" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.STR_NULL)), "not_null"); jndi.bind("" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.FLAG_TRUE)), "false"); jndi.bind("java:comp/env/" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.FLAG_FALSE)), "true"); jndi.bind("java:" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.FLAG_NULL)), "TRUE"); jndi.bind("" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.INT_TEN)), "-999"); jndi.bind("java:comp/env/" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.INT_NULL)), "999"); jndi.bind("java:comp/env/" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.LNG_TEN)), "-999"); jndi.bind("java:comp/env/" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.LNG_NULL)), "999"); jndi.bind("java:comp/env/" + bns.getUriName(NameUtil.getAndHowName(SimpleParams.class, SimpleParams.LDT_2007_10_01)), "2007-11-02T00:00"); jndi.bind("java:comp/env/" + bns.getUriName(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(LocalDateTime.parse("2007-11-02T00:00"), SimpleParams.LDT_2007_10_01.getValue()); assertEquals(LocalDateTime.parse("2007-11-02T00:00"), SimpleParams.LDT_NULL.getValue()); }
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); } }