AMJournalEditorConfigContributor extends BaseEditorConfigContributor { @Override public void populateConfigJSONObject( JSONObject jsonObject, Map<String, Object> inputEditorTaglibAttributes, ThemeDisplay themeDisplay, RequestBackedPortletURLFactory requestBackedPortletURLFactory) { String allowedContent = jsonObject.getString("allowedContent"); if (Validator.isNotNull(allowedContent) && !allowedContent.equals(Boolean.TRUE.toString())) { allowedContent += StringPool.SPACE + _IMG_TAG_RULE; jsonObject.put("allowedContent", allowedContent); } String itemSelectorURL = jsonObject.getString( "filebrowserImageBrowseLinkUrl"); if (Validator.isNull(itemSelectorURL)) { return; } List<ItemSelectorCriterion> itemSelectorCriteria = _itemSelector.getItemSelectorCriteria(itemSelectorURL); boolean amImageURLItemSelectorReturnTypeAdded = false; for (ItemSelectorCriterion itemSelectorCriterion : itemSelectorCriteria) { if (itemSelectorCriterion instanceof FileItemSelectorCriterion || itemSelectorCriterion instanceof ImageItemSelectorCriterion || itemSelectorCriterion instanceof JournalItemSelectorCriterion || itemSelectorCriterion instanceof UploadItemSelectorCriterion) { addAMImageFileEntryItemSelectorReturnType( itemSelectorCriterion); amImageURLItemSelectorReturnTypeAdded = true; } } if (!amImageURLItemSelectorReturnTypeAdded) { return; } jsonObject.put( "adaptiveMediaFileEntryAttributeName", AMImageHTMLConstants.ATTRIBUTE_NAME_FILE_ENTRY_ID); String extraPlugins = jsonObject.getString("extraPlugins"); if (Validator.isNotNull(extraPlugins)) { extraPlugins = extraPlugins + ",adaptivemedia"; } else { extraPlugins = "adaptivemedia"; } jsonObject.put("extraPlugins", extraPlugins); PortletURL itemSelectorPortletURL = _itemSelector.getItemSelectorURL( requestBackedPortletURLFactory, _itemSelector.getItemSelectedEventName(itemSelectorURL), itemSelectorCriteria.toArray(new ItemSelectorCriterion[0])); jsonObject.put( "filebrowserImageBrowseLinkUrl", itemSelectorPortletURL.toString() ).put( "filebrowserImageBrowseUrl", itemSelectorPortletURL.toString() ); }  @Override void populateConfigJSONObject(
		JSONObject jsonObject, Map<String, Object> inputEditorTaglibAttributes,
		ThemeDisplay themeDisplay,
		RequestBackedPortletURLFactory requestBackedPortletURLFactory);  }
