Difference between url and uri bael 864 hariprasad (#1987)
* Commit URUURLJNDIFS added. * URI URL REST commit. * Revert "URI URL REST commit." This reverts commit d9e26399be1f3a26d871cd0600036e3a4558cde2. * Difference URI URL REST BAEL-864. * Commit Difference URI URL REST #864, small changes. * Difference URI URL REST project has been moved to spring-rest. * BAEL-864. Deleted unused project and did one small change.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package com.baeldung.filesystem.jndi;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
public class LookupFSJNDI {
|
||||
InitialContext ctx = null;
|
||||
|
||||
public LookupFSJNDI() throws NamingException {
|
||||
super();
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() throws NamingException {
|
||||
Hashtable<String, String> env = new Hashtable<String, String>();
|
||||
|
||||
env.put (Context.INITIAL_CONTEXT_FACTORY,
|
||||
"com.sun.jndi.fscontext.RefFSContextFactory");
|
||||
// URI to namespace (actual directory)
|
||||
env.put(Context.PROVIDER_URL, "file:./src/test/resources");
|
||||
|
||||
ctx = new InitialContext(env);
|
||||
}
|
||||
|
||||
public InitialContext getCtx() {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
public File getFile(String fileName) {
|
||||
File file;
|
||||
try {
|
||||
file = (File)getCtx().lookup(fileName);
|
||||
} catch (NamingException e) {
|
||||
file = null;
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.baeldung.filesystem.jndi.test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.filesystem.jndi.LookupFSJNDI;
|
||||
|
||||
public class LookupFSJNDITest {
|
||||
LookupFSJNDI fsjndi;
|
||||
File file;
|
||||
InitialContext ctx = null;
|
||||
final String FILENAME = "test.find";
|
||||
|
||||
public LookupFSJNDITest() {
|
||||
try {
|
||||
fsjndi = new LookupFSJNDI();
|
||||
} catch (NamingException e) {
|
||||
fsjndi = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInitializationLookupFSJNDIIsNotNull_thenSuccess() {
|
||||
assertNotNull("Class LookupFSJNDI has instance", fsjndi);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenLookupFSJNDI_whengetInitialContextIsNotNull_thenSuccess() {
|
||||
ctx = fsjndi.getCtx();
|
||||
assertNotNull("Context exists", ctx);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenInitialContext_whenLokupFileExists_thenSuccess() {
|
||||
File file = fsjndi.getFile(FILENAME);
|
||||
assertNotNull("File exists", file);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Test of JNDI on file.
|
||||
Reference in New Issue
Block a user