Skip to content

Commit

Permalink
LOGBACK-1604 test
Browse files Browse the repository at this point in the history
Signed-off-by: Ceki Gulcu <ceki@qos.ch>
  • Loading branch information
ceki committed Dec 27, 2021
1 parent d45153c commit da180d7
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 19 deletions.
Expand Up @@ -23,8 +23,9 @@
import ch.qos.logback.classic.ClassicConstants;
import ch.qos.logback.classic.selector.servlet.ContextDetachingSCL;
import ch.qos.logback.classic.util.ContextSelectorStaticBinder;
import ch.qos.logback.classic.util.MockInitialContext;
import ch.qos.logback.classic.util.MockInitialContextFactory;
import ch.qos.logback.core.testUtil.MockInitialContext;
import ch.qos.logback.core.testUtil.MockInitialContextFactory;

import org.slf4j.LoggerFactoryFriend;
import org.slf4j.impl.StaticLoggerBinderFriend;

Expand Down
Expand Up @@ -23,9 +23,9 @@

import ch.qos.logback.classic.ClassicConstants;
import ch.qos.logback.classic.util.ContextSelectorStaticBinder;
import ch.qos.logback.classic.util.MockInitialContext;
import ch.qos.logback.classic.util.MockInitialContextFactory;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.testUtil.MockInitialContext;
import ch.qos.logback.core.testUtil.MockInitialContextFactory;

public class ContextJNDISelectorTest {

Expand Down
Expand Up @@ -15,6 +15,8 @@

import static ch.qos.logback.core.CoreConstants.JNDI_JAVA_NAMESPACE;

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
Expand All @@ -36,6 +38,10 @@ public static Context getInitialContext() throws NamingException {
return new InitialContext();
}

public static Context getInitialContext(Hashtable<?,?> props) throws NamingException {
return new InitialContext(props);
}

public static Object lookupObject(Context ctx, String name) throws NamingException {
if (ctx == null) {
return null;
Expand Down
Expand Up @@ -11,7 +11,7 @@
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/
package ch.qos.logback.classic.util;
package ch.qos.logback.core.testUtil;

import java.util.HashMap;
import java.util.Map;
Expand Down
Expand Up @@ -11,7 +11,7 @@
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/
package ch.qos.logback.classic.util;
package ch.qos.logback.core.testUtil;

import java.util.Hashtable;

Expand Down
Expand Up @@ -29,4 +29,5 @@ public class CoreTestConstants {
public static final String BASH_PATH_ON_LINUX = "bash";

public static final String SLOW_JENKINS = "slowJenkins";
public static final String JAVA_NAMING_FACTORY_INITIAL = "java.naming.factory.initial";
}
@@ -1,30 +1,24 @@
package ch.qos.logback.core.util;

import static org.junit.Assert.*;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.NamingException;

import org.junit.Before;
import org.junit.Test;

public class JNDIUtilTest {

Context ctxt;
import ch.qos.logback.core.testUtil.MockInitialContextFactory;

@Before
public void setup() {
try {
ctxt = JNDIUtil.getInitialContext();
} catch (NamingException e) {
e.printStackTrace();
}
}
public class JNDIUtilTest {

@Test
public void ensureJavaNameSpace() throws NamingException {

try {
Context ctxt = JNDIUtil.getInitialContext();
JNDIUtil.lookupString(ctxt, "ldap:...");
} catch (NamingException e) {
String excaptionMsg = e.getMessage();
Expand All @@ -40,6 +34,9 @@ public void ensureJavaNameSpace() throws NamingException {

@Test
public void testToStringCast() throws NamingException {
Hashtable<String, String> props = new Hashtable<String, String>();
props.put(CoreTestConstants.JAVA_NAMING_FACTORY_INITIAL, MockInitialContextFactory.class.getCanonicalName());
Context ctxt = JNDIUtil.getInitialContext(props);
String x = JNDIUtil.lookupString(ctxt, "java:comp:/inexistent");
assertNull(x);
}
Expand Down

0 comments on commit da180d7

Please sign in to comment.