Search in sources :

Example 1 with UrlResource

use of org.grails.io.support.UrlResource in project grails-core by grails.

the class GrailsResourceUtilsTests method testGetTestNameResource.

public void testGetTestNameResource() throws Exception {
    Resource r = new UrlResource(new URL(UNIT_TESTS_URL));
    assertEquals("SomeTests", GrailsResourceUtils.getClassName(r));
}
Also used : UrlResource(org.grails.io.support.UrlResource) Resource(org.grails.io.support.Resource) UrlResource(org.grails.io.support.UrlResource) URL(java.net.URL)

Example 2 with UrlResource

use of org.grails.io.support.UrlResource in project grails-core by grails.

the class GrailsResourceUtilsTests method testGetPluginContextPath.

public void testGetPluginContextPath() throws Exception {
    MockServletContext servletContext = new MockServletContext("/myapp");
    MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
    request.setContextPath("/myapp");
    assertEquals("", GrailsResourceUtils.getStaticResourcePathForResource(new UrlResource(TEST_CONTROLLER_URL), null));
    assertEquals("plugins/myplugin", GrailsResourceUtils.getStaticResourcePathForResource(new UrlResource(TEST_PLUGIN_CTRL), null));
    assertEquals("", GrailsResourceUtils.getStaticResourcePathForResource(new UrlResource(WEBINF_CONTROLLER), null));
    assertEquals("plugins/myplugin", GrailsResourceUtils.getStaticResourcePathForResource(new UrlResource(WEBINF_PLUGIN_CTRL), null));
    assertEquals("/myapp", GrailsResourceUtils.getStaticResourcePathForResource(new UrlResource(WEBINF_CONTROLLER), request.getContextPath()));
    assertEquals("/myapp/plugins/myplugin", GrailsResourceUtils.getStaticResourcePathForResource(new UrlResource(WEBINF_PLUGIN_CTRL), request.getContextPath()));
}
Also used : UrlResource(org.grails.io.support.UrlResource) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockServletContext(org.springframework.mock.web.MockServletContext)

Example 3 with UrlResource

use of org.grails.io.support.UrlResource in project grails-core by grails.

the class GrailsResourceUtilsTests method testGetAppDir.

public void testGetAppDir() throws Exception {
    Resource appDir = GrailsResourceUtils.getAppDir(new UrlResource(TEST_CONTROLLER_URL));
    assertEquals(toFileUrl("/test/grails/app/grails-app"), appDir.getURL().toString());
    appDir = GrailsResourceUtils.getAppDir(new UrlResource(TEST_URL));
    assertEquals(toFileUrl("/test/grails/app/grails-app"), appDir.getURL().toString());
}
Also used : UrlResource(org.grails.io.support.UrlResource) Resource(org.grails.io.support.Resource) UrlResource(org.grails.io.support.UrlResource)

Example 4 with UrlResource

use of org.grails.io.support.UrlResource in project grails-core by grails.

the class GrailsResourceUtilsTests method testGetDirWithinWebInf.

public void testGetDirWithinWebInf() throws Exception {
    Resource viewsDir = GrailsResourceUtils.getViewsDir(new UrlResource(TEST_CONTROLLER_URL));
    Resource pluginViews = GrailsResourceUtils.getViewsDir(new UrlResource(TEST_PLUGIN_CTRL));
    Resource webInfViews = GrailsResourceUtils.getViewsDir(new UrlResource(WEBINF_CONTROLLER));
    Resource webInfPluginViews = GrailsResourceUtils.getViewsDir(new UrlResource(WEBINF_PLUGIN_CTRL));
    assertEquals(toFileUrl("/test/grails/app/grails-app/views"), viewsDir.getURL().toString());
    assertEquals(toFileUrl("/test/grails/app/plugins/myplugin/grails-app/views"), pluginViews.getURL().toString());
    assertEquals(toFileUrl("/test/grails/app/WEB-INF/grails-app/views"), webInfViews.getURL().toString());
    assertEquals(toFileUrl("/test/grails/app/WEB-INF/plugins/myplugin/grails-app/views"), webInfPluginViews.getURL().toString());
    assertEquals("/WEB-INF/grails-app/views", GrailsResourceUtils.getRelativeInsideWebInf(webInfViews));
    assertEquals("/WEB-INF/plugins/myplugin/grails-app/views", GrailsResourceUtils.getRelativeInsideWebInf(webInfPluginViews));
    assertEquals("/WEB-INF/plugins/myplugin/grails-app/views", GrailsResourceUtils.getRelativeInsideWebInf(pluginViews));
    assertEquals("/WEB-INF/grails-app/views", GrailsResourceUtils.getRelativeInsideWebInf(viewsDir));
}
Also used : UrlResource(org.grails.io.support.UrlResource) Resource(org.grails.io.support.Resource) UrlResource(org.grails.io.support.UrlResource)

Example 5 with UrlResource

use of org.grails.io.support.UrlResource in project grails-core by grails.

the class GrailsResourceUtilsTests method testGetViewsDirForURL.

public void testGetViewsDirForURL() throws Exception {
    Resource viewsDir = GrailsResourceUtils.getViewsDir(new UrlResource(TEST_CONTROLLER_URL));
    assertEquals(toFileUrl("/test/grails/app/grails-app/views"), viewsDir.getURL().toString());
    viewsDir = GrailsResourceUtils.getViewsDir(new UrlResource(TEST_URL));
    assertEquals(toFileUrl("/test/grails/app/grails-app/views"), viewsDir.getURL().toString());
}
Also used : UrlResource(org.grails.io.support.UrlResource) Resource(org.grails.io.support.Resource) UrlResource(org.grails.io.support.UrlResource)

Aggregations

UrlResource (org.grails.io.support.UrlResource)7 Resource (org.grails.io.support.Resource)5 URL (java.net.URL)3 IOException (java.io.IOException)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockServletContext (org.springframework.mock.web.MockServletContext)1