Line 0
Link Here
|
|
|
1 |
package org.apache.catalina.loader; |
2 |
|
3 |
import org.apache.catalina.core.StandardContext; |
4 |
import org.apache.catalina.startup.Tomcat; |
5 |
import org.apache.catalina.startup.TomcatBaseTest; |
6 |
import org.junit.Test; |
7 |
|
8 |
import java.io.File; |
9 |
import java.net.MalformedURLException; |
10 |
|
11 |
public class TestHandleTypesWebappLoader extends TomcatBaseTest { |
12 |
public static final String TEST_DIR = new File("test/webapp-3.0-spring").getAbsolutePath(); |
13 |
|
14 |
@Test |
15 |
public void testStartInternalForLibrary() throws Exception { |
16 |
Tomcat tomcat = getTomcatInstance(); |
17 |
StandardContext context = (StandardContext)tomcat.addWebapp(null, "/spring", TEST_DIR + "/src/main/webapp"); |
18 |
context.setLoader(new WebappLoader()); |
19 |
context.setUnpackWAR(false); |
20 |
|
21 |
// Add application classes as JAR file |
22 |
context.getLoader().addRepository(new File(TEST_DIR, "/target/lib/app.jar").toURI().toURL().toString()); |
23 |
|
24 |
addLibsToRepository(context); |
25 |
tomcat.start(); |
26 |
} |
27 |
|
28 |
@Test |
29 |
public void testStartInternalForClassesDirectory() throws Exception { |
30 |
Tomcat tomcat = getTomcatInstance(); |
31 |
StandardContext context = (StandardContext)tomcat.addWebapp(null, "/spring", TEST_DIR + "/src/main/webapp"); |
32 |
context.setLoader(new WebappLoader()); |
33 |
context.setUnpackWAR(false); |
34 |
|
35 |
// Add application classes as directory |
36 |
context.getLoader().addRepository(new File(TEST_DIR, "/target/classes/main").toURI().toURL().toString()); |
37 |
context.getLoader().addRepository(new File(TEST_DIR, "/src/main/resources").toURI().toURL().toString()); |
38 |
|
39 |
addLibsToRepository(context); |
40 |
tomcat.start(); |
41 |
} |
42 |
|
43 |
private void addLibsToRepository(StandardContext context) throws MalformedURLException { |
44 |
File folder = new File(TEST_DIR, "/lib"); |
45 |
File[] libs = folder.listFiles(); |
46 |
|
47 |
for(File lib : libs) { |
48 |
context.getLoader().addRepository(lib.toURI().toURL().toString()); |
49 |
} |
50 |
} |
51 |
} |