DefaultAMURIResolver implements AMURIResolver { @Override public URI resolveURI(URI relativeURI) { String pathModule = _portal.getPathModule(); if (!pathModule.endsWith(StringPool.SLASH)) { pathModule += StringPool.SLASH; } String servletPath = pathModule + AMWebConstants.SERVLET_PATH + StringPool.SLASH; URI moduleURI = URI.create(servletPath); return moduleURI.resolve(relativeURI); }  @Override URI resolveURI(URI relativeURI);  }
@Test public void testMediaURIWhenPathDoesNotEndInSlash() { String pathModule = StringPool.SLASH + RandomTestUtil.randomString(); Mockito.when( _portal.getPathModule() ).thenReturn( pathModule ); URI relativeURI = URI.create(RandomTestUtil.randomString()); String uriString = String.valueOf( _amURIResolver.resolveURI(relativeURI)); Assert.assertTrue(uriString, uriString.contains(pathModule)); Assert.assertTrue( uriString, uriString.contains(AMWebConstants.SERVLET_PATH)); Assert.assertTrue( uriString, uriString.contains(relativeURI.toString())); }
@Test public void testMediaURIWhenPathEndsInSlash() { String pathModule = StringPool.SLASH + RandomTestUtil.randomString() + StringPool.SLASH; Mockito.when( _portal.getPathModule() ).thenReturn( pathModule ); URI relativeURI = URI.create(RandomTestUtil.randomString()); String uriString = String.valueOf( _amURIResolver.resolveURI(relativeURI)); Assert.assertTrue(uriString, uriString.contains(pathModule)); Assert.assertTrue( uriString, uriString.contains(AMWebConstants.SERVLET_PATH)); Assert.assertTrue( uriString, uriString.contains(relativeURI.toString())); }