@Test public void testIncomingRssMessage() throws DbException, FormatException { Transaction txn = new Transaction(null, false); BdfList body = BdfList.of("body"); BdfDictionary meta = BdfDictionary.of( new BdfEntry(KEY_TYPE, POST.getInt()), new BdfEntry(KEY_TIMESTAMP, timestamp), new BdfEntry(KEY_TIME_RECEIVED, timeReceived), new BdfEntry(KEY_AUTHOR, rssAuthorList), new BdfEntry(KEY_READ, false), new BdfEntry(KEY_RSS_FEED, true) ); context.checking(new Expectations() {{ oneOf(clientHelper).parseAndValidateAuthor(rssAuthorList); will(returnValue(rssLocalAuthor)); }}); blogManager.incomingMessage(txn, rssMessage, body, meta); context.assertIsSatisfied(); assertEquals(1, txn.getEvents().size()); assertTrue(txn.getEvents().get(0) instanceof BlogPostAddedEvent); BlogPostAddedEvent e = (BlogPostAddedEvent) txn.getEvents().get(0); assertEquals(rssBlog.getId(), e.getGroupId()); BlogPostHeader h = e.getHeader(); assertEquals(POST, h.getType()); assertTrue(h.isRssFeed()); assertEquals(timestamp, h.getTimestamp()); assertEquals(timeReceived, h.getTimeReceived()); assertEquals(rssMessageId, h.getId()); assertEquals(rssBlog.getId(), h.getGroupId()); assertNull(h.getParentId()); assertEquals(NONE, h.getAuthorStatus()); assertEquals(rssLocalAuthor, h.getAuthor()); }
@Override protected boolean incomingMessage(Transaction txn, Message m, BdfList list, BdfDictionary meta) throws DbException, FormatException { GroupId groupId = m.getGroupId(); MessageType type = getMessageType(meta); if (type == POST || type == COMMENT) { BlogPostHeader h = getPostHeaderFromMetadata(txn, groupId, m.getId(), meta); if (type == COMMENT) { MessageId parentId = h.getParentId(); if (parentId == null) throw new FormatException(); BdfDictionary d = clientHelper .getMessageMetadataAsDictionary(txn, parentId); byte[] original1 = d.getRaw(KEY_ORIGINAL_MSG_ID); byte[] original2 = meta.getRaw(KEY_ORIGINAL_PARENT_MSG_ID); if (!Arrays.equals(original1, original2)) { throw new FormatException(); } } BlogPostAddedEvent event = new BlogPostAddedEvent(groupId, h, false); txn.attach(event); return true; } else if (type == WRAPPED_COMMENT) { MessageId dependencyId = new MessageId(meta.getRaw(KEY_PARENT_MSG_ID)); BdfDictionary d = clientHelper .getMessageMetadataAsDictionary(txn, dependencyId); byte[] original1 = d.getRaw(KEY_ORIGINAL_MSG_ID); byte[] original2 = meta.getRaw(KEY_ORIGINAL_PARENT_MSG_ID); if (!Arrays.equals(original1, original2)) { throw new FormatException(); } } return false; }
BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
		ContactHook, Client { @Override protected boolean incomingMessage(Transaction txn, Message m, BdfList list, BdfDictionary meta) throws DbException, FormatException { GroupId groupId = m.getGroupId(); MessageType type = getMessageType(meta); if (type == POST || type == COMMENT) { BlogPostHeader h = getPostHeaderFromMetadata(txn, groupId, m.getId(), meta); if (type == COMMENT) { MessageId parentId = h.getParentId(); if (parentId == null) throw new FormatException(); BdfDictionary d = clientHelper .getMessageMetadataAsDictionary(txn, parentId); byte[] original1 = d.getRaw(KEY_ORIGINAL_MSG_ID); byte[] original2 = meta.getRaw(KEY_ORIGINAL_PARENT_MSG_ID); if (!Arrays.equals(original1, original2)) { throw new FormatException(); } } BlogPostAddedEvent event = new BlogPostAddedEvent(groupId, h, false); txn.attach(event); return true; } else if (type == WRAPPED_COMMENT) { MessageId dependencyId = new MessageId(meta.getRaw(KEY_PARENT_MSG_ID)); BdfDictionary d = clientHelper .getMessageMetadataAsDictionary(txn, dependencyId); byte[] original1 = d.getRaw(KEY_ORIGINAL_MSG_ID); byte[] original2 = meta.getRaw(KEY_ORIGINAL_PARENT_MSG_ID); if (!Arrays.equals(original1, original2)) { throw new FormatException(); } } return false; } }
BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
		ContactHook, Client { @Override protected boolean incomingMessage(Transaction txn, Message m, BdfList list, BdfDictionary meta) throws DbException, FormatException { GroupId groupId = m.getGroupId(); MessageType type = getMessageType(meta); if (type == POST || type == COMMENT) { BlogPostHeader h = getPostHeaderFromMetadata(txn, groupId, m.getId(), meta); if (type == COMMENT) { MessageId parentId = h.getParentId(); if (parentId == null) throw new FormatException(); BdfDictionary d = clientHelper .getMessageMetadataAsDictionary(txn, parentId); byte[] original1 = d.getRaw(KEY_ORIGINAL_MSG_ID); byte[] original2 = meta.getRaw(KEY_ORIGINAL_PARENT_MSG_ID); if (!Arrays.equals(original1, original2)) { throw new FormatException(); } } BlogPostAddedEvent event = new BlogPostAddedEvent(groupId, h, false); txn.attach(event); return true; } else if (type == WRAPPED_COMMENT) { MessageId dependencyId = new MessageId(meta.getRaw(KEY_PARENT_MSG_ID)); BdfDictionary d = clientHelper .getMessageMetadataAsDictionary(txn, dependencyId); byte[] original1 = d.getRaw(KEY_ORIGINAL_MSG_ID); byte[] original2 = meta.getRaw(KEY_ORIGINAL_PARENT_MSG_ID); if (!Arrays.equals(original1, original2)) { throw new FormatException(); } } return false; } @Inject  BlogManagerImpl(DatabaseComponent db, IdentityManager identityManager,
			ClientHelper clientHelper, MetadataParser metadataParser,
			BlogFactory blogFactory, BlogPostFactory blogPostFactory); }
BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
		ContactHook, Client { @Override protected boolean incomingMessage(Transaction txn, Message m, BdfList list, BdfDictionary meta) throws DbException, FormatException { GroupId groupId = m.getGroupId(); MessageType type = getMessageType(meta); if (type == POST || type == COMMENT) { BlogPostHeader h = getPostHeaderFromMetadata(txn, groupId, m.getId(), meta); if (type == COMMENT) { MessageId parentId = h.getParentId(); if (parentId == null) throw new FormatException(); BdfDictionary d = clientHelper .getMessageMetadataAsDictionary(txn, parentId); byte[] original1 = d.getRaw(KEY_ORIGINAL_MSG_ID); byte[] original2 = meta.getRaw(KEY_ORIGINAL_PARENT_MSG_ID); if (!Arrays.equals(original1, original2)) { throw new FormatException(); } } BlogPostAddedEvent event = new BlogPostAddedEvent(groupId, h, false); txn.attach(event); return true; } else if (type == WRAPPED_COMMENT) { MessageId dependencyId = new MessageId(meta.getRaw(KEY_PARENT_MSG_ID)); BdfDictionary d = clientHelper .getMessageMetadataAsDictionary(txn, dependencyId); byte[] original1 = d.getRaw(KEY_ORIGINAL_MSG_ID); byte[] original2 = meta.getRaw(KEY_ORIGINAL_PARENT_MSG_ID); if (!Arrays.equals(original1, original2)) { throw new FormatException(); } } return false; } @Inject  BlogManagerImpl(DatabaseComponent db, IdentityManager identityManager,
			ClientHelper clientHelper, MetadataParser metadataParser,
			BlogFactory blogFactory, BlogPostFactory blogPostFactory); @Override void createLocalState(Transaction txn); @Override void addingContact(Transaction txn, Contact c); @Override void removingContact(Transaction txn, Contact c); @Override void addBlog(Blog b); @Override void addBlog(Transaction txn, Blog b); @Override boolean canBeRemoved(Blog b); @Override void removeBlog(Blog b); @Override void removeBlog(Transaction txn, Blog b); @Override void addLocalPost(BlogPost p); @Override void addLocalPost(Transaction txn, BlogPost p); @Override void addLocalComment(LocalAuthor author, GroupId groupId,
			@Nullable String comment, BlogPostHeader parentHeader); @Override Blog getBlog(GroupId g); @Override Blog getBlog(Transaction txn, GroupId g); @Override Collection<Blog> getBlogs(LocalAuthor localAuthor); @Override Blog getPersonalBlog(Author author); @Override Collection<Blog> getBlogs(); @Override BlogPostHeader getPostHeader(GroupId g, MessageId m); @Override String getPostBody(MessageId m); @Override Collection<BlogPostHeader> getPostHeaders(GroupId g); @Override void setReadFlag(MessageId m, boolean read); @Override void registerRemoveBlogHook(RemoveBlogHook hook); }
BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
		ContactHook, Client { @Override protected boolean incomingMessage(Transaction txn, Message m, BdfList list, BdfDictionary meta) throws DbException, FormatException { GroupId groupId = m.getGroupId(); MessageType type = getMessageType(meta); if (type == POST || type == COMMENT) { BlogPostHeader h = getPostHeaderFromMetadata(txn, groupId, m.getId(), meta); if (type == COMMENT) { MessageId parentId = h.getParentId(); if (parentId == null) throw new FormatException(); BdfDictionary d = clientHelper .getMessageMetadataAsDictionary(txn, parentId); byte[] original1 = d.getRaw(KEY_ORIGINAL_MSG_ID); byte[] original2 = meta.getRaw(KEY_ORIGINAL_PARENT_MSG_ID); if (!Arrays.equals(original1, original2)) { throw new FormatException(); } } BlogPostAddedEvent event = new BlogPostAddedEvent(groupId, h, false); txn.attach(event); return true; } else if (type == WRAPPED_COMMENT) { MessageId dependencyId = new MessageId(meta.getRaw(KEY_PARENT_MSG_ID)); BdfDictionary d = clientHelper .getMessageMetadataAsDictionary(txn, dependencyId); byte[] original1 = d.getRaw(KEY_ORIGINAL_MSG_ID); byte[] original2 = meta.getRaw(KEY_ORIGINAL_PARENT_MSG_ID); if (!Arrays.equals(original1, original2)) { throw new FormatException(); } } return false; } @Inject  BlogManagerImpl(DatabaseComponent db, IdentityManager identityManager,
			ClientHelper clientHelper, MetadataParser metadataParser,
			BlogFactory blogFactory, BlogPostFactory blogPostFactory); @Override void createLocalState(Transaction txn); @Override void addingContact(Transaction txn, Contact c); @Override void removingContact(Transaction txn, Contact c); @Override void addBlog(Blog b); @Override void addBlog(Transaction txn, Blog b); @Override boolean canBeRemoved(Blog b); @Override void removeBlog(Blog b); @Override void removeBlog(Transaction txn, Blog b); @Override void addLocalPost(BlogPost p); @Override void addLocalPost(Transaction txn, BlogPost p); @Override void addLocalComment(LocalAuthor author, GroupId groupId,
			@Nullable String comment, BlogPostHeader parentHeader); @Override Blog getBlog(GroupId g); @Override Blog getBlog(Transaction txn, GroupId g); @Override Collection<Blog> getBlogs(LocalAuthor localAuthor); @Override Blog getPersonalBlog(Author author); @Override Collection<Blog> getBlogs(); @Override BlogPostHeader getPostHeader(GroupId g, MessageId m); @Override String getPostBody(MessageId m); @Override Collection<BlogPostHeader> getPostHeaders(GroupId g); @Override void setReadFlag(MessageId m, boolean read); @Override void registerRemoveBlogHook(RemoveBlogHook hook);  }