TrackbackMVCActionCommand extends BaseMVCActionCommand { public void addTrackback( ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { try { BlogsEntry entry = getBlogsEntry(actionRequest); validate(entry); ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY); HttpServletRequest httpServletRequest = _portal.getHttpServletRequest(actionRequest); HttpServletRequest originalHttpServletRequest = _portal.getOriginalServletRequest(httpServletRequest); String excerpt = ParamUtil.getString( originalHttpServletRequest, "excerpt"); String url = ParamUtil.getString(originalHttpServletRequest, "url"); String blogName = ParamUtil.getString( originalHttpServletRequest, "blog_name"); String title = ParamUtil.getString( originalHttpServletRequest, "title"); validate(actionRequest, httpServletRequest.getRemoteAddr(), url); _trackback.addTrackback( entry, themeDisplay, excerpt, url, blogName, title, new ServiceContextFunction(actionRequest)); } catch (TrackbackValidationException trackbackValidationException) { sendError( actionRequest, actionResponse, trackbackValidationException.getMessage()); return; } sendSuccess(actionRequest, actionResponse); }  void addTrackback(
			ActionRequest actionRequest, ActionResponse actionResponse);  }
@Test public void testDisabledComments() throws Exception { whenGetEntryThenReturn(_blogsEntry); when( _portletPreferences.getValue("enableComments", null) ).thenReturn( "false" ); addTrackback(); assertError("Comments are disabled"); }
@Test public void testMismatchedIPAddress() throws Exception { whenGetEntryThenReturn(_blogsEntry); initURL("123"); addTrackback(); assertError("Remote IP does not match the trackback URL's IP"); }
@Test public void testMissingURL() throws Exception { whenGetEntryThenReturn(_blogsEntry); addTrackback(); assertError("Trackback requires a valid permanent URL"); }
@Test(expected = NoSuchEntryException.class) public void testNoSuchEntryException() throws Exception { whenGetEntryThenThrow(new NoSuchEntryException()); initValidURL(); addTrackback(); }
@Test public void testPrincipalException() throws Exception { whenGetEntryThenThrow(new PrincipalException()); initValidURL(); addTrackback(); assertError( "Blog entry must have guest view permissions to enable trackbacks"); }
@Test public void testSuccess() throws Exception { whenGetEntryThenReturn(_blogsEntry); _mockOriginalServletRequest.setParameter("blog_name", "__blogName__"); _mockOriginalServletRequest.setParameter("excerpt", "__excerpt__"); _mockOriginalServletRequest.setParameter("title", "__title__"); initValidURL(); addTrackback(); assertSuccess(); Mockito.verify( _trackback ).addTrackback( Matchers.same(_blogsEntry), Matchers.same(_themeDisplay), Matchers.eq("__excerpt__"), Matchers.eq("__url__"), Matchers.eq("__blogName__"), Matchers.eq("__title__"), (Function<String, ServiceContext>)Matchers.any() ); }
@Test public void testTrackbacksNotEnabled() throws Exception { whenGetEntryThenReturn(_blogsEntry); when( _blogsEntry.isAllowTrackbacks() ).thenReturn( false ); initValidURL(); addTrackback(); assertError("Trackbacks are not enabled"); }