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:
hariprasad108
2017-06-04 21:39:21 +02:00
committed by maibin
parent 29e3437545
commit c17d19ff21
11 changed files with 291 additions and 4 deletions
+10 -4
View File
@@ -45,11 +45,11 @@
<artifactId>commons-math3</artifactId>
<version>${commons-math3.version}</version>
</dependency>
<dependency>
<groupId>org.decimal4j</groupId>
<artifactId>decimal4j</artifactId>
<version>${decimal4j.version}</version>
<groupId>org.decimal4j</groupId>
<artifactId>decimal4j</artifactId>
<version>${decimal4j.version}</version>
</dependency>
<dependency>
@@ -177,6 +177,11 @@
<version>2.1.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.messaging.mq</groupId>
<artifactId>fscontext</artifactId>
<version>${fscontext.version}</version>
</dependency>
</dependencies>
<build>
@@ -382,6 +387,7 @@
<unix4j.version>0.4</unix4j.version>
<grep4j.version>1.8.7</grep4j.version>
<lombok.version>1.16.12</lombok.version>
<fscontext.version>4.6-b01</fscontext.version>
<!-- testing -->
<org.hamcrest.version>1.3</org.hamcrest.version>
@@ -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);
}
}
+1
View File
@@ -0,0 +1 @@
Test of JNDI on file.