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);
}
Aggregations