Search in sources :

Example 1 with IBlogServiceRole

use of com.celements.blog.service.IBlogServiceRole in project celements-blog by celements.

the class NewsletterReceiversTest method unsubscribeLink.

private void unsubscribeLink(String email) throws Exception {
    String spaceName = "TestSpace";
    String docName = "BlogArticle";
    String urlParams = "xpage=celements_ajax&ajax_mode=BlogAjax&doaction=unsubscribe&emailadresse=";
    String urlStaticPart = "http://celements.com/" + spaceName + "/" + docName + "?" + urlParams;
    URL url = new URL(urlStaticPart + URLEncoder.encode(email, UTF_8.name()));
    IBlogServiceRole blogServiceMock = registerComponentMock(IBlogServiceRole.class);
    XWikiDocument doc = new XWikiDocument(new DocumentReference(getContext().getDatabase(), spaceName, docName));
    BaseObject blogObj = new BaseObject();
    blogObj.setXClassReference(new DocumentReference(getContext().getDatabase(), "Celements2", "BlogConfigClass"));
    blogObj.setIntValue("unsubscribe_info", 1);
    doc.addXObject(blogObj);
    expect(blogServiceMock.getBlogPageByBlogSpace(eq(spaceName))).andReturn(doc);
    XWikiURLFactory urlFactoryMock = createMockAndAddToDefault(XWikiURLFactory.class);
    getContext().setURLFactory(urlFactoryMock);
    expect(urlFactoryMock.createExternalURL(eq(spaceName), eq(docName), eq("view"), eq(urlParams + URLEncoder.encode(email, UTF_8.name())), (String) eq(null), eq(getContext().getDatabase()), same(getContext()))).andReturn(url);
    replayDefault();
    String link = comp.getUnsubscribeLink(spaceName, email);
    verifyDefault();
    assertEquals(url.toString(), link);
}
Also used : XWikiURLFactory(com.xpn.xwiki.web.XWikiURLFactory) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) IBlogServiceRole(com.celements.blog.service.IBlogServiceRole) URL(java.net.URL) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject)

Aggregations

IBlogServiceRole (com.celements.blog.service.IBlogServiceRole)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 BaseObject (com.xpn.xwiki.objects.BaseObject)1 XWikiURLFactory (com.xpn.xwiki.web.XWikiURLFactory)1 URL (java.net.URL)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1