@Test public void testAdaptiveMediaFileEntryAttributeNameIsAdded() throws Exception { PortletURL itemSelectorPortletURL = mock(PortletURL.class); when( itemSelectorPortletURL.toString() ).thenReturn( "itemSelectorPortletURL" ); when( _itemSelector.getItemSelectorURL( Mockito.any(RequestBackedPortletURLFactory.class), Mockito.anyString(), Mockito.any(ItemSelectorCriterion.class)) ).thenReturn( itemSelectorPortletURL ); when( _itemSelector.getItemSelectedEventName(Mockito.anyString()) ).thenReturn( "selectedEventName" ); when( _itemSelector.getItemSelectorCriteria( "journalItemSelectorCriterionFileEntryItemSelectorReturnType") ).thenReturn( _getBlogsItemSelectorCriterionFileEntryItemSelectorReturnType() ); JSONObject originalJSONObject = JSONUtil.put( "filebrowserImageBrowseLinkUrl", "journalItemSelectorCriterionFileEntryItemSelectorReturnType"); JSONObject jsonObject = JSONFactoryUtil.createJSONObject( originalJSONObject.toJSONString()); AMJournalEditorConfigContributor amBlogsEditorConfigContributor = new AMJournalEditorConfigContributor(); ReflectionTestUtil.setFieldValue( amBlogsEditorConfigContributor, "_itemSelector", _itemSelector); amBlogsEditorConfigContributor.populateConfigJSONObject( jsonObject, _inputEditorTaglibAttributes, _themeDisplay, _requestBackedPortletURLFactory); Assert.assertEquals( "data-fileentryid", jsonObject.get("adaptiveMediaFileEntryAttributeName")); }
@Test public void testAdaptiveMediaIsAddedToExtraPlugins() throws Exception { PortletURL itemSelectorPortletURL = mock(PortletURL.class); when( itemSelectorPortletURL.toString() ).thenReturn( "itemSelectorPortletURL" ); when( _itemSelector.getItemSelectorURL( Mockito.any(RequestBackedPortletURLFactory.class), Mockito.anyString(), Mockito.any(ItemSelectorCriterion.class)) ).thenReturn( itemSelectorPortletURL ); when( _itemSelector.getItemSelectedEventName(Mockito.anyString()) ).thenReturn( "selectedEventName" ); when( _itemSelector.getItemSelectorCriteria( "journalItemSelectorCriterionFileEntryItemSelectorReturnType") ).thenReturn( _getBlogsItemSelectorCriterionFileEntryItemSelectorReturnType() ); JSONObject originalJSONObject = JSONUtil.put( "filebrowserImageBrowseLinkUrl", "journalItemSelectorCriterionFileEntryItemSelectorReturnType"); JSONObject jsonObject = JSONFactoryUtil.createJSONObject( originalJSONObject.toJSONString()); AMJournalEditorConfigContributor amJournalEditorConfigContributor = new AMJournalEditorConfigContributor(); ReflectionTestUtil.setFieldValue( amJournalEditorConfigContributor, "_itemSelector", _itemSelector); amJournalEditorConfigContributor.populateConfigJSONObject( jsonObject, _inputEditorTaglibAttributes, _themeDisplay, _requestBackedPortletURLFactory); Assert.assertEquals( "adaptivemedia", jsonObject.getString("extraPlugins")); }
@Test public void testAdaptiveMediaIsExtraPlugins() throws Exception { PortletURL itemSelectorPortletURL = mock(PortletURL.class); when( itemSelectorPortletURL.toString() ).thenReturn( "itemSelectorPortletURL" ); when( _itemSelector.getItemSelectorURL( Mockito.any(RequestBackedPortletURLFactory.class), Mockito.anyString(), Mockito.any(ItemSelectorCriterion.class)) ).thenReturn( itemSelectorPortletURL ); when( _itemSelector.getItemSelectedEventName(Mockito.anyString()) ).thenReturn( "selectedEventName" ); when( _itemSelector.getItemSelectorCriteria( "journalItemSelectorCriterionFileEntryItemSelectorReturnType") ).thenReturn( _getBlogsItemSelectorCriterionFileEntryItemSelectorReturnType() ); JSONObject originalJSONObject = JSONUtil.put( "extraPlugins", "ae_placeholder,ae_selectionregion,ae_uicore" ).put( "filebrowserImageBrowseLinkUrl", "journalItemSelectorCriterionFileEntryItemSelectorReturnType" ); JSONObject jsonObject = JSONFactoryUtil.createJSONObject( originalJSONObject.toJSONString()); AMJournalEditorConfigContributor amJournalEditorConfigContributor = new AMJournalEditorConfigContributor(); ReflectionTestUtil.setFieldValue( amJournalEditorConfigContributor, "_itemSelector", _itemSelector); amJournalEditorConfigContributor.populateConfigJSONObject( jsonObject, _inputEditorTaglibAttributes, _themeDisplay, _requestBackedPortletURLFactory); Assert.assertEquals( "ae_placeholder,ae_selectionregion,ae_uicore,adaptivemedia", jsonObject.getString("extraPlugins")); }
@Test public void testImgIsAddedToAllowedContent() throws Exception { JSONObject originalJSONObject = JSONUtil.put( "allowedContent", "a[*](*); div(*);"); JSONObject jsonObject = JSONFactoryUtil.createJSONObject( originalJSONObject.toJSONString()); AMJournalEditorConfigContributor amJournalEditorConfigContributor = new AMJournalEditorConfigContributor(); amJournalEditorConfigContributor.populateConfigJSONObject( jsonObject, _inputEditorTaglibAttributes, _themeDisplay, _requestBackedPortletURLFactory); JSONObject expectedJSONObject = JSONUtil.put( "allowedContent", "a[*](*); div(*); img[*](*){*};"); JSONAssert.assertEquals( expectedJSONObject.toJSONString(), jsonObject.toJSONString(), true); }
@Test public void testImgIsAllowedContent() throws Exception { JSONObject originalJSONObject = JSONFactoryUtil.createJSONObject(); JSONObject jsonObject = JSONFactoryUtil.createJSONObject( originalJSONObject.toJSONString()); AMJournalEditorConfigContributor amJournalEditorConfigContributor = new AMJournalEditorConfigContributor(); amJournalEditorConfigContributor.populateConfigJSONObject( jsonObject, _inputEditorTaglibAttributes, _themeDisplay, _requestBackedPortletURLFactory); JSONObject expectedJSONObject = JSONFactoryUtil.createJSONObject(); JSONAssert.assertEquals( expectedJSONObject.toJSONString(), jsonObject.toJSONString(), true); }
@Test public void testImgIsNotAddedToAllowedContentIfEverythingWasAlreadyAllowed() throws Exception { JSONObject originalJSONObject = JSONUtil.put("allowedContent", true); JSONObject jsonObject = JSONFactoryUtil.createJSONObject( originalJSONObject.toJSONString()); AMJournalEditorConfigContributor amJournalEditorConfigContributor = new AMJournalEditorConfigContributor(); amJournalEditorConfigContributor.populateConfigJSONObject( jsonObject, _inputEditorTaglibAttributes, _themeDisplay, _requestBackedPortletURLFactory); JSONObject expectedJSONObject = JSONUtil.put("allowedContent", true); JSONAssert.assertEquals( expectedJSONObject.toJSONString(), jsonObject.toJSONString(), true); }
@Test public void testItemSelectorURLWhenNoFileBrowserImageBrowseLinkUrl() throws Exception { JSONObject originalJSONObject = JSONUtil.put( "filebrowserImageBrowseLinkUrl", StringPool.BLANK); JSONObject jsonObject = JSONFactoryUtil.createJSONObject( originalJSONObject.toJSONString()); AMJournalEditorConfigContributor amJournalEditorConfigContributor = new AMJournalEditorConfigContributor(); ReflectionTestUtil.setFieldValue( amJournalEditorConfigContributor, "_itemSelector", _itemSelector); amJournalEditorConfigContributor.populateConfigJSONObject( jsonObject, _inputEditorTaglibAttributes, _themeDisplay, _requestBackedPortletURLFactory); Mockito.verify( _itemSelector, Mockito.never() ).getItemSelectorURL( Mockito.any(RequestBackedPortletURLFactory.class), Mockito.anyString(), Mockito.any(ItemSelectorCriterion.class) ); JSONObject expectedJSONObject = JSONFactoryUtil.createJSONObject( originalJSONObject.toJSONString()); JSONAssert.assertEquals( expectedJSONObject.toJSONString(), jsonObject.toJSONString(), true); }
@Test public void testItemSelectorURLWithAudioItemSelectorCriterion() throws Exception { when( _itemSelector.getItemSelectorCriteria( "audioItemSelectorCriterionFileEntryItemSelectorReturnType") ).thenReturn( _getAudioItemSelectorCriterionFileEntryItemSelectorReturnType() ); JSONObject originalJSONObject = JSONUtil.put( "filebrowserImageBrowseLinkUrl", "audioItemSelectorCriterionFileEntryItemSelectorReturnType"); JSONObject jsonObject = JSONFactoryUtil.createJSONObject( originalJSONObject.toJSONString()); AMJournalEditorConfigContributor amJournalEditorConfigContributor = new AMJournalEditorConfigContributor(); ReflectionTestUtil.setFieldValue( amJournalEditorConfigContributor, "_itemSelector", _itemSelector); amJournalEditorConfigContributor.populateConfigJSONObject( jsonObject, _inputEditorTaglibAttributes, _themeDisplay, _requestBackedPortletURLFactory); Mockito.verify( _itemSelector, Mockito.never() ).getItemSelectorURL( Mockito.any(RequestBackedPortletURLFactory.class), Mockito.anyString(), Mockito.any(ItemSelectorCriterion.class) ); JSONObject expectedJSONObject = JSONFactoryUtil.createJSONObject( originalJSONObject.toJSONString()); JSONAssert.assertEquals( expectedJSONObject.toJSONString(), jsonObject.toJSONString(), true); }
@Test public void testItemSelectorURLWithBlogsItemSelectorCriterion() throws Exception { PortletURL itemSelectorPortletURL = mock(PortletURL.class); when( itemSelectorPortletURL.toString() ).thenReturn( "itemSelectorPortletURL" ); when( _itemSelector.getItemSelectorURL( Mockito.any(RequestBackedPortletURLFactory.class), Mockito.anyString(), Mockito.any(ItemSelectorCriterion.class)) ).thenReturn( itemSelectorPortletURL ); when( _itemSelector.getItemSelectedEventName(Mockito.anyString()) ).thenReturn( "selectedEventName" ); when( _itemSelector.getItemSelectorCriteria( "journalItemSelectorCriterionFileEntryItemSelectorReturnType") ).thenReturn( _getBlogsItemSelectorCriterionFileEntryItemSelectorReturnType() ); JSONObject originalJSONObject = JSONUtil.put( "filebrowserImageBrowseLinkUrl", "journalItemSelectorCriterionFileEntryItemSelectorReturnType"); JSONObject jsonObject = JSONFactoryUtil.createJSONObject( originalJSONObject.toJSONString()); AMJournalEditorConfigContributor amJournalEditorConfigContributor = new AMJournalEditorConfigContributor(); ReflectionTestUtil.setFieldValue( amJournalEditorConfigContributor, "_itemSelector", _itemSelector); amJournalEditorConfigContributor.populateConfigJSONObject( jsonObject, _inputEditorTaglibAttributes, _themeDisplay, _requestBackedPortletURLFactory); Mockito.verify( _itemSelector ).getItemSelectorURL( Mockito.any(RequestBackedPortletURLFactory.class), Mockito.anyString(), Mockito.any(ItemSelectorCriterion.class) ); }
@Test public void testItemSelectorURLWithFileItemSelectorCriterion() throws Exception { PortletURL itemSelectorPortletURL = mock(PortletURL.class); when( itemSelectorPortletURL.toString() ).thenReturn( "itemSelectorPortletURL" ); when( _itemSelector.getItemSelectorURL( Mockito.any(RequestBackedPortletURLFactory.class), Mockito.anyString(), Mockito.any(ItemSelectorCriterion.class)) ).thenReturn( itemSelectorPortletURL ); when( _itemSelector.getItemSelectedEventName(Mockito.anyString()) ).thenReturn( "selectedEventName" ); when( _itemSelector.getItemSelectorCriteria( "fileItemSelectorCriterionFileEntryItemSelectorReturnType") ).thenReturn( _getFileItemSelectorCriterionFileEntryItemSelectorReturnType() ); JSONObject originalJSONObject = JSONUtil.put( "filebrowserImageBrowseLinkUrl", "fileItemSelectorCriterionFileEntryItemSelectorReturnType"); JSONObject jsonObject = JSONFactoryUtil.createJSONObject( originalJSONObject.toJSONString()); AMJournalEditorConfigContributor amJournalEditorConfigContributor = new AMJournalEditorConfigContributor(); ReflectionTestUtil.setFieldValue( amJournalEditorConfigContributor, "_itemSelector", _itemSelector); amJournalEditorConfigContributor.populateConfigJSONObject( jsonObject, _inputEditorTaglibAttributes, _themeDisplay, _requestBackedPortletURLFactory); Mockito.verify( _itemSelector ).getItemSelectorURL( Mockito.any(RequestBackedPortletURLFactory.class), Mockito.anyString(), Mockito.any(ItemSelectorCriterion.class) ); }