View Javadoc
1   package ch.qos.logback.core.util;
2   
3   import java.util.Hashtable;
4   
5   import javax.naming.Context;
6   import javax.naming.NamingException;
7   
8   import org.junit.jupiter.api.Assertions;
9   import org.junit.jupiter.api.Test;
10  
11  import ch.qos.logback.core.testUtil.CoreTestConstants;
12  import ch.qos.logback.core.testUtil.MockInitialContextFactory;
13  
14  import static org.junit.jupiter.api.Assertions.fail;
15  
16  public class JNDIUtilTest {
17  
18      @Test
19      public void ensureJavaNameSpace() throws NamingException {
20  
21          try {
22              Context ctxt = JNDIUtil.getInitialContext();
23              JNDIUtil.lookupString(ctxt, "ldap:...");
24          } catch (NamingException e) {
25              String excaptionMsg = e.getMessage();
26              if (excaptionMsg.startsWith(JNDIUtil.RESTRICTION_MSG))
27                  return;
28              else {
29                  fail("unexpected exception " + e);
30              }
31          }
32  
33          fail("Should aNot yet implemented");
34      }
35  
36      @Test
37      public void testToStringCast() throws NamingException {
38          Hashtable<String, String> props = new Hashtable<String, String>();
39          props.put(CoreTestConstants.JAVA_NAMING_FACTORY_INITIAL, MockInitialContextFactory.class.getCanonicalName());
40          Context ctxt = JNDIUtil.getInitialContext(props);
41          String x = JNDIUtil.lookupString(ctxt, "java:comp:/inexistent");
42          Assertions.assertNull(x);
43      }
44  
45      public String castToString(Object input) {
46          String a = (String) input;
47          return a;
48      }
49  
50  }