AMImageHTMLExportImportContentProcessor implements ExportImportContentProcessor<String> { @Override public void validateContentReferences(long groupId, String content) throws PortalException { Document document = _parseDocument(content); String elementSelector = "[" + AMImageHTMLConstants.ATTRIBUTE_NAME_FILE_ENTRY_ID + "]"; for (Element element : document.select(elementSelector)) { long fileEntryId = Long.valueOf( element.attr( AMImageHTMLConstants.ATTRIBUTE_NAME_FILE_ENTRY_ID)); _dlAppLocalService.getFileEntry(fileEntryId); } }  @Override String replaceExportContentReferences(
		PortletDataContext portletDataContext, StagedModel stagedModel,
		String content, boolean exportReferencedContent,
		boolean escapeContent); @Override String replaceImportContentReferences(
			PortletDataContext portletDataContext, StagedModel stagedModel,
			String content); @Override void validateContentReferences(long groupId, String content);  }
@Test(expected = NoSuchFileEntryException.class) public void testValidateContentFailsWithInvalidReferences() throws Exception { StringBundler sb = new StringBundler(5); sb.append("<img data-fileentryid=\""); sb.append(RandomTestUtil.randomLong()); sb.append("\" src=\"PATH_"); sb.append(_FILE_ENTRY_ID_1); sb.append("\" />"); _amImageHTMLExportImportContentProcessor.validateContentReferences( RandomTestUtil.randomLong(), sb.toString()); }
@Test(expected = NoSuchFileEntryException.class) public void testValidateContentFailsWithInvalidStaticReferences() throws Exception { String content = "<picture data-fileentryid=\"" + RandomTestUtil.randomLong() + "\"></picture>"; _amImageHTMLExportImportContentProcessor.validateContentReferences( RandomTestUtil.randomLong(), content); }
@Test public void testValidateContentSucceedsWhenAllReferencesAreValid() throws Exception { StringBundler sb = new StringBundler(5); sb.append("<img data-fileentryid=\""); sb.append(_FILE_ENTRY_ID_1); sb.append("\" src=\"PATH_"); sb.append(_FILE_ENTRY_ID_1); sb.append("\" />"); _amImageHTMLExportImportContentProcessor.validateContentReferences( RandomTestUtil.randomLong(), sb.toString()); }
@Test public void testValidateContentSucceedsWhenAllStaticReferencesAreValid() throws Exception { Mockito.doReturn( _fileEntry1 ).when( _dlAppLocalService ).getFileEntry( _FILE_ENTRY_ID_1 ); String content = "<picture data-fileentryid=\"" + _FILE_ENTRY_ID_1 + "\"></picture>"; _amImageHTMLExportImportContentProcessor.validateContentReferences( RandomTestUtil.randomLong(), content); }