JndiHomeDetector implements HomeDetector { @Override public File detect() { try { String value = (String) new InitialContext().lookup(VARIABLE); if (value == null || value.isEmpty()) return null; log.info("Using Oxalis folder specified as JNDI path '{}' with value '{}'.", VARIABLE, value); return new File(value); } catch (NamingException ex) { return null; } }  @Override File detect();  }
@Test public void testFromJndi() throws Exception { System.setProperty(Context.INITIAL_CONTEXT_FACTORY, TestableInitialContextFactory.class.getName()); new InitialContext().unbind(VARIABLE); String path = new File("/some/system/path1").getAbsolutePath(); File oxalis_home = homeDetector.detect(); assertNull(oxalis_home); new InitialContext().bind(VARIABLE, path); oxalis_home = homeDetector.detect(); assertEquals(oxalis_home.getAbsolutePath(), path); new InitialContext().unbind(VARIABLE); }
@Test public void testEmpty() throws Exception { System.setProperty(Context.INITIAL_CONTEXT_FACTORY, TestableInitialContextFactory.class.getName()); new InitialContext().unbind(VARIABLE); File oxalis_home = homeDetector.detect(); assertNull(oxalis_home); new InitialContext().bind(VARIABLE, ""); assertNull(homeDetector.detect()); new InitialContext().unbind(VARIABLE); }
@Test public void testNotSet() throws Exception { System.clearProperty(Context.INITIAL_CONTEXT_FACTORY); assertNull(homeDetector.detect()); }