mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Add support for bang paths
This commit is contained in:
@@ -1,14 +1,28 @@
|
||||
package com.avaje.tests.unitinternal;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebeaninternal.server.core.XmlConfigLoader;
|
||||
import com.avaje.ebeaninternal.server.lib.util.Dnode;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarOutputStream;
|
||||
|
||||
/**
|
||||
* Tests basic xml loading functionality across multiple jars and inside our own test structure.
|
||||
*
|
||||
* @author Rob Bygrave
|
||||
* @author Richard Vowles - http://plus.google.com/RichardVowles
|
||||
*/
|
||||
public class TestXmlConfigLoader extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
@@ -16,10 +30,62 @@ public class TestXmlConfigLoader extends BaseTestCase {
|
||||
|
||||
XmlConfigLoader xmlConfigLoader = new XmlConfigLoader(null);
|
||||
|
||||
List<Dnode> ebeanOrmXml = xmlConfigLoader.search("META-INF/ebean-orm.xml");
|
||||
List<Dnode> ebeanOrmXml = xmlConfigLoader.search(META_INF_EBEAN_ORM_XML);
|
||||
|
||||
Assert.assertNotNull(ebeanOrmXml);
|
||||
Assert.assertTrue("Found ebean-orm.xml", ebeanOrmXml.size() > 0);
|
||||
|
||||
}
|
||||
|
||||
private static final String META_INF_EBEAN_ORM_XML = "META-INF/ebean-orm.xml";
|
||||
private static final String META_INF_ORM_XML = "META-INF/orm.xml";
|
||||
private static final String WEB_INF_CLASSES = "WEB-INF/classes/";
|
||||
|
||||
@Test
|
||||
public void ensureEbeanOrmStillLoads() throws IOException {
|
||||
URL jar = setupJar();
|
||||
URL jarBang = setupJarBang();
|
||||
|
||||
URLClassLoader cl = new URLClassLoader(new URL[] { jar, jarBang}, getClass().getClassLoader());
|
||||
|
||||
XmlConfigLoader loader = new XmlConfigLoader(cl);
|
||||
|
||||
Assert.assertEquals(3, loader.search(META_INF_EBEAN_ORM_XML).size()); // 1 in parent, 2 in ours
|
||||
Assert.assertEquals(2, loader.search(META_INF_ORM_XML).size()); // 2 in ours
|
||||
|
||||
}
|
||||
|
||||
private URL createJar(File jarFile, String offset) throws IOException {
|
||||
FileOutputStream stream = new FileOutputStream(jarFile);
|
||||
JarOutputStream jarOutputStream = new JarOutputStream(stream);
|
||||
|
||||
JarEntry entry = new JarEntry(offset + META_INF_EBEAN_ORM_XML);
|
||||
jarOutputStream.putNextEntry(entry);
|
||||
InputStream classStream = getClass().getResourceAsStream("/" + META_INF_EBEAN_ORM_XML);
|
||||
IOUtils.copy(classStream, jarOutputStream);
|
||||
|
||||
entry = new JarEntry(offset + META_INF_ORM_XML);
|
||||
jarOutputStream.putNextEntry(entry);
|
||||
classStream = getClass().getResourceAsStream("/" + META_INF_EBEAN_ORM_XML);
|
||||
IOUtils.copy(classStream, jarOutputStream);
|
||||
|
||||
jarOutputStream.close();
|
||||
stream.close();
|
||||
|
||||
if (offset.length() > 0) {
|
||||
return new URL("jar:" + jarFile.toURI().toString() + "!/" + offset);
|
||||
} else {
|
||||
return jarFile.toURI().toURL();
|
||||
}
|
||||
}
|
||||
|
||||
private URL setupJarBang() throws IOException {
|
||||
File jarFile = File.createTempFile("bang", ".war");
|
||||
return createJar(jarFile, WEB_INF_CLASSES);
|
||||
}
|
||||
|
||||
private URL setupJar() throws IOException {
|
||||
File jarFile = File.createTempFile("nobang", ".jar");
|
||||
return createJar(jarFile, "");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user