/** * Get the handle for this uri. */ public String getHandle(String uri) { return this.getMapping(uri).getHandle(uri); }
public String getHandle(String uri) String handle = super.getHandle(uri); if (MediaEl.module().isLazyResolutionCreation())
path = mapping.getHandle(path);
@Test public void handlePrefixIsNotRemoved() { // GIVEN String uri = "/travel0"; URI2RepositoryMapping mapping = new URI2RepositoryMapping("", RepositoryConstants.WEBSITE, "/travel"); // WHEN String handle = mapping.getHandle(uri); // THEN assertThat(handle, is("/travel/travel0")); } }
@Test public void dotInFileNameResolvesSelectorsProperly() throws Exception { // GIVEN String uri = "http://example.com/page-1.1~foo=bar~.html"; state.setCurrentURI(uri); MockHttpServletResponse response = new MockHttpServletResponse(); // WHEN filter.doFilter(request, response, mock(FilterChain.class)); // THEN verify(mapping).getHandle("http://example.com/page-1.1.html"); }
@Test public void getHandleWhenLinkWithPrefixHandleExistInRepo() throws Exception { // GIVEN final URI2RepositoryMapping uri2RepositoryMapping = new URI2RepositoryMapping("/demo-project", "website", "/demoproject/year2010"); // WHEN String handle = uri2RepositoryMapping.getHandle("/demo-project/blah.ext"); // THEN assertThat(handle, is("/demoproject/year2010/blah")); }
@Test public void uriPrefixEndsWithSlash() throws Exception { // GIVEN final URI2RepositoryMapping uri2RepositoryMapping = new URI2RepositoryMapping("/sitemaps/", "googleSitemaps", ""); // WHEN String handle = uri2RepositoryMapping.getHandle("/sitemaps/siteMap.xml"); // THEN assertThat(handle, is("/siteMap")); }
@Test public void whenRequestingTheHandleMakeSureItIsNotAppendedTwice() throws Exception { // GIVEN final String uri = "/travel"; final URI2RepositoryMapping mapping = new URI2RepositoryMapping(); mapping.setHandlePrefix("/travel"); mapping.setURIPrefix(""); mapping.setRepository(RepositoryConstants.WEBSITE); // WHEN final String handle = mapping.getHandle(uri); // THEN assertThat("We're expecting the actual URI (which equals to the handle) plus a trailing slash", handle, is(uri + "/")); }