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