use of cn.taketoday.web.context.support.ServletContextResourcePatternLoader in project today-infrastructure by TAKETODAY.
the class ServletContextSupportTests method testServletContextResourcePatternLoaderWithUnboundedPatternPath.
@Test
public void testServletContextResourcePatternLoaderWithUnboundedPatternPath() throws IOException {
final Set<String> dirs = new HashSet<>();
dirs.add("/WEB-INF/mydir1/");
dirs.add("/WEB-INF/mydir2/");
final Set<String> paths = new HashSet<>();
paths.add("/WEB-INF/mydir2/context2.xml");
paths.add("/WEB-INF/mydir2/mydir3/");
MockServletContext sc = new MockServletContext("classpath:cn/taketoday/web/context") {
@Override
public Set<String> getResourcePaths(String path) {
if ("/WEB-INF/".equals(path)) {
return dirs;
}
if ("/WEB-INF/mydir1/".equals(path)) {
return Collections.singleton("/WEB-INF/mydir1/context1.xml");
}
if ("/WEB-INF/mydir2/".equals(path)) {
return paths;
}
if ("/WEB-INF/mydir2/mydir3/".equals(path)) {
return Collections.singleton("/WEB-INF/mydir2/mydir3/context3.xml");
}
return null;
}
};
ServletContextResourcePatternLoader rpr = new ServletContextResourcePatternLoader(sc);
Resource[] found = rpr.getResourcesArray("/WEB-INF/**/*.xml");
Set<String> foundPaths = new HashSet<>();
for (Resource resource : found) {
foundPaths.add(((ServletContextResource) resource).getPath());
}
assertThat(foundPaths.size()).isEqualTo(3);
assertThat(foundPaths.contains("/WEB-INF/mydir1/context1.xml")).isTrue();
assertThat(foundPaths.contains("/WEB-INF/mydir2/context2.xml")).isTrue();
assertThat(foundPaths.contains("/WEB-INF/mydir2/mydir3/context3.xml")).isTrue();
}
use of cn.taketoday.web.context.support.ServletContextResourcePatternLoader in project today-infrastructure by TAKETODAY.
the class ServletContextSupportTests method testServletContextResourcePatternLoader.
@Test
public void testServletContextResourcePatternLoader() throws IOException {
final Set<String> paths = new HashSet<>();
paths.add("/WEB-INF/context1.xml");
paths.add("/WEB-INF/context2.xml");
MockServletContext sc = new MockServletContext("classpath:cn/taketoday/web/context") {
@Override
public Set<String> getResourcePaths(String path) {
if ("/WEB-INF/".equals(path)) {
return paths;
}
return null;
}
};
ServletContextResourcePatternLoader rpr = new ServletContextResourcePatternLoader(sc);
Resource[] found = rpr.getResourcesArray("/WEB-INF/*.xml");
Set<String> foundPaths = new HashSet<>();
for (Resource resource : found) {
foundPaths.add(((ServletContextResource) resource).getPath());
}
assertThat(foundPaths.size()).isEqualTo(2);
assertThat(foundPaths.contains("/WEB-INF/context1.xml")).isTrue();
assertThat(foundPaths.contains("/WEB-INF/context2.xml")).isTrue();
}
use of cn.taketoday.web.context.support.ServletContextResourcePatternLoader in project today-infrastructure by TAKETODAY.
the class ServletContextSupportTests method testServletContextResourcePatternLoaderWithPatternPath.
@Test
public void testServletContextResourcePatternLoaderWithPatternPath() throws IOException {
final Set<String> dirs = new HashSet<>();
dirs.add("/WEB-INF/mydir1/");
dirs.add("/WEB-INF/mydir2/");
MockServletContext sc = new MockServletContext("classpath:cn/taketoday/web/context") {
@Override
public Set<String> getResourcePaths(String path) {
if ("/WEB-INF/".equals(path)) {
return dirs;
}
if ("/WEB-INF/mydir1/".equals(path)) {
return Collections.singleton("/WEB-INF/mydir1/context1.xml");
}
if ("/WEB-INF/mydir2/".equals(path)) {
return Collections.singleton("/WEB-INF/mydir2/context2.xml");
}
return null;
}
};
ServletContextResourcePatternLoader rpr = new ServletContextResourcePatternLoader(sc);
Resource[] found = rpr.getResourcesArray("/WEB-INF/*/*.xml");
Set<String> foundPaths = new HashSet<>();
for (Resource resource : found) {
foundPaths.add(((ServletContextResource) resource).getPath());
}
assertThat(foundPaths.size()).isEqualTo(2);
assertThat(foundPaths.contains("/WEB-INF/mydir1/context1.xml")).isTrue();
assertThat(foundPaths.contains("/WEB-INF/mydir2/context2.xml")).isTrue();
}
use of cn.taketoday.web.context.support.ServletContextResourcePatternLoader in project today-infrastructure by TAKETODAY.
the class ServletContextSupportTests method testServletContextResourcePatternLoaderWithAbsolutePaths.
@Test
public void testServletContextResourcePatternLoaderWithAbsolutePaths() throws IOException {
final Set<String> paths = new HashSet<>();
paths.add("C:/webroot/WEB-INF/context1.xml");
paths.add("C:/webroot/WEB-INF/context2.xml");
paths.add("C:/webroot/someOtherDirThatDoesntContainPath");
MockServletContext sc = new MockServletContext("classpath:cn/taketoday/web/context") {
@Override
public Set<String> getResourcePaths(String path) {
if ("/WEB-INF/".equals(path)) {
return paths;
}
return null;
}
};
ServletContextResourcePatternLoader rpr = new ServletContextResourcePatternLoader(sc);
Resource[] found = rpr.getResourcesArray("/WEB-INF/*.xml");
Set<String> foundPaths = new HashSet<>();
for (Resource resource : found) {
foundPaths.add(((ServletContextResource) resource).getPath());
}
assertThat(foundPaths.size()).isEqualTo(2);
assertThat(foundPaths.contains("/WEB-INF/context1.xml")).isTrue();
assertThat(foundPaths.contains("/WEB-INF/context2.xml")).isTrue();
}
use of cn.taketoday.web.context.support.ServletContextResourcePatternLoader in project today-framework by TAKETODAY.
the class ServletContextSupportTests method testServletContextResourcePatternLoaderWithPatternPath.
@Test
public void testServletContextResourcePatternLoaderWithPatternPath() throws IOException {
final Set<String> dirs = new HashSet<>();
dirs.add("/WEB-INF/mydir1/");
dirs.add("/WEB-INF/mydir2/");
MockServletContext sc = new MockServletContext("classpath:cn/taketoday/web/context") {
@Override
public Set<String> getResourcePaths(String path) {
if ("/WEB-INF/".equals(path)) {
return dirs;
}
if ("/WEB-INF/mydir1/".equals(path)) {
return Collections.singleton("/WEB-INF/mydir1/context1.xml");
}
if ("/WEB-INF/mydir2/".equals(path)) {
return Collections.singleton("/WEB-INF/mydir2/context2.xml");
}
return null;
}
};
ServletContextResourcePatternLoader rpr = new ServletContextResourcePatternLoader(sc);
Resource[] found = rpr.getResourcesArray("/WEB-INF/*/*.xml");
Set<String> foundPaths = new HashSet<>();
for (Resource resource : found) {
foundPaths.add(((ServletContextResource) resource).getPath());
}
assertThat(foundPaths.size()).isEqualTo(2);
assertThat(foundPaths.contains("/WEB-INF/mydir1/context1.xml")).isTrue();
assertThat(foundPaths.contains("/WEB-INF/mydir2/context2.xml")).isTrue();
}
Aggregations