PathInterpreter { public Optional<Tuple<FileVersion, Map<String, String>>> interpretPath( String pathInfo) { try { if (pathInfo == null) { throw new IllegalArgumentException("Path information is null"); } Matcher matcher = _pattern.matcher(pathInfo); if (!matcher.matches()) { return Optional.empty(); } long fileEntryId = Long.valueOf(matcher.group(1)); FileEntry fileEntry = _dlAppService.getFileEntry(fileEntryId); long fileVersionId = _getFileVersionId(matcher); FileVersion fileVersion = _getFileVersion(fileEntry, fileVersionId); String configurationEntryUUID = _getConfigurationEntryUUID(matcher); Optional<AMImageConfigurationEntry> amImageConfigurationEntryOptional = _amImageConfigurationHelper.getAMImageConfigurationEntry( fileVersion.getCompanyId(), configurationEntryUUID); Map<String, String> properties = amImageConfigurationEntryOptional.map( amImageConfigurationEntry -> { Map<String, String> curProperties = amImageConfigurationEntry.getProperties(); AMAttribute<?, String> configurationUuidAMAttribute = AMAttribute.getConfigurationUuidAMAttribute(); curProperties.put( configurationUuidAMAttribute.getName(), amImageConfigurationEntry.getUUID()); return curProperties; } ).orElse( new HashMap<>() ); return Optional.of(Tuple.of(fileVersion, properties)); } catch (PortalException portalException) { throw new AMRuntimeException(portalException); } }  Optional<Tuple<FileVersion, Map<String, String>>> interpretPath(
		String pathInfo);  }
@Test public void testFileEntryPath() throws Exception { Mockito.when( _dlAppService.getFileEntry(Mockito.anyLong()) ).thenReturn( _fileEntry ); Mockito.when( _fileEntry.getFileVersion() ).thenReturn( _fileVersion ); Mockito.when( _amImageConfigurationHelper.getAMImageConfigurationEntry( Mockito.anyLong(), Mockito.eq("x")) ).thenReturn( Optional.of(_amImageConfigurationEntry) ); _pathInterpreter.interpretPath("/image/0/x/foo.jpg"); Mockito.verify( _dlAppService ).getFileEntry( 0 ); Mockito.verify( _fileVersion ).getCompanyId(); Mockito.verify( _amImageConfigurationEntry ).getProperties(); Mockito.verify( _amImageConfigurationEntry ).getUUID(); }
@Test(expected = AMRuntimeException.class) public void testFileEntryPathDLAppFailure() throws Exception { Mockito.when( _dlAppService.getFileEntry(0) ).thenThrow( PortalException.class ); _pathInterpreter.interpretPath("/image/0/x/foo.jpg"); }
@Test(expected = AMRuntimeException.class) public void testFileEntryPathGetFileVersionFailure() throws Exception { Mockito.when( _dlAppService.getFileEntry(0) ).thenReturn( _fileEntry ); Mockito.when( _fileEntry.getFileVersion() ).thenThrow( PortalException.class ); _pathInterpreter.interpretPath("/image/0/x/foo.jpg"); }
@Test public void testFileEntryPathWithTimestamp() throws Exception { Mockito.when( _dlAppService.getFileEntry(Mockito.anyLong()) ).thenReturn( _fileEntry ); Mockito.when( _fileEntry.getFileVersion() ).thenReturn( _fileVersion ); Mockito.when( _amImageConfigurationHelper.getAMImageConfigurationEntry( Mockito.anyLong(), Mockito.eq("x")) ).thenReturn( Optional.of(_amImageConfigurationEntry) ); _pathInterpreter.interpretPath("/image/0/x/foo.jpg?t=12345"); Mockito.verify( _dlAppService ).getFileEntry( 0 ); Mockito.verify( _fileVersion ).getCompanyId(); Mockito.verify( _amImageConfigurationEntry ).getProperties(); Mockito.verify( _amImageConfigurationEntry ).getUUID(); }
@Test public void testFileVersionPath() throws Exception { Mockito.when( _dlAppService.getFileVersion(1) ).thenReturn( _fileVersion ); Mockito.when( _amImageConfigurationHelper.getAMImageConfigurationEntry( Mockito.anyLong(), Mockito.eq("x")) ).thenReturn( Optional.of(_amImageConfigurationEntry) ); _pathInterpreter.interpretPath("/image/0/1/x/foo.jpg"); Mockito.verify( _dlAppService ).getFileEntry( 0 ); Mockito.verify( _dlAppService ).getFileVersion( 1 ); Mockito.verify( _fileVersion ).getCompanyId(); Mockito.verify( _amImageConfigurationEntry ).getProperties(); Mockito.verify( _amImageConfigurationEntry ).getUUID(); }
@Test(expected = AMRuntimeException.class) public void testFileVersionPathDLAppFailure() throws Exception { Mockito.when( _dlAppService.getFileVersion(1) ).thenThrow( PortalException.class ); _pathInterpreter.interpretPath("/image/0/1/x/foo.jpg"); }
@Test public void testNonmatchingPathInfo() { Optional<Tuple<FileVersion, Map<String, String>>> resultOptional = _pathInterpreter.interpretPath("/" + RandomTestUtil.randomString()); Assert.assertFalse(resultOptional.isPresent()); }
@Test(expected = IllegalArgumentException.class) public void testNullPathInfoFails() { _pathInterpreter.interpretPath(null); }