mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
Merge branch 'use-java-8-language-features' into 'master'
Use java 8 language features See merge request !621
This commit is contained in:
@@ -86,7 +86,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
this.identityManager = identityManager;
|
||||
this.blogFactory = blogFactory;
|
||||
this.blogPostFactory = blogPostFactory;
|
||||
removeHooks = new CopyOnWriteArrayList<RemoveBlogHook>();
|
||||
removeHooks = new CopyOnWriteArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -404,7 +404,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
throws DbException {
|
||||
|
||||
Collection<Blog> allBlogs = getBlogs();
|
||||
List<Blog> blogs = new ArrayList<Blog>();
|
||||
List<Blog> blogs = new ArrayList<>();
|
||||
for (Blog b : allBlogs) {
|
||||
if (b.getAuthor().equals(localAuthor)) {
|
||||
blogs.add(b);
|
||||
@@ -421,7 +421,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
@Override
|
||||
public Collection<Blog> getBlogs() throws DbException {
|
||||
try {
|
||||
List<Blog> blogs = new ArrayList<Blog>();
|
||||
List<Blog> blogs = new ArrayList<>();
|
||||
Collection<Group> groups;
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
@@ -492,7 +492,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
new BdfEntry(KEY_TYPE, COMMENT.getInt())
|
||||
);
|
||||
|
||||
Collection<BlogPostHeader> headers = new ArrayList<BlogPostHeader>();
|
||||
Collection<BlogPostHeader> headers = new ArrayList<>();
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
Map<MessageId, BdfDictionary> metadata1 =
|
||||
@@ -500,20 +500,18 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
Map<MessageId, BdfDictionary> metadata2 =
|
||||
clientHelper.getMessageMetadataAsDictionary(txn, g, query2);
|
||||
Map<MessageId, BdfDictionary> metadata =
|
||||
new HashMap<MessageId, BdfDictionary>(
|
||||
metadata1.size() + metadata2.size());
|
||||
new HashMap<>(metadata1.size() + metadata2.size());
|
||||
metadata.putAll(metadata1);
|
||||
metadata.putAll(metadata2);
|
||||
// get all authors we need to get the status for
|
||||
Set<AuthorId> authors = new HashSet<AuthorId>();
|
||||
Set<AuthorId> authors = new HashSet<>();
|
||||
for (Entry<MessageId, BdfDictionary> entry : metadata.entrySet()) {
|
||||
authors.add(new AuthorId(
|
||||
entry.getValue().getDictionary(KEY_AUTHOR)
|
||||
.getRaw(KEY_AUTHOR_ID)));
|
||||
}
|
||||
// get statuses for all authors
|
||||
Map<AuthorId, Status> authorStatuses =
|
||||
new HashMap<AuthorId, Status>();
|
||||
Map<AuthorId, Status> authorStatuses = new HashMap<>();
|
||||
for (AuthorId authorId : authors) {
|
||||
authorStatuses.put(authorId,
|
||||
identityManager.getAuthorStatus(txn, authorId));
|
||||
@@ -562,7 +560,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
GroupId groupId, MessageId id, BdfDictionary meta)
|
||||
throws DbException, FormatException {
|
||||
return getPostHeaderFromMetadata(txn, groupId, id, meta,
|
||||
Collections.<AuthorId, Status>emptyMap());
|
||||
Collections.emptyMap());
|
||||
}
|
||||
|
||||
private BlogPostHeader getPostHeaderFromMetadata(Transaction txn,
|
||||
|
||||
@@ -96,7 +96,7 @@ class MessageQueueManagerImpl implements MessageQueueManager {
|
||||
private QueueState loadQueueState(Transaction txn, GroupId g)
|
||||
throws DbException {
|
||||
try {
|
||||
TreeMap<Long, MessageId> pending = new TreeMap<Long, MessageId>();
|
||||
TreeMap<Long, MessageId> pending = new TreeMap<>();
|
||||
Metadata groupMeta = db.getGroupMetadata(txn, g);
|
||||
byte[] raw = groupMeta.get(QUEUE_STATE_KEY);
|
||||
if (raw == null) return new QueueState(0, 0, pending);
|
||||
@@ -231,7 +231,7 @@ class MessageQueueManagerImpl implements MessageQueueManager {
|
||||
m.getTimestamp(), queuePosition, m.getRaw());
|
||||
queueState.incomingPosition++;
|
||||
// Collect any consecutive messages
|
||||
List<MessageId> consecutive = new ArrayList<MessageId>();
|
||||
List<MessageId> consecutive = new ArrayList<>();
|
||||
MessageId next;
|
||||
while ((next = queueState.popIncomingMessageId()) != null)
|
||||
consecutive.add(next);
|
||||
|
||||
@@ -19,17 +19,12 @@ import javax.annotation.concurrent.ThreadSafe;
|
||||
public class MessageTreeImpl<T extends MessageTree.MessageNode>
|
||||
implements MessageTree<T> {
|
||||
|
||||
private final Map<MessageId, List<T>> nodeMap =
|
||||
new HashMap<MessageId, List<T>>();
|
||||
private final List<T> roots = new ArrayList<T>();
|
||||
private final List<List<T>> unsortedLists = new ArrayList<List<T>>();
|
||||
private final Map<MessageId, List<T>> nodeMap = new HashMap<>();
|
||||
private final List<T> roots = new ArrayList<>();
|
||||
private final List<List<T>> unsortedLists = new ArrayList<>();
|
||||
|
||||
private Comparator<T> comparator = new Comparator<T>() {
|
||||
@Override
|
||||
public int compare(T o1, T o2) {
|
||||
return Long.valueOf(o1.getTimestamp()).compareTo(o2.getTimestamp());
|
||||
}
|
||||
};
|
||||
private Comparator<T> comparator = (o1, o2) ->
|
||||
Long.valueOf(o1.getTimestamp()).compareTo(o2.getTimestamp());
|
||||
|
||||
@Override
|
||||
public synchronized void clear() {
|
||||
@@ -41,7 +36,7 @@ public class MessageTreeImpl<T extends MessageTree.MessageNode>
|
||||
public synchronized void add(Collection<T> nodes) {
|
||||
// add all nodes to the node map
|
||||
for (T node : nodes) {
|
||||
nodeMap.put(node.getId(), new ArrayList<T>());
|
||||
nodeMap.put(node.getId(), new ArrayList<>());
|
||||
}
|
||||
// parse the nodes for dependencies
|
||||
for (T node : nodes) {
|
||||
@@ -100,7 +95,7 @@ public class MessageTreeImpl<T extends MessageTree.MessageNode>
|
||||
|
||||
@Override
|
||||
public synchronized Collection<T> depthFirstOrder() {
|
||||
List<T> orderedList = new ArrayList<T>();
|
||||
List<T> orderedList = new ArrayList<>();
|
||||
for (T root : roots) {
|
||||
traverse(orderedList, root, 0);
|
||||
}
|
||||
|
||||
@@ -129,17 +129,7 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
|
||||
private void startFeedExecutor() {
|
||||
if (fetcherStarted.getAndSet(true)) return;
|
||||
LOG.info("Tor started, scheduling RSS feed fetcher");
|
||||
Runnable fetcher = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ioExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
fetchFeeds();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
Runnable fetcher = () -> ioExecutor.execute(this::fetchFeeds);
|
||||
scheduler.scheduleWithFixedDelay(fetcher, FETCH_DELAY_INITIAL,
|
||||
FETCH_INTERVAL, FETCH_UNIT);
|
||||
}
|
||||
@@ -154,7 +144,7 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
|
||||
db.addGroup(txn, g);
|
||||
|
||||
// Add initial metadata
|
||||
List<Feed> feeds = new ArrayList<Feed>(0);
|
||||
List<Feed> feeds = new ArrayList<>(0);
|
||||
storeFeeds(txn, feeds);
|
||||
}
|
||||
|
||||
@@ -237,7 +227,7 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
|
||||
}
|
||||
|
||||
private List<Feed> getFeeds(Transaction txn) throws DbException {
|
||||
List<Feed> feeds = new ArrayList<Feed>();
|
||||
List<Feed> feeds = new ArrayList<>();
|
||||
Group g = getLocalGroup();
|
||||
try {
|
||||
BdfDictionary d =
|
||||
@@ -300,15 +290,11 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
|
||||
}
|
||||
|
||||
// Fetch and update all feeds
|
||||
List<Feed> newFeeds = new ArrayList<Feed>(feeds.size());
|
||||
List<Feed> newFeeds = new ArrayList<>(feeds.size());
|
||||
for (Feed feed : feeds) {
|
||||
try {
|
||||
newFeeds.add(fetchFeed(feed));
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
newFeeds.add(feed);
|
||||
} catch (DbException e) {
|
||||
} catch (IOException | DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
newFeeds.add(feed);
|
||||
@@ -391,9 +377,7 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
|
||||
SyndFeedInput input = new SyndFeedInput();
|
||||
try {
|
||||
return input.build(new XmlReader(stream));
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new IOException(e);
|
||||
} catch (FeedException e) {
|
||||
} catch (IllegalArgumentException | FeedException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
@@ -479,13 +463,7 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
|
||||
BlogPost post = blogPostFactory
|
||||
.createBlogPost(groupId, time, null, localAuthor, body);
|
||||
blogManager.addLocalPost(txn, post);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
} catch (GeneralSecurityException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
} catch (FormatException e) {
|
||||
} catch (DbException | GeneralSecurityException | FormatException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IllegalArgumentException e) {
|
||||
@@ -502,23 +480,18 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
|
||||
}
|
||||
|
||||
private Comparator<SyndEntry> getEntryComparator() {
|
||||
return new Comparator<SyndEntry>() {
|
||||
@Override
|
||||
public int compare(SyndEntry e1, SyndEntry e2) {
|
||||
Date d1 =
|
||||
e1.getPublishedDate() != null ? e1.getPublishedDate() :
|
||||
e1.getUpdatedDate();
|
||||
Date d2 =
|
||||
e2.getPublishedDate() != null ? e2.getPublishedDate() :
|
||||
e2.getUpdatedDate();
|
||||
if (d1 == null && d2 == null) return 0;
|
||||
if (d1 == null) return -1;
|
||||
if (d2 == null) return 1;
|
||||
return (e1, e2) -> {
|
||||
Date d1 = e1.getPublishedDate() != null ? e1.getPublishedDate() :
|
||||
e1.getUpdatedDate();
|
||||
Date d2 = e2.getPublishedDate() != null ? e2.getPublishedDate() :
|
||||
e2.getUpdatedDate();
|
||||
if (d1 == null && d2 == null) return 0;
|
||||
if (d1 == null) return -1;
|
||||
if (d2 == null) return 1;
|
||||
|
||||
if (d1.after(d2)) return 1;
|
||||
if (d1.before(d2)) return -1;
|
||||
return 0;
|
||||
}
|
||||
if (d1.after(d2)) return 1;
|
||||
if (d1.before(d2)) return -1;
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
||||
this.forumFactory = forumFactory;
|
||||
this.forumPostFactory = forumPostFactory;
|
||||
this.messageTracker = messageTracker;
|
||||
removeHooks = new CopyOnWriteArrayList<RemoveForumHook>();
|
||||
removeHooks = new CopyOnWriteArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -127,16 +127,13 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForumPost createLocalPost(final GroupId groupId, final String body,
|
||||
final long timestamp, final @Nullable MessageId parentId,
|
||||
final LocalAuthor author) {
|
||||
public ForumPost createLocalPost(GroupId groupId, String body,
|
||||
long timestamp, @Nullable MessageId parentId, LocalAuthor author) {
|
||||
ForumPost p;
|
||||
try {
|
||||
p = forumPostFactory.createPost(groupId, timestamp, parentId,
|
||||
author, body);
|
||||
} catch (GeneralSecurityException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (FormatException e) {
|
||||
} catch (GeneralSecurityException | FormatException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return p;
|
||||
@@ -203,7 +200,7 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
List<Forum> forums = new ArrayList<Forum>();
|
||||
List<Forum> forums = new ArrayList<>();
|
||||
for (Group g : groups) forums.add(parseForum(g));
|
||||
return forums;
|
||||
} catch (FormatException e) {
|
||||
@@ -232,13 +229,13 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
||||
public Collection<ForumPostHeader> getPostHeaders(GroupId g)
|
||||
throws DbException {
|
||||
|
||||
Collection<ForumPostHeader> headers = new ArrayList<ForumPostHeader>();
|
||||
Collection<ForumPostHeader> headers = new ArrayList<>();
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
Map<MessageId, BdfDictionary> metadata =
|
||||
clientHelper.getMessageMetadataAsDictionary(txn, g);
|
||||
// get all authors we need to get the status for
|
||||
Set<AuthorId> authors = new HashSet<AuthorId>();
|
||||
Set<AuthorId> authors = new HashSet<>();
|
||||
for (Entry<MessageId, BdfDictionary> entry : metadata.entrySet()) {
|
||||
BdfDictionary d =
|
||||
entry.getValue().getDictionary(KEY_AUTHOR, null);
|
||||
@@ -246,7 +243,7 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
||||
authors.add(new AuthorId(d.getRaw(KEY_ID)));
|
||||
}
|
||||
// get statuses for all authors
|
||||
Map<AuthorId, Status> statuses = new HashMap<AuthorId, Status>();
|
||||
Map<AuthorId, Status> statuses = new HashMap<>();
|
||||
for (AuthorId id : authors) {
|
||||
statuses.put(id, identityManager.getAuthorStatus(txn, id));
|
||||
}
|
||||
@@ -290,8 +287,7 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
||||
|
||||
private ForumPostHeader getForumPostHeader(Transaction txn, MessageId id,
|
||||
BdfDictionary meta) throws DbException, FormatException {
|
||||
return getForumPostHeader(txn, id, meta,
|
||||
Collections.<AuthorId, Status>emptyMap());
|
||||
return getForumPostHeader(txn, id, meta, Collections.emptyMap());
|
||||
}
|
||||
|
||||
private ForumPostHeader getForumPostHeader(Transaction txn, MessageId id,
|
||||
|
||||
@@ -106,7 +106,7 @@ class IntroduceeEngine
|
||||
else return abortSession(currentState, localState);
|
||||
}
|
||||
|
||||
List<BdfDictionary> messages = new ArrayList<BdfDictionary>(1);
|
||||
List<BdfDictionary> messages = new ArrayList<>(1);
|
||||
if (action == LOCAL_ACCEPT || action == LOCAL_DECLINE) {
|
||||
localState.put(STATE, nextState.getValue());
|
||||
localState.put(ANSWERED, true);
|
||||
@@ -136,8 +136,7 @@ class IntroduceeEngine
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
List<Event> events = Collections.emptyList();
|
||||
return new StateUpdate<BdfDictionary, BdfDictionary>(false,
|
||||
false,
|
||||
return new StateUpdate<>(false, false,
|
||||
localState, messages, events);
|
||||
} catch (FormatException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
@@ -204,16 +203,15 @@ class IntroduceeEngine
|
||||
}
|
||||
// we are done (probably declined response), ignore & delete message
|
||||
else if (currentState == FINISHED) {
|
||||
return new StateUpdate<BdfDictionary, BdfDictionary>(true,
|
||||
false, localState,
|
||||
return new StateUpdate<>(true, false, localState,
|
||||
Collections.<BdfDictionary>emptyList(),
|
||||
Collections.<Event>emptyList());
|
||||
Collections.emptyList());
|
||||
}
|
||||
// this should not happen
|
||||
else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return new StateUpdate<BdfDictionary, BdfDictionary>(false, false,
|
||||
return new StateUpdate<>(false, false,
|
||||
localState, messages, events);
|
||||
} catch (FormatException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
@@ -361,15 +359,14 @@ class IntroduceeEngine
|
||||
Event event = new IntroductionAbortedEvent(contactId, sessionId);
|
||||
List<Event> events = Collections.singletonList(event);
|
||||
|
||||
return new StateUpdate<BdfDictionary, BdfDictionary>(false, false,
|
||||
localState, messages, events);
|
||||
return new StateUpdate<>(false, false, localState, messages, events);
|
||||
}
|
||||
|
||||
private StateUpdate<BdfDictionary, BdfDictionary> noUpdate(
|
||||
BdfDictionary localState) throws FormatException {
|
||||
|
||||
return new StateUpdate<BdfDictionary, BdfDictionary>(false, false,
|
||||
localState, Collections.<BdfDictionary>emptyList(),
|
||||
Collections.<Event>emptyList());
|
||||
return new StateUpdate<>(false, false, localState,
|
||||
Collections.<BdfDictionary>emptyList(),
|
||||
Collections.emptyList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,9 +519,7 @@ class IntroduceeManager {
|
||||
try {
|
||||
processStateUpdate(txn, null,
|
||||
engine.onLocalAction(state, localAction));
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
} catch (DbException | IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -539,8 +537,7 @@ class IntroduceeManager {
|
||||
private Map<TransportId, TransportProperties> parseTransportProperties(
|
||||
BdfDictionary d) throws FormatException {
|
||||
|
||||
Map<TransportId, TransportProperties> tpMap =
|
||||
new HashMap<TransportId, TransportProperties>();
|
||||
Map<TransportId, TransportProperties> tpMap = new HashMap<>();
|
||||
BdfDictionary tpMapDict = d.getDictionary(TRANSPORT);
|
||||
for (String key : tpMapDict.keySet()) {
|
||||
TransportId transportId = new TransportId(key);
|
||||
|
||||
@@ -102,7 +102,7 @@ class IntroducerEngine
|
||||
localState.put(STATE, nextState.getValue());
|
||||
if (action == LOCAL_REQUEST) {
|
||||
// create the introduction requests for both contacts
|
||||
List<BdfDictionary> messages = new ArrayList<BdfDictionary>(2);
|
||||
List<BdfDictionary> messages = new ArrayList<>(2);
|
||||
BdfDictionary msg1 = new BdfDictionary();
|
||||
msg1.put(TYPE, TYPE_REQUEST);
|
||||
msg1.put(SESSION_ID, localState.getRaw(SESSION_ID));
|
||||
@@ -129,8 +129,7 @@ class IntroducerEngine
|
||||
logLocalAction(currentState, localState);
|
||||
|
||||
List<Event> events = Collections.emptyList();
|
||||
return new StateUpdate<BdfDictionary, BdfDictionary>(false,
|
||||
false,
|
||||
return new StateUpdate<>(false, false,
|
||||
localState, messages, events);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown Local Action");
|
||||
@@ -206,7 +205,7 @@ class IntroducerEngine
|
||||
} else {
|
||||
throw new IllegalArgumentException("Bad state");
|
||||
}
|
||||
return new StateUpdate<BdfDictionary, BdfDictionary>(false, false,
|
||||
return new StateUpdate<>(false, false,
|
||||
localState, messages, events);
|
||||
} catch (FormatException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
@@ -334,7 +333,7 @@ class IntroducerEngine
|
||||
currentState.name());
|
||||
|
||||
localState.put(STATE, ERROR.getValue());
|
||||
List<BdfDictionary> messages = new ArrayList<BdfDictionary>(2);
|
||||
List<BdfDictionary> messages = new ArrayList<>(2);
|
||||
BdfDictionary msg1 = new BdfDictionary();
|
||||
msg1.put(TYPE, TYPE_ABORT);
|
||||
msg1.put(SESSION_ID, localState.getRaw(SESSION_ID));
|
||||
@@ -347,7 +346,7 @@ class IntroducerEngine
|
||||
messages.add(msg2);
|
||||
|
||||
// send one abort event per contact
|
||||
List<Event> events = new ArrayList<Event>(2);
|
||||
List<Event> events = new ArrayList<>(2);
|
||||
SessionId sessionId = new SessionId(localState.getRaw(SESSION_ID));
|
||||
ContactId contactId1 =
|
||||
new ContactId(localState.getLong(CONTACT_ID_1).intValue());
|
||||
@@ -358,15 +357,14 @@ class IntroducerEngine
|
||||
Event event2 = new IntroductionAbortedEvent(contactId2, sessionId);
|
||||
events.add(event2);
|
||||
|
||||
return new StateUpdate<BdfDictionary, BdfDictionary>(false, false,
|
||||
localState, messages, events);
|
||||
return new StateUpdate<>(false, false, localState, messages, events);
|
||||
}
|
||||
|
||||
private StateUpdate<BdfDictionary, BdfDictionary> noUpdate(
|
||||
BdfDictionary localState) throws FormatException {
|
||||
|
||||
return new StateUpdate<BdfDictionary, BdfDictionary>(false, false,
|
||||
localState, Collections.<BdfDictionary>emptyList(),
|
||||
Collections.<Event>emptyList());
|
||||
return new StateUpdate<>(false, false, localState,
|
||||
Collections.<BdfDictionary>emptyList(),
|
||||
Collections.emptyList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,9 +173,7 @@ class IntroducerManager {
|
||||
try {
|
||||
processStateUpdate(txn,
|
||||
engine.onLocalAction(state, localAction));
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
} catch (DbException | IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,12 +251,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
LOG.warning("Unknown role '" + role + "'");
|
||||
throw new DbException();
|
||||
}
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
if (role == ROLE_INTRODUCER) introducerManager.abort(txn, state);
|
||||
else introduceeManager.abort(txn, state);
|
||||
} catch (FormatException e) {
|
||||
// FIXME necessary?
|
||||
} catch (DbException | FormatException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
if (role == ROLE_INTRODUCER) introducerManager.abort(txn, state);
|
||||
else introduceeManager.abort(txn, state);
|
||||
@@ -277,7 +272,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
|
||||
@Override
|
||||
public void makeIntroduction(Contact c1, Contact c2, @Nullable String msg,
|
||||
final long timestamp) throws DbException, FormatException {
|
||||
long timestamp) throws DbException, FormatException {
|
||||
|
||||
Transaction txn = db.startTransaction(false);
|
||||
try {
|
||||
@@ -293,9 +288,8 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptIntroduction(final ContactId contactId,
|
||||
final SessionId sessionId, final long timestamp)
|
||||
throws DbException, FormatException {
|
||||
public void acceptIntroduction(ContactId contactId, SessionId sessionId,
|
||||
long timestamp) throws DbException, FormatException {
|
||||
|
||||
Transaction txn = db.startTransaction(false);
|
||||
try {
|
||||
@@ -313,9 +307,8 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void declineIntroduction(final ContactId contactId,
|
||||
final SessionId sessionId, final long timestamp)
|
||||
throws DbException, FormatException {
|
||||
public void declineIntroduction(ContactId contactId, SessionId sessionId,
|
||||
long timestamp) throws DbException, FormatException {
|
||||
|
||||
Transaction txn = db.startTransaction(false);
|
||||
try {
|
||||
@@ -336,8 +329,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
public Collection<IntroductionMessage> getIntroductionMessages(
|
||||
ContactId contactId) throws DbException {
|
||||
|
||||
Collection<IntroductionMessage> list =
|
||||
new ArrayList<IntroductionMessage>();
|
||||
Collection<IntroductionMessage> list = new ArrayList<>();
|
||||
|
||||
Map<MessageId, BdfDictionary> metadata;
|
||||
Collection<MessageStatus> statuses;
|
||||
|
||||
@@ -24,7 +24,7 @@ class ConversationManagerImpl implements ConversationManager {
|
||||
@Inject
|
||||
ConversationManagerImpl(DatabaseComponent db) {
|
||||
this.db = db;
|
||||
clients = new CopyOnWriteArraySet<ConversationClient>();
|
||||
clients = new CopyOnWriteArraySet<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -176,8 +176,7 @@ class MessagingManagerImpl extends ConversationClientImpl
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
Collection<PrivateMessageHeader> headers =
|
||||
new ArrayList<PrivateMessageHeader>();
|
||||
Collection<PrivateMessageHeader> headers = new ArrayList<>();
|
||||
for (MessageStatus s : statuses) {
|
||||
MessageId id = s.getMessageId();
|
||||
BdfDictionary meta = metadata.get(id);
|
||||
|
||||
@@ -63,9 +63,7 @@ class GroupMessageFactoryImpl implements GroupMessageFactory {
|
||||
Message m = clientHelper.createMessage(groupId, timestamp, body);
|
||||
|
||||
return new GroupMessage(m, null, member);
|
||||
} catch (GeneralSecurityException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (FormatException e) {
|
||||
} catch (GeneralSecurityException | FormatException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
@@ -91,9 +89,7 @@ class GroupMessageFactoryImpl implements GroupMessageFactory {
|
||||
Message m = clientHelper.createMessage(groupId, timestamp, body);
|
||||
|
||||
return new GroupMessage(m, parentId, author);
|
||||
} catch (GeneralSecurityException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (FormatException e) {
|
||||
} catch (GeneralSecurityException | FormatException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ class GroupMessageValidator extends BdfMessageValidator {
|
||||
|
||||
// The parent post, if any,
|
||||
// and the member's previous message are dependencies
|
||||
Collection<MessageId> dependencies = new ArrayList<MessageId>();
|
||||
Collection<MessageId> dependencies = new ArrayList<>();
|
||||
if (parentId != null) dependencies.add(new MessageId(parentId));
|
||||
dependencies.add(new MessageId(previousMessageId));
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
this.contactManager = contactManager;
|
||||
this.identityManager = identityManager;
|
||||
this.messageTracker = messageTracker;
|
||||
hooks = new CopyOnWriteArrayList<PrivateGroupHook>();
|
||||
hooks = new CopyOnWriteArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -284,7 +284,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
}
|
||||
try {
|
||||
Collection<PrivateGroup> privateGroups =
|
||||
new ArrayList<PrivateGroup>(groups.size());
|
||||
new ArrayList<>(groups.size());
|
||||
for (Group g : groups) {
|
||||
privateGroups.add(privateGroupFactory.parsePrivateGroup(g));
|
||||
}
|
||||
@@ -324,20 +324,19 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
@Override
|
||||
public Collection<GroupMessageHeader> getHeaders(GroupId g)
|
||||
throws DbException {
|
||||
Collection<GroupMessageHeader> headers =
|
||||
new ArrayList<GroupMessageHeader>();
|
||||
Collection<GroupMessageHeader> headers = new ArrayList<>();
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
Map<MessageId, BdfDictionary> metadata =
|
||||
clientHelper.getMessageMetadataAsDictionary(txn, g);
|
||||
// get all authors we need to get the status for
|
||||
Set<AuthorId> authors = new HashSet<AuthorId>();
|
||||
Set<AuthorId> authors = new HashSet<>();
|
||||
for (BdfDictionary meta : metadata.values()) {
|
||||
byte[] idBytes = meta.getRaw(KEY_MEMBER_ID);
|
||||
authors.add(new AuthorId(idBytes));
|
||||
}
|
||||
// get statuses for all authors
|
||||
Map<AuthorId, Status> statuses = new HashMap<AuthorId, Status>();
|
||||
Map<AuthorId, Status> statuses = new HashMap<>();
|
||||
for (AuthorId id : authors) {
|
||||
statuses.put(id, identityManager.getAuthorStatus(txn, id));
|
||||
}
|
||||
@@ -404,7 +403,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
public Collection<GroupMember> getMembers(GroupId g) throws DbException {
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
Collection<GroupMember> members = new ArrayList<GroupMember>();
|
||||
Collection<GroupMember> members = new ArrayList<>();
|
||||
Map<Author, Visibility> authors = getMembers(txn, g);
|
||||
LocalAuthor la = identityManager.getLocalAuthor(txn);
|
||||
PrivateGroup privateGroup = getPrivateGroup(txn, g);
|
||||
@@ -434,8 +433,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
BdfDictionary meta =
|
||||
clientHelper.getGroupMetadataAsDictionary(txn, g);
|
||||
BdfList list = meta.getList(GROUP_KEY_MEMBERS);
|
||||
Map<Author, Visibility> members =
|
||||
new HashMap<Author, Visibility>(list.size());
|
||||
Map<Author, Visibility> members = new HashMap<>(list.size());
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
BdfDictionary d = list.getDictionary(i);
|
||||
Author member = getAuthor(d);
|
||||
@@ -584,7 +582,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
BdfDictionary meta, boolean local)
|
||||
throws DbException, FormatException {
|
||||
GroupMessageHeader header = getGroupMessageHeader(txn, m.getGroupId(),
|
||||
m.getId(), meta, Collections.<AuthorId, Status>emptyMap());
|
||||
m.getId(), meta, Collections.emptyMap());
|
||||
String body = getMessageBody(clientHelper.toList(m));
|
||||
txn.attach(new GroupMessageAddedEvent(m.getGroupId(), header, body,
|
||||
local));
|
||||
@@ -594,7 +592,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
BdfDictionary meta, boolean local, Visibility v)
|
||||
throws DbException, FormatException {
|
||||
JoinMessageHeader header = getJoinMessageHeader(txn, m.getGroupId(),
|
||||
m.getId(), meta, Collections.<AuthorId, Status>emptyMap(), v);
|
||||
m.getId(), meta, Collections.emptyMap(), v);
|
||||
txn.attach(new GroupMessageAddedEvent(m.getGroupId(), header, "",
|
||||
local));
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
BdfDictionary query = messageParser.getMessagesVisibleInUiQuery();
|
||||
Map<MessageId, BdfDictionary> results = clientHelper
|
||||
.getMessageMetadataAsDictionary(txn, contactGroupId, query);
|
||||
messages = new ArrayList<InvitationMessage>(results.size());
|
||||
messages = new ArrayList<>(results.size());
|
||||
for (Entry<MessageId, BdfDictionary> e : results.entrySet()) {
|
||||
MessageId m = e.getKey();
|
||||
MessageMetadata meta =
|
||||
@@ -427,7 +427,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
|
||||
@Override
|
||||
public Collection<GroupInvitationItem> getInvitations() throws DbException {
|
||||
List<GroupInvitationItem> items = new ArrayList<GroupInvitationItem>();
|
||||
List<GroupInvitationItem> items = new ArrayList<>();
|
||||
BdfDictionary query = messageParser.getInvitesAvailableToAnswerQuery();
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
|
||||
@@ -17,10 +17,10 @@ import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import static org.briarproject.briar.sharing.MessageType.INVITE;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_AVAILABLE_TO_ANSWER;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_INVITATION_ACCEPTED;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_LOCAL;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_MESSAGE_TYPE;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_READ;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_INVITATION_ACCEPTED;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_SHAREABLE_ID;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_TIMESTAMP;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_VISIBLE_IN_UI;
|
||||
@@ -91,7 +91,7 @@ abstract class MessageParserImpl<S extends Shareable>
|
||||
BdfList descriptor = body.getList(2);
|
||||
S shareable = createShareable(descriptor);
|
||||
String message = body.getOptionalString(3);
|
||||
return new InviteMessage<S>(m.getId(), previousMessageId,
|
||||
return new InviteMessage<>(m.getId(), previousMessageId,
|
||||
m.getGroupId(), shareable, message, m.getTimestamp());
|
||||
}
|
||||
|
||||
|
||||
@@ -311,7 +311,7 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
BdfDictionary query = messageParser.getMessagesVisibleInUiQuery();
|
||||
Map<MessageId, BdfDictionary> results = clientHelper
|
||||
.getMessageMetadataAsDictionary(txn, contactGroupId, query);
|
||||
messages = new ArrayList<InvitationMessage>(results.size());
|
||||
messages = new ArrayList<>(results.size());
|
||||
for (Entry<MessageId, BdfDictionary> e : results.entrySet()) {
|
||||
MessageId m = e.getKey();
|
||||
MessageMetadata meta =
|
||||
@@ -367,11 +367,9 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
@Override
|
||||
public Collection<SharingInvitationItem> getInvitations()
|
||||
throws DbException {
|
||||
List<SharingInvitationItem> items =
|
||||
new ArrayList<SharingInvitationItem>();
|
||||
List<SharingInvitationItem> items = new ArrayList<>();
|
||||
BdfDictionary query = messageParser.getInvitesAvailableToAnswerQuery();
|
||||
Map<S, Collection<Contact>> sharers =
|
||||
new HashMap<S, Collection<Contact>>();
|
||||
Map<S, Collection<Contact>> sharers = new HashMap<>();
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
// get invitations from each contact
|
||||
@@ -387,7 +385,7 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
if (sharers.containsKey(s)) {
|
||||
sharers.get(s).add(c);
|
||||
} else {
|
||||
Collection<Contact> contacts = new ArrayList<Contact>();
|
||||
Collection<Contact> contacts = new ArrayList<>();
|
||||
contacts.add(c);
|
||||
sharers.put(s, contacts);
|
||||
}
|
||||
@@ -414,7 +412,7 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
@Override
|
||||
public Collection<Contact> getSharedWith(GroupId g) throws DbException {
|
||||
// TODO report also pending invitations
|
||||
Collection<Contact> contacts = new ArrayList<Contact>();
|
||||
Collection<Contact> contacts = new ArrayList<>();
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
for (Contact c : db.getContacts(txn)) {
|
||||
|
||||
@@ -88,8 +88,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
private final Executor ioExecutor;
|
||||
|
||||
private final Random random = new Random();
|
||||
private final Map<Contact, LocalAuthor> localAuthors =
|
||||
new HashMap<Contact, LocalAuthor>();
|
||||
private final Map<Contact, LocalAuthor> localAuthors = new HashMap<>();
|
||||
|
||||
@Inject
|
||||
TestDataCreatorImpl(AuthorFactory authorFactory, Clock clock,
|
||||
@@ -119,16 +118,12 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
}
|
||||
|
||||
public void createTestData() {
|
||||
ioExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
createTestDataOnDbExecutor();
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) {
|
||||
LOG.log(WARNING, "Creating test data failed", e);
|
||||
}
|
||||
}
|
||||
ioExecutor.execute(() -> {
|
||||
try {
|
||||
createTestDataOnDbExecutor();
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, "Creating test data failed", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -146,7 +141,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
}
|
||||
|
||||
private List<Contact> createContacts() throws DbException {
|
||||
List<Contact> contacts = new ArrayList<Contact>(NUM_CONTACTS);
|
||||
List<Contact> contacts = new ArrayList<>(NUM_CONTACTS);
|
||||
LocalAuthor localAuthor = identityManager.getLocalAuthor();
|
||||
for (int i = 0; i < NUM_CONTACTS; i++) {
|
||||
Contact contact = addRandomContact(localAuthor);
|
||||
@@ -206,8 +201,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
}
|
||||
|
||||
private Map<TransportId, TransportProperties> getRandomTransportProperties() {
|
||||
Map<TransportId, TransportProperties> props =
|
||||
new HashMap<TransportId, TransportProperties>();
|
||||
Map<TransportId, TransportProperties> props = new HashMap<>();
|
||||
|
||||
// Bluetooth
|
||||
TransportProperties bt = new TransportProperties();
|
||||
@@ -330,16 +324,14 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
.createBlogPost(blog.getId(), timestamp, null, author,
|
||||
body);
|
||||
blogManager.addLocalPost(blogPost);
|
||||
} catch (FormatException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (GeneralSecurityException e) {
|
||||
} catch (FormatException | GeneralSecurityException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Forum> createForums(List<Contact> contacts)
|
||||
throws DbException {
|
||||
List<Forum> forums = new ArrayList<Forum>(NUM_FORUMS);
|
||||
List<Forum> forums = new ArrayList<>(NUM_FORUMS);
|
||||
for (int i = 0; i < NUM_FORUMS; i++) {
|
||||
// create forum
|
||||
String name = GROUP_NAMES[random.nextInt(GROUP_NAMES.length)];
|
||||
@@ -367,7 +359,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
|
||||
private void createRandomForumPosts(Forum forum, List<Contact> contacts)
|
||||
throws DbException {
|
||||
List<ForumPost> posts = new ArrayList<ForumPost>();
|
||||
List<ForumPost> posts = new ArrayList<>();
|
||||
for (int i = 0; i < NUM_FORUM_POSTS; i++) {
|
||||
Contact contact = contacts.get(random.nextInt(contacts.size()));
|
||||
LocalAuthor author = localAuthors.get(contact);
|
||||
|
||||
@@ -111,7 +111,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testCreateLocalState() throws DbException {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
@@ -127,9 +127,9 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testRemovingContact() throws DbException {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
|
||||
final ContactId contactId = new ContactId(0);
|
||||
ContactId contactId = new ContactId(0);
|
||||
Contact contact = new Contact(contactId, blog2.getAuthor(),
|
||||
blog1.getAuthor().getId(), true, true);
|
||||
|
||||
@@ -149,9 +149,9 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testRemovingContactAfterRemovingBlog() throws DbException {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
|
||||
final ContactId contactId = new ContactId(0);
|
||||
ContactId contactId = new ContactId(0);
|
||||
Contact contact = new Contact(contactId, blog2.getAuthor(),
|
||||
blog1.getAuthor().getId(), true, true);
|
||||
|
||||
@@ -168,7 +168,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testIncomingMessage() throws DbException, FormatException {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
BdfList body = BdfList.of("body");
|
||||
BdfDictionary meta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, POST.getInt()),
|
||||
@@ -207,7 +207,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testIncomingRssMessage() throws DbException, FormatException {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
BdfList body = BdfList.of("body");
|
||||
BdfDictionary meta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, POST.getInt()),
|
||||
@@ -241,7 +241,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testRemoveBlog() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(false);
|
||||
@@ -259,9 +259,9 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testAddLocalPost() throws DbException, FormatException {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final BlogPost post = new BlogPost(message, null, localAuthor1);
|
||||
final BdfDictionary meta = BdfDictionary.of(
|
||||
Transaction txn = new Transaction(null, false);
|
||||
BlogPost post = new BlogPost(message, null, localAuthor1);
|
||||
BdfDictionary meta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, POST.getInt()),
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
new BdfEntry(KEY_AUTHOR, authorDict1),
|
||||
@@ -305,9 +305,9 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testAddLocalRssPost() throws DbException, FormatException {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final BlogPost post = new BlogPost(rssMessage, null, rssLocalAuthor);
|
||||
final BdfDictionary meta = BdfDictionary.of(
|
||||
Transaction txn = new Transaction(null, false);
|
||||
BlogPost post = new BlogPost(rssMessage, null, rssLocalAuthor);
|
||||
BdfDictionary meta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, POST.getInt()),
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
new BdfEntry(KEY_AUTHOR, rssAuthorDict),
|
||||
@@ -350,10 +350,10 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testAddLocalCommentToLocalPost() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
// The post was originally posted to blog 1, then reblogged to the
|
||||
// same blog (commenting on own post)
|
||||
final BdfDictionary postMeta = BdfDictionary.of(
|
||||
BdfDictionary postMeta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, POST.getInt()),
|
||||
new BdfEntry(KEY_RSS_FEED, false),
|
||||
new BdfEntry(KEY_ORIGINAL_MSG_ID, messageId),
|
||||
@@ -361,10 +361,10 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
|
||||
);
|
||||
final MessageId commentId = new MessageId(getRandomId());
|
||||
final Message commentMsg = new Message(commentId, blog1.getId(),
|
||||
MessageId commentId = new MessageId(getRandomId());
|
||||
Message commentMsg = new Message(commentId, blog1.getId(),
|
||||
timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
|
||||
final BdfDictionary commentMeta = BdfDictionary.of(
|
||||
BdfDictionary commentMeta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, COMMENT.getInt()),
|
||||
new BdfEntry(KEY_COMMENT, comment),
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
@@ -436,14 +436,14 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testAddLocalCommentToRemotePost() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
// The post was originally posted to blog 1, then reblogged to
|
||||
// blog 2 with a comment
|
||||
final BdfList originalPostBody = BdfList.of("originalPostBody");
|
||||
final MessageId wrappedPostId = new MessageId(getRandomId());
|
||||
final Message wrappedPostMsg = new Message(wrappedPostId, blog2.getId(),
|
||||
BdfList originalPostBody = BdfList.of("originalPostBody");
|
||||
MessageId wrappedPostId = new MessageId(getRandomId());
|
||||
Message wrappedPostMsg = new Message(wrappedPostId, blog2.getId(),
|
||||
timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
|
||||
final BdfDictionary wrappedPostMeta = BdfDictionary.of(
|
||||
BdfDictionary wrappedPostMeta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
|
||||
new BdfEntry(KEY_RSS_FEED, false),
|
||||
new BdfEntry(KEY_ORIGINAL_MSG_ID, messageId),
|
||||
@@ -451,10 +451,10 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
|
||||
);
|
||||
final MessageId commentId = new MessageId(getRandomId());
|
||||
final Message commentMsg = new Message(commentId, blog2.getId(),
|
||||
MessageId commentId = new MessageId(getRandomId());
|
||||
Message commentMsg = new Message(commentId, blog2.getId(),
|
||||
timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
|
||||
final BdfDictionary commentMeta = BdfDictionary.of(
|
||||
BdfDictionary commentMeta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, COMMENT.getInt()),
|
||||
new BdfEntry(KEY_COMMENT, comment),
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
@@ -539,14 +539,14 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testAddLocalCommentToRemoteRssPost() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
// The post was originally posted to the RSS blog, then reblogged to
|
||||
// blog 1 with a comment
|
||||
final BdfList originalPostBody = BdfList.of("originalPostBody");
|
||||
final MessageId wrappedPostId = new MessageId(getRandomId());
|
||||
final Message wrappedPostMsg = new Message(wrappedPostId, blog1.getId(),
|
||||
BdfList originalPostBody = BdfList.of("originalPostBody");
|
||||
MessageId wrappedPostId = new MessageId(getRandomId());
|
||||
Message wrappedPostMsg = new Message(wrappedPostId, blog1.getId(),
|
||||
timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
|
||||
final BdfDictionary wrappedPostMeta = BdfDictionary.of(
|
||||
BdfDictionary wrappedPostMeta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
|
||||
new BdfEntry(KEY_RSS_FEED, true),
|
||||
new BdfEntry(KEY_ORIGINAL_MSG_ID, rssMessageId),
|
||||
@@ -554,10 +554,10 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
|
||||
);
|
||||
final MessageId commentId = new MessageId(getRandomId());
|
||||
final Message commentMsg = new Message(commentId, blog1.getId(),
|
||||
MessageId commentId = new MessageId(getRandomId());
|
||||
Message commentMsg = new Message(commentId, blog1.getId(),
|
||||
timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
|
||||
final BdfDictionary commentMeta = BdfDictionary.of(
|
||||
BdfDictionary commentMeta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, COMMENT.getInt()),
|
||||
new BdfEntry(KEY_COMMENT, comment),
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
@@ -640,18 +640,18 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testAddLocalCommentToRebloggedRemoteRssPost() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
// The post was originally posted to the RSS blog, then reblogged to
|
||||
// blog 1 with a comment
|
||||
final MessageId wrappedPostId = new MessageId(getRandomId());
|
||||
final BdfList wrappedPostBody = BdfList.of("wrappedPostBody");
|
||||
final MessageId originalCommentId = new MessageId(getRandomId());
|
||||
final BdfList originalCommentBody = BdfList.of("originalCommentBody");
|
||||
MessageId wrappedPostId = new MessageId(getRandomId());
|
||||
BdfList wrappedPostBody = BdfList.of("wrappedPostBody");
|
||||
MessageId originalCommentId = new MessageId(getRandomId());
|
||||
BdfList originalCommentBody = BdfList.of("originalCommentBody");
|
||||
// The post and comment were reblogged to blog 2 with another comment
|
||||
final MessageId rewrappedPostId = new MessageId(getRandomId());
|
||||
final Message rewrappedPostMsg = new Message(rewrappedPostId,
|
||||
MessageId rewrappedPostId = new MessageId(getRandomId());
|
||||
Message rewrappedPostMsg = new Message(rewrappedPostId,
|
||||
blog2.getId(), timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
|
||||
final BdfDictionary rewrappedPostMeta = BdfDictionary.of(
|
||||
BdfDictionary rewrappedPostMeta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
|
||||
new BdfEntry(KEY_RSS_FEED, true),
|
||||
new BdfEntry(KEY_ORIGINAL_MSG_ID, messageId),
|
||||
@@ -659,10 +659,10 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
|
||||
);
|
||||
final MessageId wrappedCommentId = new MessageId(getRandomId());
|
||||
final Message wrappedCommentMsg = new Message(wrappedCommentId,
|
||||
MessageId wrappedCommentId = new MessageId(getRandomId());
|
||||
Message wrappedCommentMsg = new Message(wrappedCommentId,
|
||||
blog2.getId(), timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
|
||||
final BdfDictionary wrappedCommentMeta = BdfDictionary.of(
|
||||
BdfDictionary wrappedCommentMeta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, WRAPPED_COMMENT.getInt()),
|
||||
new BdfEntry(KEY_COMMENT, comment),
|
||||
new BdfEntry(KEY_PARENT_MSG_ID, rewrappedPostId),
|
||||
@@ -671,11 +671,11 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
|
||||
);
|
||||
final String localComment = getRandomString(MAX_BLOG_COMMENT_LENGTH);
|
||||
final MessageId localCommentId = new MessageId(getRandomId());
|
||||
final Message localCommentMsg = new Message(localCommentId,
|
||||
String localComment = getRandomString(MAX_BLOG_COMMENT_LENGTH);
|
||||
MessageId localCommentId = new MessageId(getRandomId());
|
||||
Message localCommentMsg = new Message(localCommentId,
|
||||
blog2.getId(), timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
|
||||
final BdfDictionary localCommentMeta = BdfDictionary.of(
|
||||
BdfDictionary localCommentMeta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, COMMENT.getInt()),
|
||||
new BdfEntry(KEY_COMMENT, localComment),
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
@@ -796,7 +796,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testBlogCanBeRemoved() throws Exception {
|
||||
// check that own personal blogs can not be removed
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(true);
|
||||
will(returnValue(txn));
|
||||
@@ -809,7 +809,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
context.assertIsSatisfied();
|
||||
|
||||
// check that blogs of contacts can be removed
|
||||
final Transaction txn2 = new Transaction(null, true);
|
||||
Transaction txn2 = new Transaction(null, true);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(true);
|
||||
will(returnValue(txn2));
|
||||
|
||||
@@ -126,7 +126,7 @@ public class BlogManagerIntegrationTest
|
||||
@Test
|
||||
public void testBlogPost() throws Exception {
|
||||
// check that blog0 has no posts
|
||||
final String body = getRandomString(42);
|
||||
String body = getRandomString(42);
|
||||
Collection<BlogPostHeader> headers0 =
|
||||
blogManager0.getPostHeaders(blog0.getId());
|
||||
assertEquals(0, headers0.size());
|
||||
@@ -164,7 +164,7 @@ public class BlogManagerIntegrationTest
|
||||
@Test
|
||||
public void testBlogPostInWrongBlog() throws Exception {
|
||||
// add a post to blog1
|
||||
final String body = getRandomString(42);
|
||||
String body = getRandomString(42);
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(blog1.getId(), clock.currentTimeMillis(), null,
|
||||
author0, body);
|
||||
@@ -203,7 +203,7 @@ public class BlogManagerIntegrationTest
|
||||
@Test
|
||||
public void testBlogComment() throws Exception {
|
||||
// add a post to blog0
|
||||
final String body = getRandomString(42);
|
||||
String body = getRandomString(42);
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(blog0.getId(), clock.currentTimeMillis(), null,
|
||||
author0, body);
|
||||
@@ -248,7 +248,7 @@ public class BlogManagerIntegrationTest
|
||||
@Test
|
||||
public void testBlogCommentOnOwnPost() throws Exception {
|
||||
// add a post to blog0
|
||||
final String body = getRandomString(42);
|
||||
String body = getRandomString(42);
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(blog0.getId(), clock.currentTimeMillis(), null,
|
||||
author0, body);
|
||||
@@ -284,7 +284,7 @@ public class BlogManagerIntegrationTest
|
||||
@Test
|
||||
public void testCommentOnComment() throws Exception {
|
||||
// add a post to blog0
|
||||
final String body = getRandomString(42);
|
||||
String body = getRandomString(42);
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(blog0.getId(), clock.currentTimeMillis(), null,
|
||||
author0, body);
|
||||
@@ -372,7 +372,7 @@ public class BlogManagerIntegrationTest
|
||||
@Test
|
||||
public void testCommentOnOwnComment() throws Exception {
|
||||
// add a post to blog0
|
||||
final String body = getRandomString(42);
|
||||
String body = getRandomString(42);
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(blog0.getId(), clock.currentTimeMillis(), null,
|
||||
author0, body);
|
||||
@@ -417,7 +417,7 @@ public class BlogManagerIntegrationTest
|
||||
assertTrue(rssBlog.isRssFeed());
|
||||
|
||||
// add a feed post to rssBlog
|
||||
final String body = getRandomString(42);
|
||||
String body = getRandomString(42);
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(rssBlog.getId(), clock.currentTimeMillis(),
|
||||
null, author0, body);
|
||||
@@ -436,7 +436,7 @@ public class BlogManagerIntegrationTest
|
||||
@Test
|
||||
public void testFeedReblog() throws Exception {
|
||||
// add a feed post to rssBlog
|
||||
final String body = getRandomString(42);
|
||||
String body = getRandomString(42);
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(rssBlog.getId(), clock.currentTimeMillis(),
|
||||
null, author0, body);
|
||||
|
||||
@@ -111,12 +111,12 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
|
||||
private void testValidateProperBlogPost(Blog b, boolean rssFeed)
|
||||
throws IOException, GeneralSecurityException {
|
||||
final byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
BdfList m = BdfList.of(POST.getInt(), body, sigBytes);
|
||||
|
||||
BdfList signed = BdfList.of(b.getId(), message.getTimestamp(), body);
|
||||
expectCrypto(b, SIGNING_LABEL_POST, signed, sigBytes);
|
||||
final BdfDictionary result =
|
||||
BdfDictionary result =
|
||||
validator.validateMessage(message, group, m).getDictionary();
|
||||
|
||||
assertEquals(authorDict, result.getDictionary(KEY_AUTHOR));
|
||||
@@ -150,14 +150,14 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
String comment = "This is a blog comment";
|
||||
MessageId pOriginalId = new MessageId(TestUtils.getRandomId());
|
||||
MessageId currentId = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
BdfList m = BdfList.of(COMMENT.getInt(), comment, pOriginalId,
|
||||
currentId, sigBytes);
|
||||
|
||||
BdfList signed = BdfList.of(blog.getId(), message.getTimestamp(),
|
||||
comment, pOriginalId, currentId);
|
||||
expectCrypto(blog, SIGNING_LABEL_COMMENT, signed, sigBytes);
|
||||
final BdfDictionary result =
|
||||
BdfDictionary result =
|
||||
validator.validateMessage(message, group, m).getDictionary();
|
||||
|
||||
assertEquals(comment, result.getString(KEY_COMMENT));
|
||||
@@ -175,14 +175,14 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
// comment, parent_original_id, signature, parent_current_id
|
||||
MessageId originalId = new MessageId(TestUtils.getRandomId());
|
||||
MessageId currentId = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
BdfList m = BdfList.of(COMMENT.getInt(), null, originalId, currentId,
|
||||
sigBytes);
|
||||
|
||||
BdfList signed = BdfList.of(blog.getId(), message.getTimestamp(), null,
|
||||
originalId, currentId);
|
||||
expectCrypto(blog, SIGNING_LABEL_COMMENT, signed, sigBytes);
|
||||
final BdfDictionary result =
|
||||
BdfDictionary result =
|
||||
validator.validateMessage(message, group, m).getDictionary();
|
||||
|
||||
assertFalse(result.containsKey(KEY_COMMENT));
|
||||
@@ -201,18 +201,18 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
testValidateProperWrappedPost(rssBlog, true);
|
||||
}
|
||||
|
||||
private void testValidateProperWrappedPost(final Blog b, boolean rssFeed)
|
||||
private void testValidateProperWrappedPost(Blog b, boolean rssFeed)
|
||||
throws IOException, GeneralSecurityException {
|
||||
// group descriptor, timestamp, content, signature
|
||||
final byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
BdfList m = BdfList.of(WRAPPED_POST.getInt(), descriptor,
|
||||
message.getTimestamp(), body, sigBytes);
|
||||
|
||||
BdfList signed = BdfList.of(b.getId(), message.getTimestamp(), body);
|
||||
expectCrypto(b, SIGNING_LABEL_POST, signed, sigBytes);
|
||||
|
||||
final BdfList originalList = BdfList.of(POST.getInt(), body, sigBytes);
|
||||
final byte[] originalBody = TestUtils.getRandomBytes(42);
|
||||
BdfList originalList = BdfList.of(POST.getInt(), body, sigBytes);
|
||||
byte[] originalBody = TestUtils.getRandomBytes(42);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(groupFactory).createGroup(clientId, descriptor);
|
||||
@@ -227,7 +227,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
will(returnValue(message));
|
||||
}});
|
||||
|
||||
final BdfDictionary result =
|
||||
BdfDictionary result =
|
||||
validator.validateMessage(message, group, m).getDictionary();
|
||||
|
||||
assertEquals(authorDict, result.getDictionary(KEY_AUTHOR));
|
||||
@@ -243,7 +243,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
String comment = "This is another comment";
|
||||
MessageId originalId = new MessageId(TestUtils.getRandomId());
|
||||
MessageId oldId = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
MessageId currentId = new MessageId(TestUtils.getRandomId());
|
||||
BdfList m = BdfList.of(WRAPPED_COMMENT.getInt(), descriptor,
|
||||
message.getTimestamp(), comment, originalId, oldId, sigBytes,
|
||||
@@ -253,9 +253,9 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
comment, originalId, oldId);
|
||||
expectCrypto(blog, SIGNING_LABEL_COMMENT, signed, sigBytes);
|
||||
|
||||
final BdfList originalList = BdfList.of(COMMENT.getInt(), comment,
|
||||
BdfList originalList = BdfList.of(COMMENT.getInt(), comment,
|
||||
originalId, oldId, sigBytes);
|
||||
final byte[] originalBody = TestUtils.getRandomBytes(42);
|
||||
byte[] originalBody = TestUtils.getRandomBytes(42);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(groupFactory).createGroup(clientId, descriptor);
|
||||
@@ -268,7 +268,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
will(returnValue(message));
|
||||
}});
|
||||
|
||||
final BdfDictionary result =
|
||||
BdfDictionary result =
|
||||
validator.validateMessage(message, group, m).getDictionary();
|
||||
|
||||
assertEquals(comment, result.getString(KEY_COMMENT));
|
||||
@@ -279,8 +279,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
private void expectCrypto(final Blog b, final String label,
|
||||
final BdfList signed, final byte[] sig)
|
||||
private void expectCrypto(Blog b, String label, BdfList signed, byte[] sig)
|
||||
throws IOException, GeneralSecurityException {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(blogFactory).parseBlog(group);
|
||||
|
||||
@@ -54,19 +54,19 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testSendingMessages() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
final QueueMessageFactory queueMessageFactory =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
QueueMessageFactory queueMessageFactory =
|
||||
context.mock(QueueMessageFactory.class);
|
||||
final ValidationManager validationManager =
|
||||
ValidationManager validationManager =
|
||||
context.mock(ValidationManager.class);
|
||||
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final byte[] body = new byte[123];
|
||||
final Metadata groupMetadata = new Metadata();
|
||||
final Metadata messageMetadata = new Metadata();
|
||||
final Metadata groupMetadata1 = new Metadata();
|
||||
final byte[] queueState = new byte[123];
|
||||
Transaction txn = new Transaction(null, false);
|
||||
byte[] body = new byte[123];
|
||||
Metadata groupMetadata = new Metadata();
|
||||
Metadata messageMetadata = new Metadata();
|
||||
Metadata groupMetadata1 = new Metadata();
|
||||
byte[] queueState = new byte[123];
|
||||
groupMetadata1.put(QUEUE_STATE_KEY, queueState);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -123,26 +123,25 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testValidatorRejectsShortMessage() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
final QueueMessageFactory queueMessageFactory =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
QueueMessageFactory queueMessageFactory =
|
||||
context.mock(QueueMessageFactory.class);
|
||||
final ValidationManager validationManager =
|
||||
ValidationManager validationManager =
|
||||
context.mock(ValidationManager.class);
|
||||
|
||||
final AtomicReference<MessageValidator> captured =
|
||||
new AtomicReference<MessageValidator>();
|
||||
final QueueMessageValidator queueMessageValidator =
|
||||
AtomicReference<MessageValidator> captured = new AtomicReference<>();
|
||||
QueueMessageValidator queueMessageValidator =
|
||||
context.mock(QueueMessageValidator.class);
|
||||
// The message is too short to be a valid queue message
|
||||
final MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH - 1];
|
||||
final Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH - 1];
|
||||
Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(validationManager).registerMessageValidator(with(clientId),
|
||||
with(any(MessageValidator.class)));
|
||||
will(new CaptureArgumentAction<MessageValidator>(captured,
|
||||
will(new CaptureArgumentAction<>(captured,
|
||||
MessageValidator.class, 1));
|
||||
}});
|
||||
|
||||
@@ -167,28 +166,27 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testValidatorRejectsNegativeQueuePosition() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
final QueueMessageFactory queueMessageFactory =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
QueueMessageFactory queueMessageFactory =
|
||||
context.mock(QueueMessageFactory.class);
|
||||
final ValidationManager validationManager =
|
||||
ValidationManager validationManager =
|
||||
context.mock(ValidationManager.class);
|
||||
|
||||
final AtomicReference<MessageValidator> captured =
|
||||
new AtomicReference<MessageValidator>();
|
||||
final QueueMessageValidator queueMessageValidator =
|
||||
AtomicReference<MessageValidator> captured = new AtomicReference<>();
|
||||
QueueMessageValidator queueMessageValidator =
|
||||
context.mock(QueueMessageValidator.class);
|
||||
// The message has a negative queue position
|
||||
final MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
for (int i = 0; i < 8; i++)
|
||||
raw[MESSAGE_HEADER_LENGTH + i] = (byte) 0xFF;
|
||||
final Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(validationManager).registerMessageValidator(with(clientId),
|
||||
with(any(MessageValidator.class)));
|
||||
will(new CaptureArgumentAction<MessageValidator>(captured,
|
||||
will(new CaptureArgumentAction<>(captured,
|
||||
MessageValidator.class, 1));
|
||||
}});
|
||||
|
||||
@@ -213,29 +211,28 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testValidatorDelegatesValidMessage() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
final QueueMessageFactory queueMessageFactory =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
QueueMessageFactory queueMessageFactory =
|
||||
context.mock(QueueMessageFactory.class);
|
||||
final ValidationManager validationManager =
|
||||
ValidationManager validationManager =
|
||||
context.mock(ValidationManager.class);
|
||||
|
||||
final AtomicReference<MessageValidator> captured =
|
||||
new AtomicReference<MessageValidator>();
|
||||
final QueueMessageValidator queueMessageValidator =
|
||||
AtomicReference<MessageValidator> captured = new AtomicReference<>();
|
||||
QueueMessageValidator queueMessageValidator =
|
||||
context.mock(QueueMessageValidator.class);
|
||||
final Metadata metadata = new Metadata();
|
||||
final MessageContext messageContext =
|
||||
Metadata metadata = new Metadata();
|
||||
MessageContext messageContext =
|
||||
new MessageContext(metadata);
|
||||
// The message is valid, with a queue position of zero
|
||||
final MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
final Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(validationManager).registerMessageValidator(with(clientId),
|
||||
with(any(MessageValidator.class)));
|
||||
will(new CaptureArgumentAction<MessageValidator>(captured,
|
||||
will(new CaptureArgumentAction<>(captured,
|
||||
MessageValidator.class, 1));
|
||||
// The message should be delegated
|
||||
oneOf(queueMessageValidator).validateMessage(
|
||||
@@ -261,30 +258,29 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
public void testIncomingMessageHookDeletesDuplicateMessage()
|
||||
throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
final QueueMessageFactory queueMessageFactory =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
QueueMessageFactory queueMessageFactory =
|
||||
context.mock(QueueMessageFactory.class);
|
||||
final ValidationManager validationManager =
|
||||
ValidationManager validationManager =
|
||||
context.mock(ValidationManager.class);
|
||||
final AtomicReference<IncomingMessageHook> captured =
|
||||
new AtomicReference<IncomingMessageHook>();
|
||||
final IncomingQueueMessageHook incomingQueueMessageHook =
|
||||
AtomicReference<IncomingMessageHook> captured = new AtomicReference<>();
|
||||
IncomingQueueMessageHook incomingQueueMessageHook =
|
||||
context.mock(IncomingQueueMessageHook.class);
|
||||
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final Metadata groupMetadata = new Metadata();
|
||||
final byte[] queueState = new byte[123];
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Metadata groupMetadata = new Metadata();
|
||||
byte[] queueState = new byte[123];
|
||||
groupMetadata.put(QUEUE_STATE_KEY, queueState);
|
||||
// The message has queue position 0
|
||||
final MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
final Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(validationManager).registerIncomingMessageHook(with(clientId),
|
||||
with(any(IncomingMessageHook.class)));
|
||||
will(new CaptureArgumentAction<IncomingMessageHook>(captured,
|
||||
will(new CaptureArgumentAction<>(captured,
|
||||
IncomingMessageHook.class, 1));
|
||||
oneOf(db).getGroupMetadata(txn, groupId);
|
||||
will(returnValue(groupMetadata));
|
||||
@@ -313,32 +309,31 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
public void testIncomingMessageHookAddsOutOfOrderMessageToPendingList()
|
||||
throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
final QueueMessageFactory queueMessageFactory =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
QueueMessageFactory queueMessageFactory =
|
||||
context.mock(QueueMessageFactory.class);
|
||||
final ValidationManager validationManager =
|
||||
ValidationManager validationManager =
|
||||
context.mock(ValidationManager.class);
|
||||
final AtomicReference<IncomingMessageHook> captured =
|
||||
new AtomicReference<IncomingMessageHook>();
|
||||
final IncomingQueueMessageHook incomingQueueMessageHook =
|
||||
AtomicReference<IncomingMessageHook> captured = new AtomicReference<>();
|
||||
IncomingQueueMessageHook incomingQueueMessageHook =
|
||||
context.mock(IncomingQueueMessageHook.class);
|
||||
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final Metadata groupMetadata = new Metadata();
|
||||
final byte[] queueState = new byte[123];
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Metadata groupMetadata = new Metadata();
|
||||
byte[] queueState = new byte[123];
|
||||
groupMetadata.put(QUEUE_STATE_KEY, queueState);
|
||||
// The message has queue position 1
|
||||
final MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
ByteUtils.writeUint64(1L, raw, MESSAGE_HEADER_LENGTH);
|
||||
final Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
final BdfList pending = BdfList.of(BdfList.of(1L, messageId));
|
||||
Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
BdfList pending = BdfList.of(BdfList.of(1L, messageId));
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(validationManager).registerIncomingMessageHook(with(clientId),
|
||||
with(any(IncomingMessageHook.class)));
|
||||
will(new CaptureArgumentAction<IncomingMessageHook>(captured,
|
||||
will(new CaptureArgumentAction<>(captured,
|
||||
IncomingMessageHook.class, 1));
|
||||
oneOf(db).getGroupMetadata(txn, groupId);
|
||||
will(returnValue(groupMetadata));
|
||||
@@ -369,31 +364,30 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
public void testIncomingMessageHookDelegatesInOrderMessage()
|
||||
throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
final QueueMessageFactory queueMessageFactory =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
QueueMessageFactory queueMessageFactory =
|
||||
context.mock(QueueMessageFactory.class);
|
||||
final ValidationManager validationManager =
|
||||
ValidationManager validationManager =
|
||||
context.mock(ValidationManager.class);
|
||||
final AtomicReference<IncomingMessageHook> captured =
|
||||
new AtomicReference<IncomingMessageHook>();
|
||||
final IncomingQueueMessageHook incomingQueueMessageHook =
|
||||
AtomicReference<IncomingMessageHook> captured = new AtomicReference<>();
|
||||
IncomingQueueMessageHook incomingQueueMessageHook =
|
||||
context.mock(IncomingQueueMessageHook.class);
|
||||
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final Metadata groupMetadata = new Metadata();
|
||||
final byte[] queueState = new byte[123];
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Metadata groupMetadata = new Metadata();
|
||||
byte[] queueState = new byte[123];
|
||||
groupMetadata.put(QUEUE_STATE_KEY, queueState);
|
||||
// The message has queue position 0
|
||||
final MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
final Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
final Metadata messageMetadata = new Metadata();
|
||||
MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
Metadata messageMetadata = new Metadata();
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(validationManager).registerIncomingMessageHook(with(clientId),
|
||||
with(any(IncomingMessageHook.class)));
|
||||
will(new CaptureArgumentAction<IncomingMessageHook>(captured,
|
||||
will(new CaptureArgumentAction<>(captured,
|
||||
IncomingMessageHook.class, 1));
|
||||
oneOf(db).getGroupMetadata(txn, groupId);
|
||||
will(returnValue(groupMetadata));
|
||||
@@ -427,38 +421,37 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
public void testIncomingMessageHookRetrievesPendingMessage()
|
||||
throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
final QueueMessageFactory queueMessageFactory =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
QueueMessageFactory queueMessageFactory =
|
||||
context.mock(QueueMessageFactory.class);
|
||||
final ValidationManager validationManager =
|
||||
ValidationManager validationManager =
|
||||
context.mock(ValidationManager.class);
|
||||
final AtomicReference<IncomingMessageHook> captured =
|
||||
new AtomicReference<IncomingMessageHook>();
|
||||
final IncomingQueueMessageHook incomingQueueMessageHook =
|
||||
AtomicReference<IncomingMessageHook> captured = new AtomicReference<>();
|
||||
IncomingQueueMessageHook incomingQueueMessageHook =
|
||||
context.mock(IncomingQueueMessageHook.class);
|
||||
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final Metadata groupMetadata = new Metadata();
|
||||
final byte[] queueState = new byte[123];
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Metadata groupMetadata = new Metadata();
|
||||
byte[] queueState = new byte[123];
|
||||
groupMetadata.put(QUEUE_STATE_KEY, queueState);
|
||||
// The message has queue position 0
|
||||
final MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
final Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
final Metadata messageMetadata = new Metadata();
|
||||
MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
Metadata messageMetadata = new Metadata();
|
||||
// Queue position 1 is pending
|
||||
final MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] raw1 = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
final QueueMessage message1 = new QueueMessage(messageId1, groupId,
|
||||
MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
||||
byte[] raw1 = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
QueueMessage message1 = new QueueMessage(messageId1, groupId,
|
||||
timestamp, 1L, raw1);
|
||||
final Metadata messageMetadata1 = new Metadata();
|
||||
final BdfList pending = BdfList.of(BdfList.of(1L, messageId1));
|
||||
Metadata messageMetadata1 = new Metadata();
|
||||
BdfList pending = BdfList.of(BdfList.of(1L, messageId1));
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(validationManager).registerIncomingMessageHook(with(clientId),
|
||||
with(any(IncomingMessageHook.class)));
|
||||
will(new CaptureArgumentAction<IncomingMessageHook>(captured,
|
||||
will(new CaptureArgumentAction<>(captured,
|
||||
IncomingMessageHook.class, 1));
|
||||
oneOf(db).getGroupMetadata(txn, groupId);
|
||||
will(returnValue(groupMetadata));
|
||||
|
||||
@@ -19,7 +19,7 @@ public class MessageTreeImplTest {
|
||||
|
||||
@Test
|
||||
public void testMessageTree() {
|
||||
tree = new MessageTreeImpl<TestNode>();
|
||||
tree = new MessageTreeImpl<>();
|
||||
testSimpleTree();
|
||||
tree.clear();
|
||||
testSimpleTree();
|
||||
|
||||
@@ -89,7 +89,7 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testFetchFeedIoException() throws Exception {
|
||||
final BdfDictionary feedDict= new BdfDictionary();
|
||||
BdfDictionary feedDict= new BdfDictionary();
|
||||
BdfList feedList = BdfList.of(feedDict);
|
||||
|
||||
expectGetFeeds(feedList);
|
||||
@@ -104,17 +104,16 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testPostFeedEntriesEmptyDate() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
List<SyndEntry> entries = new ArrayList<SyndEntry>();
|
||||
Transaction txn = new Transaction(null, false);
|
||||
List<SyndEntry> entries = new ArrayList<>();
|
||||
entries.add(new SyndEntryImpl());
|
||||
final SyndEntry entry = new SyndEntryImpl();
|
||||
SyndEntry entry = new SyndEntryImpl();
|
||||
entry.setUpdatedDate(new Date());
|
||||
entries.add(entry);
|
||||
final String body =
|
||||
"<p> (" + entry.getUpdatedDate().toString() + ")</p>";
|
||||
String body = "<p> (" + entry.getUpdatedDate().toString() + ")</p>";
|
||||
Message msg = new Message(new MessageId(getRandomId()), blogGroupId, 0,
|
||||
getRandomBytes(42));
|
||||
final BlogPost post = new BlogPost(msg, null, localAuthor);
|
||||
BlogPost post = new BlogPost(msg, null, localAuthor);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(false);
|
||||
@@ -139,9 +138,9 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
|
||||
}});
|
||||
}
|
||||
|
||||
private void expectGetFeeds(final BdfList feedList) throws Exception {
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
final BdfDictionary feedsDict =
|
||||
private void expectGetFeeds(BdfList feedList) throws Exception {
|
||||
Transaction txn = new Transaction(null, true);
|
||||
BdfDictionary feedsDict =
|
||||
BdfDictionary.of(new BdfEntry(KEY_FEEDS, feedList));
|
||||
expectGetLocalGroup();
|
||||
context.checking(new Expectations() {{
|
||||
@@ -158,8 +157,8 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
|
||||
}});
|
||||
}
|
||||
|
||||
private void expectStoreFeed(final BdfList feedList) throws Exception {
|
||||
final BdfDictionary feedDict =
|
||||
private void expectStoreFeed(BdfList feedList) throws Exception {
|
||||
BdfDictionary feedDict =
|
||||
BdfDictionary.of(new BdfEntry(KEY_FEEDS, feedList));
|
||||
expectGetLocalGroup();
|
||||
context.checking(new Expectations() {{
|
||||
|
||||
@@ -81,10 +81,10 @@ public class ForumManagerTest
|
||||
@Test
|
||||
public void testForumPost() throws Exception {
|
||||
assertEquals(1, forumManager0.getForums().size());
|
||||
final long ms1 = clock.currentTimeMillis() - 1000L;
|
||||
final String body1 = "some forum text";
|
||||
final long ms2 = clock.currentTimeMillis();
|
||||
final String body2 = "some other forum text";
|
||||
long ms1 = clock.currentTimeMillis() - 1000L;
|
||||
String body1 = "some forum text";
|
||||
long ms2 = clock.currentTimeMillis();
|
||||
String body2 = "some other forum text";
|
||||
ForumPost post1 =
|
||||
createForumPost(forum0.getGroup().getId(), null, body1, ms1);
|
||||
assertEquals(ms1, post1.getMessage().getTimestamp());
|
||||
@@ -109,7 +109,7 @@ public class ForumManagerTest
|
||||
forumManager0.getPostHeaders(forum0.getGroup().getId());
|
||||
assertEquals(2, headers.size());
|
||||
for (ForumPostHeader h : headers) {
|
||||
final String hBody = forumManager0.getPostBody(h.getId());
|
||||
String hBody = forumManager0.getPostBody(h.getId());
|
||||
|
||||
boolean isPost1 = h.getId().equals(post1.getMessage().getId());
|
||||
boolean isPost2 = h.getId().equals(post2.getMessage().getId());
|
||||
|
||||
@@ -166,12 +166,12 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
|
||||
|
||||
@Test
|
||||
public void testAcceptsMinLengthAuthorName() throws Exception {
|
||||
final String shortAuthorName = StringUtils.getRandomString(1);
|
||||
String shortAuthorName = StringUtils.getRandomString(1);
|
||||
BdfList shortNameAuthorList =
|
||||
BdfList.of(shortAuthorName, authorPublicKey);
|
||||
final Author shortNameAuthor =
|
||||
Author shortNameAuthor =
|
||||
new Author(authorId, shortAuthorName, authorPublicKey);
|
||||
final BdfList signedWithShortNameAuthor = BdfList.of(groupId, timestamp,
|
||||
BdfList signedWithShortNameAuthor = BdfList.of(groupId, timestamp,
|
||||
parentId.getBytes(), shortNameAuthorList, content);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -259,7 +259,7 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
|
||||
@Test
|
||||
public void testAcceptsMinLengthContent() throws Exception {
|
||||
String shortContent = "";
|
||||
final BdfList signedWithShortContent = BdfList.of(groupId, timestamp,
|
||||
BdfList signedWithShortContent = BdfList.of(groupId, timestamp,
|
||||
parentId.getBytes(), authorList, shortContent);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
|
||||
@@ -174,7 +174,7 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
public void testIncomingRequestMessage()
|
||||
throws DbException, FormatException {
|
||||
|
||||
final BdfDictionary msg = new BdfDictionary();
|
||||
BdfDictionary msg = new BdfDictionary();
|
||||
msg.put(TYPE, TYPE_REQUEST);
|
||||
msg.put(GROUP_ID, introductionGroup1.getId());
|
||||
msg.put(SESSION_ID, sessionId);
|
||||
@@ -183,7 +183,7 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
msg.put(NAME, introducee2.getAuthor().getName());
|
||||
msg.put(PUBLIC_KEY, introducee2.getAuthor().getPublicKey());
|
||||
|
||||
final BdfDictionary state =
|
||||
BdfDictionary state =
|
||||
initializeSessionState(txn, introductionGroup1.getId(), msg);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -201,7 +201,7 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
public void testIncomingResponseMessage()
|
||||
throws DbException, FormatException {
|
||||
|
||||
final BdfDictionary msg = new BdfDictionary();
|
||||
BdfDictionary msg = new BdfDictionary();
|
||||
msg.put(TYPE, TYPE_RESPONSE);
|
||||
msg.put(GROUP_ID, introductionGroup1.getId());
|
||||
msg.put(SESSION_ID, sessionId);
|
||||
@@ -210,7 +210,7 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
msg.put(NAME, introducee2.getAuthor().getName());
|
||||
msg.put(PUBLIC_KEY, introducee2.getAuthor().getPublicKey());
|
||||
|
||||
final BdfDictionary state =
|
||||
BdfDictionary state =
|
||||
initializeSessionState(txn, introductionGroup1.getId(), msg);
|
||||
state.put(STATE, IntroduceeProtocolState.AWAIT_RESPONSES.ordinal());
|
||||
|
||||
@@ -236,7 +236,7 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
throws DbException, FormatException, GeneralSecurityException {
|
||||
|
||||
// TODO MR !237 should use its new default initialization method here
|
||||
final BdfDictionary msg = new BdfDictionary();
|
||||
BdfDictionary msg = new BdfDictionary();
|
||||
msg.put(TYPE, TYPE_RESPONSE);
|
||||
msg.put(GROUP_ID, introductionGroup1.getId());
|
||||
msg.put(SESSION_ID, sessionId);
|
||||
@@ -244,19 +244,19 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
msg.put(MESSAGE_TIME, time);
|
||||
msg.put(NAME, introducee2.getAuthor().getName());
|
||||
msg.put(PUBLIC_KEY, introducee2.getAuthor().getPublicKey());
|
||||
final BdfDictionary state =
|
||||
BdfDictionary state =
|
||||
initializeSessionState(txn, introductionGroup1.getId(), msg);
|
||||
|
||||
// prepare state for incoming ACK
|
||||
state.put(STATE, IntroduceeProtocolState.AWAIT_ACK.ordinal());
|
||||
state.put(ADDED_CONTACT_ID, 2);
|
||||
final byte[] nonce = TestUtils.getRandomBytes(42);
|
||||
byte[] nonce = TestUtils.getRandomBytes(42);
|
||||
state.put(NONCE, nonce);
|
||||
state.put(PUBLIC_KEY, introducee2.getAuthor().getPublicKey());
|
||||
|
||||
// create incoming ACK message
|
||||
final byte[] mac = TestUtils.getRandomBytes(MAC_LENGTH);
|
||||
final byte[] sig = TestUtils.getRandomBytes(MAX_SIGNATURE_LENGTH);
|
||||
byte[] mac = TestUtils.getRandomBytes(MAC_LENGTH);
|
||||
byte[] sig = TestUtils.getRandomBytes(MAX_SIGNATURE_LENGTH);
|
||||
BdfDictionary ack = BdfDictionary.of(
|
||||
new BdfEntry(TYPE, TYPE_ACK),
|
||||
new BdfEntry(SESSION_ID, sessionId),
|
||||
@@ -286,9 +286,9 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
public void testSignatureVerification()
|
||||
throws FormatException, DbException, GeneralSecurityException {
|
||||
|
||||
final byte[] publicKeyBytes = introducee2.getAuthor().getPublicKey();
|
||||
final byte[] nonce = TestUtils.getRandomBytes(MAC_LENGTH);
|
||||
final byte[] sig = TestUtils.getRandomBytes(MAC_LENGTH);
|
||||
byte[] publicKeyBytes = introducee2.getAuthor().getPublicKey();
|
||||
byte[] nonce = TestUtils.getRandomBytes(MAC_LENGTH);
|
||||
byte[] sig = TestUtils.getRandomBytes(MAC_LENGTH);
|
||||
|
||||
BdfDictionary state = new BdfDictionary();
|
||||
state.put(PUBLIC_KEY, publicKeyBytes);
|
||||
@@ -308,12 +308,12 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
public void testMacVerification()
|
||||
throws FormatException, DbException, GeneralSecurityException {
|
||||
|
||||
final byte[] publicKeyBytes = introducee2.getAuthor().getPublicKey();
|
||||
final BdfDictionary tp = BdfDictionary.of(new BdfEntry("fake", "fake"));
|
||||
final byte[] ePublicKeyBytes =
|
||||
byte[] publicKeyBytes = introducee2.getAuthor().getPublicKey();
|
||||
BdfDictionary tp = BdfDictionary.of(new BdfEntry("fake", "fake"));
|
||||
byte[] ePublicKeyBytes =
|
||||
TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
|
||||
final byte[] mac = TestUtils.getRandomBytes(MAC_LENGTH);
|
||||
final SecretKey macKey = TestUtils.getSecretKey();
|
||||
byte[] mac = TestUtils.getRandomBytes(MAC_LENGTH);
|
||||
SecretKey macKey = TestUtils.getSecretKey();
|
||||
|
||||
// move state to where it would be after an ACK arrived
|
||||
BdfDictionary state = new BdfDictionary();
|
||||
@@ -324,7 +324,7 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
state.put(MAC, mac);
|
||||
state.put(MAC_KEY, macKey.getBytes());
|
||||
|
||||
final byte[] signBytes = TestUtils.getRandomBytes(42);
|
||||
byte[] signBytes = TestUtils.getRandomBytes(42);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(clientHelper).toByteArray(
|
||||
BdfList.of(publicKeyBytes, ePublicKeyBytes, tp, time));
|
||||
@@ -356,17 +356,17 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
private BdfDictionary initializeSessionState(final Transaction txn,
|
||||
final GroupId groupId, final BdfDictionary msg)
|
||||
private BdfDictionary initializeSessionState(Transaction txn,
|
||||
GroupId groupId, BdfDictionary msg)
|
||||
throws DbException, FormatException {
|
||||
|
||||
final SecureRandom secureRandom = context.mock(SecureRandom.class);
|
||||
final Bytes salt = new Bytes(new byte[64]);
|
||||
final BdfDictionary groupMetadata = BdfDictionary.of(
|
||||
SecureRandom secureRandom = context.mock(SecureRandom.class);
|
||||
Bytes salt = new Bytes(new byte[64]);
|
||||
BdfDictionary groupMetadata = BdfDictionary.of(
|
||||
new BdfEntry(CONTACT, introducee1.getId().getInt())
|
||||
);
|
||||
final boolean contactExists = false;
|
||||
final BdfDictionary state = new BdfDictionary();
|
||||
boolean contactExists = false;
|
||||
BdfDictionary state = new BdfDictionary();
|
||||
state.put(STORAGE_ID, localStateMessage.getId());
|
||||
state.put(STATE, AWAIT_REQUEST.getValue());
|
||||
state.put(ROLE, ROLE_INTRODUCEE);
|
||||
|
||||
@@ -108,14 +108,14 @@ public class IntroducerManagerTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testMakeIntroduction() throws DbException, FormatException {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final long time = 42L;
|
||||
Transaction txn = new Transaction(null, false);
|
||||
long time = 42L;
|
||||
context.setImposteriser(ClassImposteriser.INSTANCE);
|
||||
final SecureRandom secureRandom = context.mock(SecureRandom.class);
|
||||
final Bytes salt = new Bytes(new byte[64]);
|
||||
final Message msg = new Message(new MessageId(TestUtils.getRandomId()),
|
||||
SecureRandom secureRandom = context.mock(SecureRandom.class);
|
||||
Bytes salt = new Bytes(new byte[64]);
|
||||
Message msg = new Message(new MessageId(TestUtils.getRandomId()),
|
||||
localGroup0.getId(), time, TestUtils.getRandomBytes(64));
|
||||
final BdfDictionary state = new BdfDictionary();
|
||||
BdfDictionary state = new BdfDictionary();
|
||||
state.put(SESSION_ID, msg.getId());
|
||||
state.put(STORAGE_ID, msg.getId());
|
||||
state.put(STATE, PREPARE_REQUESTS.getValue());
|
||||
@@ -128,25 +128,25 @@ public class IntroducerManagerTest extends BriarTestCase {
|
||||
state.put(CONTACT_ID_2, introducee2.getId().getInt());
|
||||
state.put(AUTHOR_ID_1, introducee1.getAuthor().getId());
|
||||
state.put(AUTHOR_ID_2, introducee2.getAuthor().getId());
|
||||
final BdfDictionary state2 = (BdfDictionary) state.clone();
|
||||
BdfDictionary state2 = (BdfDictionary) state.clone();
|
||||
state2.put(STATE, AWAIT_RESPONSES.getValue());
|
||||
|
||||
final BdfDictionary msg1 = new BdfDictionary();
|
||||
BdfDictionary msg1 = new BdfDictionary();
|
||||
msg1.put(TYPE, TYPE_REQUEST);
|
||||
msg1.put(SESSION_ID, state.getRaw(SESSION_ID));
|
||||
msg1.put(GROUP_ID, state.getRaw(GROUP_ID_1));
|
||||
msg1.put(NAME, state.getString(CONTACT_2));
|
||||
msg1.put(PUBLIC_KEY, introducee2.getAuthor().getPublicKey());
|
||||
final BdfDictionary msg1send = (BdfDictionary) msg1.clone();
|
||||
BdfDictionary msg1send = (BdfDictionary) msg1.clone();
|
||||
msg1send.put(MESSAGE_TIME, time);
|
||||
|
||||
final BdfDictionary msg2 = new BdfDictionary();
|
||||
BdfDictionary msg2 = new BdfDictionary();
|
||||
msg2.put(TYPE, TYPE_REQUEST);
|
||||
msg2.put(SESSION_ID, state.getRaw(SESSION_ID));
|
||||
msg2.put(GROUP_ID, state.getRaw(GROUP_ID_2));
|
||||
msg2.put(NAME, state.getString(CONTACT_1));
|
||||
msg2.put(PUBLIC_KEY, introducee1.getAuthor().getPublicKey());
|
||||
final BdfDictionary msg2send = (BdfDictionary) msg2.clone();
|
||||
BdfDictionary msg2send = (BdfDictionary) msg2.clone();
|
||||
msg2send.put(MESSAGE_TIME, time);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
|
||||
@@ -464,7 +464,7 @@ public class IntroductionIntegrationTest
|
||||
assertTrue(listener1.requestReceived);
|
||||
|
||||
// get SessionId
|
||||
List<IntroductionMessage> list = new ArrayList<IntroductionMessage>(
|
||||
List<IntroductionMessage> list = new ArrayList<>(
|
||||
introductionManager1.getIntroductionMessages(contactId0From1));
|
||||
assertEquals(2, list.size());
|
||||
assertTrue(list.get(0) instanceof IntroductionRequest);
|
||||
@@ -706,39 +706,29 @@ public class IntroductionIntegrationTest
|
||||
|
||||
@Test
|
||||
public void testModifiedTransportProperties() throws Exception {
|
||||
testModifiedResponse(new StateVisitor() {
|
||||
@Override
|
||||
public boolean visit(BdfDictionary response) {
|
||||
BdfDictionary tp = response.getDictionary(TRANSPORT, null);
|
||||
tp.put("fakeId",
|
||||
BdfDictionary.of(new BdfEntry("fake", "fake")));
|
||||
response.put(TRANSPORT, tp);
|
||||
return false;
|
||||
}
|
||||
testModifiedResponse(response -> {
|
||||
BdfDictionary tp = response.getDictionary(TRANSPORT, null);
|
||||
tp.put("fakeId", BdfDictionary.of(new BdfEntry("fake", "fake")));
|
||||
response.put(TRANSPORT, tp);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModifiedTimestamp() throws Exception {
|
||||
testModifiedResponse(new StateVisitor() {
|
||||
@Override
|
||||
public boolean visit(BdfDictionary response) {
|
||||
long timestamp = response.getLong(TIME, 0L);
|
||||
response.put(TIME, timestamp + 1);
|
||||
return false;
|
||||
}
|
||||
testModifiedResponse(response -> {
|
||||
long timestamp = response.getLong(TIME, 0L);
|
||||
response.put(TIME, timestamp + 1);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModifiedEphemeralPublicKey() throws Exception {
|
||||
testModifiedResponse(new StateVisitor() {
|
||||
@Override
|
||||
public boolean visit(BdfDictionary response) {
|
||||
KeyPair keyPair = crypto.generateSignatureKeyPair();
|
||||
response.put(E_PUBLIC_KEY, keyPair.getPublic().getEncoded());
|
||||
return true;
|
||||
}
|
||||
testModifiedResponse(response -> {
|
||||
KeyPair keyPair = crypto.generateSignatureKeyPair();
|
||||
response.put(E_PUBLIC_KEY, keyPair.getPublic().getEncoded());
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -934,9 +924,7 @@ public class IntroductionIntegrationTest
|
||||
time);
|
||||
}
|
||||
}
|
||||
} catch (DbException exception) {
|
||||
eventWaiter.rethrow(exception);
|
||||
} catch (FormatException exception) {
|
||||
} catch (DbException | FormatException exception) {
|
||||
eventWaiter.rethrow(exception);
|
||||
} finally {
|
||||
eventWaiter.resume();
|
||||
|
||||
@@ -146,7 +146,7 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testAcceptIntroduction() throws DbException, FormatException {
|
||||
final BdfDictionary state = BdfDictionary.of(
|
||||
BdfDictionary state = BdfDictionary.of(
|
||||
new BdfEntry(GROUP_ID_1, introductionGroup1.getId()),
|
||||
new BdfEntry(GROUP_ID_2, introductionGroup2.getId())
|
||||
);
|
||||
@@ -177,7 +177,7 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testDeclineIntroduction() throws DbException, FormatException {
|
||||
final BdfDictionary state = BdfDictionary.of(
|
||||
BdfDictionary state = BdfDictionary.of(
|
||||
new BdfEntry(GROUP_ID_1, introductionGroup1.getId()),
|
||||
new BdfEntry(GROUP_ID_2, introductionGroup2.getId())
|
||||
);
|
||||
@@ -210,8 +210,8 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
public void testGetIntroductionMessages()
|
||||
throws DbException, FormatException {
|
||||
|
||||
final Map<MessageId, BdfDictionary> metadata = Collections.emptyMap();
|
||||
final Collection<MessageStatus> statuses = Collections.emptyList();
|
||||
Map<MessageId, BdfDictionary> metadata = Collections.emptyMap();
|
||||
Collection<MessageStatus> statuses = Collections.emptyList();
|
||||
txn = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -240,10 +240,10 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
public void testIncomingRequestMessage()
|
||||
throws DbException, FormatException {
|
||||
|
||||
final BdfDictionary msg = new BdfDictionary();
|
||||
BdfDictionary msg = new BdfDictionary();
|
||||
msg.put(TYPE, TYPE_REQUEST);
|
||||
|
||||
final BdfDictionary state = new BdfDictionary();
|
||||
BdfDictionary state = new BdfDictionary();
|
||||
txn = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -267,12 +267,12 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
public void testIncomingResponseMessage()
|
||||
throws DbException, FormatException {
|
||||
|
||||
final BdfDictionary msg = BdfDictionary.of(
|
||||
BdfDictionary msg = BdfDictionary.of(
|
||||
new BdfEntry(TYPE, TYPE_RESPONSE),
|
||||
new BdfEntry(SESSION_ID, sessionId)
|
||||
);
|
||||
|
||||
final BdfDictionary state = new BdfDictionary();
|
||||
BdfDictionary state = new BdfDictionary();
|
||||
state.put(ROLE, ROLE_INTRODUCER);
|
||||
state.put(GROUP_ID_1, introductionGroup1.getId());
|
||||
state.put(GROUP_ID_2, introductionGroup2.getId());
|
||||
|
||||
@@ -83,17 +83,17 @@ public class IntroductionValidatorTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testValidateProperIntroductionRequest() throws IOException {
|
||||
final byte[] sessionId = TestUtils.getRandomId();
|
||||
final String name = StringUtils.getRandomString(MAX_AUTHOR_NAME_LENGTH);
|
||||
final byte[] publicKey =
|
||||
byte[] sessionId = TestUtils.getRandomId();
|
||||
String name = StringUtils.getRandomString(MAX_AUTHOR_NAME_LENGTH);
|
||||
byte[] publicKey =
|
||||
TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
|
||||
final String text =
|
||||
String text =
|
||||
StringUtils.getRandomString(MAX_INTRODUCTION_MESSAGE_LENGTH);
|
||||
|
||||
BdfList body = BdfList.of(TYPE_REQUEST, sessionId,
|
||||
name, publicKey, text);
|
||||
|
||||
final BdfDictionary result =
|
||||
BdfDictionary result =
|
||||
validator.validateMessage(message, group, body)
|
||||
.getDictionary();
|
||||
|
||||
@@ -192,7 +192,7 @@ public class IntroductionValidatorTest extends BriarTestCase {
|
||||
msg.getBoolean(ACCEPT), msg.getLong(TIME),
|
||||
msg.getRaw(E_PUBLIC_KEY), msg.getDictionary(TRANSPORT));
|
||||
|
||||
final BdfDictionary result =
|
||||
BdfDictionary result =
|
||||
validator.validateMessage(message, group, body).getDictionary();
|
||||
|
||||
assertEquals(Long.valueOf(TYPE_RESPONSE), result.getLong(TYPE));
|
||||
|
||||
@@ -58,26 +58,26 @@ public class MessageSenderTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testSendMessage() throws DbException, FormatException {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final Group privateGroup =
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Group privateGroup =
|
||||
new Group(new GroupId(TestUtils.getRandomId()),
|
||||
new ClientId(StringUtils.getRandomString(5)),
|
||||
new byte[0]);
|
||||
final SessionId sessionId = new SessionId(TestUtils.getRandomId());
|
||||
SessionId sessionId = new SessionId(TestUtils.getRandomId());
|
||||
byte[] mac = TestUtils.getRandomBytes(42);
|
||||
byte[] sig = TestUtils.getRandomBytes(MAX_SIGNATURE_LENGTH);
|
||||
final long time = 42L;
|
||||
final BdfDictionary msg = BdfDictionary.of(
|
||||
long time = 42L;
|
||||
BdfDictionary msg = BdfDictionary.of(
|
||||
new BdfEntry(TYPE, TYPE_ACK),
|
||||
new BdfEntry(GROUP_ID, privateGroup.getId()),
|
||||
new BdfEntry(SESSION_ID, sessionId),
|
||||
new BdfEntry(MAC, mac),
|
||||
new BdfEntry(SIGNATURE, sig)
|
||||
);
|
||||
final BdfList bodyList =
|
||||
BdfList bodyList =
|
||||
BdfList.of(TYPE_ACK, sessionId.getBytes(), mac, sig);
|
||||
final byte[] body = TestUtils.getRandomBytes(8);
|
||||
final Metadata metadata = new Metadata();
|
||||
byte[] body = TestUtils.getRandomBytes(8);
|
||||
Metadata metadata = new Metadata();
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(clientHelper).toByteArray(bodyList);
|
||||
|
||||
@@ -172,7 +172,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
|
||||
BdfMessageContext messageContext =
|
||||
validator.validateMessage(message, group, body);
|
||||
assertExpectedMessageContext(messageContext, JOIN, creator,
|
||||
Collections.<MessageId>emptyList());
|
||||
Collections.emptyList());
|
||||
assertTrue(messageContext.getDictionary()
|
||||
.getBoolean(KEY_INITIAL_JOIN_MSG));
|
||||
}
|
||||
@@ -325,12 +325,12 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
|
||||
BdfMessageContext messageContext =
|
||||
validator.validateMessage(message, group, body);
|
||||
assertExpectedMessageContext(messageContext, JOIN, member,
|
||||
Collections.<MessageId>emptyList());
|
||||
Collections.emptyList());
|
||||
assertFalse(messageContext.getDictionary()
|
||||
.getBoolean(KEY_INITIAL_JOIN_MSG));
|
||||
}
|
||||
|
||||
private void expectCreateAuthor(final Author member) {
|
||||
private void expectCreateAuthor(Author member) {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(authorFactory).createAuthor(member.getName(),
|
||||
member.getPublicKey());
|
||||
@@ -345,10 +345,9 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
|
||||
}});
|
||||
}
|
||||
|
||||
private void expectJoinMessage(final Author member, final BdfList invite,
|
||||
final boolean creatorSigValid, final boolean memberSigValid)
|
||||
throws Exception {
|
||||
final BdfList signed = BdfList.of(group.getId(), message.getTimestamp(),
|
||||
private void expectJoinMessage(Author member, BdfList invite,
|
||||
boolean creatorSigValid, boolean memberSigValid) throws Exception {
|
||||
BdfList signed = BdfList.of(group.getId(), message.getTimestamp(),
|
||||
JOIN.getInt(), member.getName(), member.getPublicKey(), invite);
|
||||
expectCreateAuthor(member);
|
||||
expectParsePrivateGroup();
|
||||
@@ -610,9 +609,9 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
|
||||
messageContext.getDictionary().containsKey(KEY_PARENT_MSG_ID));
|
||||
}
|
||||
|
||||
private void expectPostMessage(final Author member,
|
||||
final MessageId parentId, final boolean sigValid) throws Exception {
|
||||
final BdfList signed = BdfList.of(group.getId(), message.getTimestamp(),
|
||||
private void expectPostMessage(Author member, MessageId parentId,
|
||||
boolean sigValid) throws Exception {
|
||||
BdfList signed = BdfList.of(group.getId(), message.getTimestamp(),
|
||||
POST.getInt(), member.getName(), member.getPublicKey(),
|
||||
parentId == null ? null : parentId.getBytes(),
|
||||
previousMsgId.getBytes(), postContent);
|
||||
|
||||
@@ -112,14 +112,14 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
|
||||
assertEquals(inviteTimestamp, s.getInviteTimestamp());
|
||||
}
|
||||
|
||||
protected void expectGetLocalTimestamp(final long time) {
|
||||
protected void expectGetLocalTimestamp(long time) {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(clock).currentTimeMillis();
|
||||
will(returnValue(time));
|
||||
}});
|
||||
}
|
||||
|
||||
protected void expectSendInviteMessage(final String msg)
|
||||
protected void expectSendInviteMessage(String msg)
|
||||
throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageEncoder)
|
||||
@@ -131,7 +131,7 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
|
||||
expectSendMessage(INVITE, true);
|
||||
}
|
||||
|
||||
protected void expectSendJoinMessage(final JoinMessage m, boolean visible)
|
||||
protected void expectSendJoinMessage(JoinMessage m, boolean visible)
|
||||
throws Exception {
|
||||
expectGetLocalTimestamp(messageTimestamp);
|
||||
context.checking(new Expectations() {{
|
||||
@@ -165,8 +165,8 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
|
||||
expectSendMessage(ABORT, false);
|
||||
}
|
||||
|
||||
private void expectSendMessage(final MessageType type,
|
||||
final boolean visible) throws Exception {
|
||||
private void expectSendMessage(MessageType type, boolean visible)
|
||||
throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageEncoder).encodeMetadata(type, privateGroupId,
|
||||
message.getTimestamp(), true, true, visible, false, false);
|
||||
@@ -175,7 +175,7 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
|
||||
}});
|
||||
}
|
||||
|
||||
protected void expectSetPrivateGroupVisibility(final Group.Visibility v)
|
||||
protected void expectSetPrivateGroupVisibility(Group.Visibility v)
|
||||
throws Exception {
|
||||
expectGetContactId();
|
||||
context.checking(new Expectations() {{
|
||||
@@ -184,7 +184,7 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
|
||||
}
|
||||
|
||||
protected void expectGetContactId() throws Exception {
|
||||
final BdfDictionary groupMeta = BdfDictionary
|
||||
BdfDictionary groupMeta = BdfDictionary
|
||||
.of(new BdfEntry(GROUP_KEY_CONTACT_ID, contactId.getInt()));
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(clientHelper)
|
||||
@@ -211,10 +211,9 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
|
||||
}});
|
||||
}
|
||||
|
||||
protected void expectMarkMessageVisibleInUi(final MessageId m,
|
||||
final boolean visible)
|
||||
protected void expectMarkMessageVisibleInUi(MessageId m, boolean visible)
|
||||
throws Exception {
|
||||
final BdfDictionary d = new BdfDictionary();
|
||||
BdfDictionary d = new BdfDictionary();
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageEncoder).setVisibleInUi(d, visible);
|
||||
oneOf(clientHelper).mergeMessageMetadata(txn, m, d);
|
||||
|
||||
@@ -66,7 +66,7 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
assertSessionConstantsUnchanged(session, newSession);
|
||||
}
|
||||
|
||||
private void expectOnLocalInvite(final String msg) throws Exception {
|
||||
private void expectOnLocalInvite(String msg) throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).getGroup(txn, privateGroupId);
|
||||
will(returnValue(privateGroupGroup));
|
||||
|
||||
@@ -159,8 +159,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
groupInvitationManager.createLocalState(txn);
|
||||
}
|
||||
|
||||
private void expectAddingContact(final Contact c,
|
||||
final boolean contactExists) throws Exception {
|
||||
private void expectAddingContact(Contact c, boolean contactExists)
|
||||
throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, c);
|
||||
will(returnValue(contactGroup));
|
||||
@@ -169,7 +169,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
}});
|
||||
if (contactExists) return;
|
||||
|
||||
final BdfDictionary meta = BdfDictionary
|
||||
BdfDictionary meta = BdfDictionary
|
||||
.of(new BdfEntry(GROUP_KEY_CONTACT_ID, c.getId().getInt()));
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).addGroup(txn, contactGroup);
|
||||
@@ -186,8 +186,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
expectAddingMember(privateGroup.getId(), c);
|
||||
}
|
||||
|
||||
private void expectAddingMember(final GroupId g, final Contact c)
|
||||
throws Exception {
|
||||
private void expectAddingMember(GroupId g, Contact c) throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, c);
|
||||
will(returnValue(contactGroup));
|
||||
@@ -214,8 +213,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
}});
|
||||
}
|
||||
|
||||
private void expectStoreSession(final Session session,
|
||||
final MessageId storageId) throws Exception {
|
||||
private void expectStoreSession(Session session, MessageId storageId)
|
||||
throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(sessionEncoder).encodeSession(session);
|
||||
will(returnValue(meta));
|
||||
@@ -223,10 +222,9 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
}});
|
||||
}
|
||||
|
||||
private void expectGetSession(final Map<MessageId, BdfDictionary> results,
|
||||
final SessionId sessionId, final GroupId contactGroupId)
|
||||
throws Exception {
|
||||
final BdfDictionary query = BdfDictionary.of(new BdfEntry("q", "u"));
|
||||
private void expectGetSession(Map<MessageId, BdfDictionary> results,
|
||||
SessionId sessionId, GroupId contactGroupId) throws Exception {
|
||||
BdfDictionary query = BdfDictionary.of(new BdfEntry("q", "u"));
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(sessionParser).getSessionQuery(sessionId);
|
||||
will(returnValue(query));
|
||||
@@ -327,9 +325,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
expectIncomingMessageWithSession(role, type, bdfSession);
|
||||
}
|
||||
|
||||
private void expectIncomingMessageWithSession(final Role role,
|
||||
final MessageType type, final BdfDictionary bdfSession)
|
||||
throws Exception {
|
||||
private void expectIncomingMessageWithSession(Role role, MessageType type,
|
||||
BdfDictionary bdfSession) throws Exception {
|
||||
expectParseMessageMetadata();
|
||||
expectGetSession(oneResult, sessionId, contactGroup.getId());
|
||||
Session session = expectHandleMessage(role, messageMetadata, bdfSession,
|
||||
@@ -339,7 +336,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Nullable
|
||||
private Session expectHandleFirstMessage(Role role,
|
||||
final MessageMetadata messageMetadata, final MessageType type)
|
||||
MessageMetadata messageMetadata, MessageType type)
|
||||
throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageMetadata).getPrivateGroupId();
|
||||
@@ -367,9 +364,9 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Session expectHandleMessage(final Role role,
|
||||
final MessageMetadata messageMetadata, final BdfDictionary state,
|
||||
final MessageType type) throws Exception {
|
||||
private Session expectHandleMessage(Role role,
|
||||
MessageMetadata messageMetadata, BdfDictionary state,
|
||||
MessageType type) throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageMetadata).getMessageType();
|
||||
will(returnValue(type));
|
||||
@@ -405,11 +402,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private <S extends Session> void expectIndividualMessage(
|
||||
final MessageType type, final ProtocolEngine<S> engine,
|
||||
final S session) throws Exception {
|
||||
private <S extends Session> void expectIndividualMessage(MessageType type,
|
||||
ProtocolEngine<S> engine, S session) throws Exception {
|
||||
if (type == INVITE) {
|
||||
final InviteMessage msg = context.mock(InviteMessage.class);
|
||||
InviteMessage msg = context.mock(InviteMessage.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageParser).parseInviteMessage(message, body);
|
||||
will(returnValue(msg));
|
||||
@@ -418,7 +414,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(session));
|
||||
}});
|
||||
} else if (type == JOIN) {
|
||||
final JoinMessage msg = context.mock(JoinMessage.class);
|
||||
JoinMessage msg = context.mock(JoinMessage.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageParser).parseJoinMessage(message, body);
|
||||
will(returnValue(msg));
|
||||
@@ -427,7 +423,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(session));
|
||||
}});
|
||||
} else if (type == LEAVE) {
|
||||
final LeaveMessage msg = context.mock(LeaveMessage.class);
|
||||
LeaveMessage msg = context.mock(LeaveMessage.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageParser).parseLeaveMessage(message, body);
|
||||
will(returnValue(msg));
|
||||
@@ -436,7 +432,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(session));
|
||||
}});
|
||||
} else if (type == ABORT) {
|
||||
final AbortMessage msg = context.mock(AbortMessage.class);
|
||||
AbortMessage msg = context.mock(AbortMessage.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageParser).parseAbortMessage(message, body);
|
||||
will(returnValue(msg));
|
||||
@@ -451,9 +447,9 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testSendFirstInvitation() throws Exception {
|
||||
final String msg = "Invitation text for first invitation";
|
||||
final long time = 42L;
|
||||
final byte[] signature = getRandomBytes(42);
|
||||
String msg = "Invitation text for first invitation";
|
||||
long time = 42L;
|
||||
byte[] signature = getRandomBytes(42);
|
||||
|
||||
expectGetSession(noResults, sessionId, contactGroup.getId());
|
||||
context.checking(new Expectations() {{
|
||||
@@ -482,9 +478,9 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testSendSubsequentInvitation() throws Exception {
|
||||
final String msg = "Invitation text for subsequent invitation";
|
||||
final long time = 43L;
|
||||
final byte[] signature = getRandomBytes(43);
|
||||
String msg = "Invitation text for subsequent invitation";
|
||||
long time = 43L;
|
||||
byte[] signature = getRandomBytes(43);
|
||||
|
||||
expectGetSession(oneResult, sessionId, contactGroup.getId());
|
||||
context.checking(new Expectations() {{
|
||||
@@ -513,7 +509,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testRespondToInvitationWithoutSession() throws Exception {
|
||||
final SessionId sessionId = new SessionId(getRandomId());
|
||||
SessionId sessionId = new SessionId(getRandomId());
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(false);
|
||||
@@ -563,8 +559,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
groupInvitationManager.respondToInvitation(contactId, pg, false);
|
||||
}
|
||||
|
||||
private void expectRespondToInvitation(final SessionId sessionId,
|
||||
final boolean accept) throws Exception {
|
||||
private void expectRespondToInvitation(SessionId sessionId, boolean accept)
|
||||
throws Exception {
|
||||
expectGetSession(oneResult, sessionId, contactGroup.getId());
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(false);
|
||||
@@ -628,25 +624,24 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testGetInvitationMessages() throws Exception {
|
||||
final BdfDictionary query = BdfDictionary.of(new BdfEntry("q", "u"));
|
||||
final MessageId messageId2 = new MessageId(TestUtils.getRandomId());
|
||||
final BdfDictionary meta2 = BdfDictionary.of(new BdfEntry("m2", "e"));
|
||||
final Map<MessageId, BdfDictionary> results =
|
||||
new HashMap<MessageId, BdfDictionary>();
|
||||
BdfDictionary query = BdfDictionary.of(new BdfEntry("q", "u"));
|
||||
MessageId messageId2 = new MessageId(TestUtils.getRandomId());
|
||||
BdfDictionary meta2 = BdfDictionary.of(new BdfEntry("m2", "e"));
|
||||
Map<MessageId, BdfDictionary> results = new HashMap<>();
|
||||
results.put(message.getId(), meta);
|
||||
results.put(messageId2, meta2);
|
||||
final long time1 = 1L, time2 = 2L;
|
||||
final MessageMetadata messageMetadata1 =
|
||||
long time1 = 1L, time2 = 2L;
|
||||
MessageMetadata messageMetadata1 =
|
||||
new MessageMetadata(INVITE, privateGroup.getId(), time1, true,
|
||||
true, true, false, true);
|
||||
final MessageMetadata messageMetadata2 =
|
||||
MessageMetadata messageMetadata2 =
|
||||
new MessageMetadata(JOIN, privateGroup.getId(), time2, true,
|
||||
true, true, true, false);
|
||||
final InviteMessage invite =
|
||||
InviteMessage invite =
|
||||
new InviteMessage(message.getId(), contactGroup.getId(),
|
||||
privateGroup.getId(), time1, "name", author,
|
||||
new byte[0], null, new byte[0]);
|
||||
final PrivateGroup pg =
|
||||
PrivateGroup pg =
|
||||
new PrivateGroup(privateGroup, invite.getGroupName(),
|
||||
invite.getCreator(), invite.getSalt());
|
||||
|
||||
@@ -702,29 +697,27 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testGetInvitations() throws Exception {
|
||||
final BdfDictionary query = BdfDictionary.of(new BdfEntry("q", "u"));
|
||||
final MessageId messageId2 = new MessageId(TestUtils.getRandomId());
|
||||
final BdfDictionary meta2 = BdfDictionary.of(new BdfEntry("m2", "e"));
|
||||
final Map<MessageId, BdfDictionary> results =
|
||||
new HashMap<MessageId, BdfDictionary>();
|
||||
BdfDictionary query = BdfDictionary.of(new BdfEntry("q", "u"));
|
||||
MessageId messageId2 = new MessageId(TestUtils.getRandomId());
|
||||
BdfDictionary meta2 = BdfDictionary.of(new BdfEntry("m2", "e"));
|
||||
Map<MessageId, BdfDictionary> results = new HashMap<>();
|
||||
results.put(message.getId(), meta);
|
||||
results.put(messageId2, meta2);
|
||||
final Message message2 = new Message(messageId2, contactGroup.getId(),
|
||||
Message message2 = new Message(messageId2, contactGroup.getId(),
|
||||
0L, getRandomBytes(MESSAGE_HEADER_LENGTH + 1));
|
||||
long time1 = 1L, time2 = 2L;
|
||||
final String groupName = getRandomString(MAX_GROUP_NAME_LENGTH);
|
||||
final byte[] salt = getRandomBytes(GROUP_SALT_LENGTH);
|
||||
final InviteMessage inviteMessage1 =
|
||||
String groupName = getRandomString(MAX_GROUP_NAME_LENGTH);
|
||||
byte[] salt = getRandomBytes(GROUP_SALT_LENGTH);
|
||||
InviteMessage inviteMessage1 =
|
||||
new InviteMessage(message.getId(), contactGroup.getId(),
|
||||
privateGroup.getId(), time1, groupName, author, salt,
|
||||
null, getRandomBytes(5));
|
||||
final InviteMessage inviteMessage2 =
|
||||
new InviteMessage(message.getId(), contactGroup.getId(),
|
||||
InviteMessage inviteMessage2 =
|
||||
new InviteMessage(message2.getId(), contactGroup.getId(),
|
||||
privateGroup.getId(), time2, groupName, author, salt,
|
||||
null, getRandomBytes(5));
|
||||
final PrivateGroup pg = new PrivateGroup(privateGroup, groupName,
|
||||
PrivateGroup pg = new PrivateGroup(privateGroup, groupName,
|
||||
author, salt);
|
||||
final BdfList body2 = BdfList.of("body2");
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageParser).getInvitesAvailableToAnswerQuery();
|
||||
@@ -796,7 +789,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
.isInvitationAllowed(contact, privateGroup.getId()));
|
||||
}
|
||||
|
||||
private void expectIsInvitationAllowed(final CreatorState state)
|
||||
private void expectIsInvitationAllowed(CreatorState state)
|
||||
throws Exception {
|
||||
expectGetSession(oneResult, sessionId, contactGroup.getId());
|
||||
context.checking(new Expectations() {{
|
||||
@@ -826,23 +819,23 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testRemovingGroupEndsSessions() throws Exception {
|
||||
final Contact contact2 = new Contact(new ContactId(2), author,
|
||||
Contact contact2 = new Contact(new ContactId(2), author,
|
||||
author.getId(), true, true);
|
||||
final Contact contact3 = new Contact(new ContactId(3), author,
|
||||
Contact contact3 = new Contact(new ContactId(3), author,
|
||||
author.getId(), true, true);
|
||||
final Collection<Contact> contacts =
|
||||
Collection<Contact> contacts =
|
||||
Arrays.asList(contact, contact2, contact3);
|
||||
|
||||
final Group contactGroup2 = new Group(new GroupId(getRandomId()),
|
||||
Group contactGroup2 = new Group(new GroupId(getRandomId()),
|
||||
CLIENT_ID, getRandomBytes(5));
|
||||
final Group contactGroup3 = new Group(new GroupId(getRandomId()),
|
||||
Group contactGroup3 = new Group(new GroupId(getRandomId()),
|
||||
CLIENT_ID, getRandomBytes(5));
|
||||
|
||||
final MessageId storageId2 = new MessageId(getRandomId());
|
||||
final MessageId storageId3 = new MessageId(getRandomId());
|
||||
final BdfDictionary bdfSession2 =
|
||||
MessageId storageId2 = new MessageId(getRandomId());
|
||||
MessageId storageId3 = new MessageId(getRandomId());
|
||||
BdfDictionary bdfSession2 =
|
||||
BdfDictionary.of(new BdfEntry("f2", "o"));
|
||||
final BdfDictionary bdfSession3 =
|
||||
BdfDictionary bdfSession3 =
|
||||
BdfDictionary.of(new BdfEntry("f3", "o"));
|
||||
|
||||
expectGetSession(oneResult, sessionId, contactGroup.getId());
|
||||
|
||||
@@ -295,8 +295,8 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
|
||||
assertEquals(meta, messageContext.getDictionary());
|
||||
}
|
||||
|
||||
private void expectInviteMessage(final boolean exception) throws Exception {
|
||||
final BdfList signed = BdfList.of(message.getTimestamp(),
|
||||
private void expectInviteMessage(boolean exception) throws Exception {
|
||||
BdfList signed = BdfList.of(message.getTimestamp(),
|
||||
message.getGroupId(), privateGroup.getId());
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(authorFactory).createAuthor(creatorName, creatorKey);
|
||||
|
||||
@@ -127,13 +127,13 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
|
||||
@Test
|
||||
public void testOnJoinActionFromInvited() throws Exception {
|
||||
final JoinMessage properJoinMessage =
|
||||
JoinMessage properJoinMessage =
|
||||
new JoinMessage(messageId, contactGroupId, privateGroupId,
|
||||
messageTimestamp, lastRemoteMessageId);
|
||||
final long timestamp = 0L;
|
||||
final GroupMessage joinGroupMessage =
|
||||
long timestamp = 0L;
|
||||
GroupMessage joinGroupMessage =
|
||||
new GroupMessage(message, null, localAuthor);
|
||||
final BdfDictionary meta = new BdfDictionary();
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
|
||||
expectMarkMessageAvailableToAnswer(lastRemoteMessageId, false);
|
||||
context.checking(new Expectations() {{
|
||||
@@ -327,7 +327,7 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
Author notCreator =
|
||||
new Author(new AuthorId(getRandomId()), "Not Creator",
|
||||
getRandomBytes(5));
|
||||
final Contact notCreatorContact =
|
||||
Contact notCreatorContact =
|
||||
new Contact(contactId, notCreator, localAuthor.getId(), true,
|
||||
true);
|
||||
|
||||
@@ -346,7 +346,7 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
@Test
|
||||
public void testOnInviteMessageFromStart() throws Exception {
|
||||
InviteeSession session = getDefaultSession(START);
|
||||
final InviteMessage properInviteMessage =
|
||||
InviteMessage properInviteMessage =
|
||||
new InviteMessage(new MessageId(getRandomId()), contactGroupId,
|
||||
privateGroupId, session.getInviteTimestamp() + 1,
|
||||
privateGroup.getName(), privateGroup.getCreator(),
|
||||
@@ -717,9 +717,9 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
|
||||
// helper methods
|
||||
|
||||
private void expectMarkMessageAvailableToAnswer(final MessageId id,
|
||||
final boolean available) throws Exception {
|
||||
final BdfDictionary meta = new BdfDictionary();
|
||||
private void expectMarkMessageAvailableToAnswer(MessageId id,
|
||||
boolean available) throws Exception {
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageEncoder)
|
||||
.setAvailableToAnswer(meta, available);
|
||||
@@ -748,9 +748,9 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
}
|
||||
|
||||
private void expectMarkInvitesUnavailableToAnswer() throws Exception {
|
||||
final BdfDictionary query = BdfDictionary.of(new BdfEntry("query", ""));
|
||||
final BdfDictionary meta = BdfDictionary.of(new BdfEntry("meta", ""));
|
||||
final Map<MessageId, BdfDictionary> invites =
|
||||
BdfDictionary query = BdfDictionary.of(new BdfEntry("query", ""));
|
||||
BdfDictionary meta = BdfDictionary.of(new BdfEntry("meta", ""));
|
||||
Map<MessageId, BdfDictionary> invites =
|
||||
Collections.singletonMap(lastRemoteMessageId, meta);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageParser)
|
||||
|
||||
@@ -660,7 +660,7 @@ public class PeerProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
|
||||
// helper methods
|
||||
|
||||
private void expectRelationshipRevealed(final boolean byContact)
|
||||
private void expectRelationshipRevealed(boolean byContact)
|
||||
throws Exception {
|
||||
expectGetContactId();
|
||||
context.checking(new Expectations() {{
|
||||
|
||||
@@ -146,9 +146,8 @@ public class BlogSharingIntegrationTest
|
||||
assertTrue(blogManager1.getBlogs().contains(blog2));
|
||||
|
||||
// invitee has one invitation message from sharer
|
||||
List<InvitationMessage> list =
|
||||
new ArrayList<InvitationMessage>(blogSharingManager1
|
||||
.getInvitationMessages(contactId0From1));
|
||||
List<InvitationMessage> list = new ArrayList<>(
|
||||
blogSharingManager1.getInvitationMessages(contactId0From1));
|
||||
assertEquals(2, list.size());
|
||||
// check other things are alright with the message
|
||||
for (InvitationMessage m : list) {
|
||||
@@ -222,9 +221,8 @@ public class BlogSharingIntegrationTest
|
||||
assertTrue(blogManager1.getBlogs().contains(rssBlog));
|
||||
|
||||
// invitee has one invitation message from sharer
|
||||
List<InvitationMessage> list =
|
||||
new ArrayList<InvitationMessage>(blogSharingManager1
|
||||
.getInvitationMessages(contactId0From1));
|
||||
List<InvitationMessage> list = new ArrayList<>(
|
||||
blogSharingManager1.getInvitationMessages(contactId0From1));
|
||||
assertEquals(2, list.size());
|
||||
// check other things are alright with the message
|
||||
for (InvitationMessage m : list) {
|
||||
@@ -286,9 +284,8 @@ public class BlogSharingIntegrationTest
|
||||
assertEquals(0, blogSharingManager1.getInvitations().size());
|
||||
|
||||
// invitee has one invitation message from sharer and one response
|
||||
List<InvitationMessage> list =
|
||||
new ArrayList<InvitationMessage>(blogSharingManager1
|
||||
.getInvitationMessages(contactId0From1));
|
||||
List<InvitationMessage> list = new ArrayList<>(
|
||||
blogSharingManager1.getInvitationMessages(contactId0From1));
|
||||
assertEquals(2, list.size());
|
||||
// check things are alright with the message
|
||||
for (InvitationMessage m : list) {
|
||||
|
||||
@@ -94,23 +94,20 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testAddingContactFreshState() throws Exception {
|
||||
Map<MessageId, BdfDictionary> sessions =
|
||||
new HashMap<MessageId, BdfDictionary>(0);
|
||||
Map<MessageId, BdfDictionary> sessions = new HashMap<>(0);
|
||||
testAddingContact(sessions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddingContactExistingState() throws Exception {
|
||||
Map<MessageId, BdfDictionary> sessions =
|
||||
new HashMap<MessageId, BdfDictionary>(1);
|
||||
Map<MessageId, BdfDictionary> sessions = new HashMap<>(1);
|
||||
sessions.put(new MessageId(getRandomId()), new BdfDictionary());
|
||||
testAddingContact(sessions);
|
||||
}
|
||||
|
||||
@Test(expected = DbException.class)
|
||||
public void testAddingContactMultipleSessions() throws Exception {
|
||||
Map<MessageId, BdfDictionary> sessions =
|
||||
new HashMap<MessageId, BdfDictionary>(2);
|
||||
Map<MessageId, BdfDictionary> sessions = new HashMap<>(2);
|
||||
sessions.put(new MessageId(getRandomId()), new BdfDictionary());
|
||||
sessions.put(new MessageId(getRandomId()), new BdfDictionary());
|
||||
testAddingContact(sessions);
|
||||
@@ -118,42 +115,39 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testRemovingBlogFreshState() throws Exception {
|
||||
Map<MessageId, BdfDictionary> sessions =
|
||||
new HashMap<MessageId, BdfDictionary>(0);
|
||||
Map<MessageId, BdfDictionary> sessions = new HashMap<>(0);
|
||||
testRemovingBlog(sessions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemovingBlogExistingState() throws Exception {
|
||||
Map<MessageId, BdfDictionary> sessions =
|
||||
new HashMap<MessageId, BdfDictionary>(1);
|
||||
Map<MessageId, BdfDictionary> sessions = new HashMap<>(1);
|
||||
sessions.put(new MessageId(getRandomId()), new BdfDictionary());
|
||||
testRemovingBlog(sessions);
|
||||
}
|
||||
|
||||
@Test(expected = DbException.class)
|
||||
public void testRemovingBlogMultipleSessions() throws Exception {
|
||||
Map<MessageId, BdfDictionary> sessions =
|
||||
new HashMap<MessageId, BdfDictionary>(2);
|
||||
Map<MessageId, BdfDictionary> sessions = new HashMap<>(2);
|
||||
sessions.put(new MessageId(getRandomId()), new BdfDictionary());
|
||||
sessions.put(new MessageId(getRandomId()), new BdfDictionary());
|
||||
testRemovingBlog(sessions);
|
||||
}
|
||||
|
||||
private void testAddingContact(final Map<MessageId, BdfDictionary> sessions)
|
||||
private void testAddingContact(Map<MessageId, BdfDictionary> sessions)
|
||||
throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final LocalAuthor localAuthor =
|
||||
Transaction txn = new Transaction(null, false);
|
||||
LocalAuthor localAuthor =
|
||||
new LocalAuthor(localAuthorId, "Local Author",
|
||||
getRandomBytes(MAX_PUBLIC_KEY_LENGTH),
|
||||
getRandomBytes(MAX_PUBLIC_KEY_LENGTH),
|
||||
System.currentTimeMillis());
|
||||
final BdfDictionary meta = BdfDictionary
|
||||
BdfDictionary meta = BdfDictionary
|
||||
.of(new BdfEntry(GROUP_KEY_CONTACT_ID, contactId.getInt()));
|
||||
final Group localBlogGroup =
|
||||
Group localBlogGroup =
|
||||
new Group(new GroupId(getRandomId()), BlogManager.CLIENT_ID,
|
||||
getRandomBytes(42));
|
||||
final Blog localBlog = new Blog(localBlogGroup, localAuthor, false);
|
||||
Blog localBlog = new Blog(localBlogGroup, localAuthor, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).getContacts(txn);
|
||||
@@ -180,14 +174,14 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
||||
blogSharingManager.createLocalState(txn);
|
||||
}
|
||||
|
||||
private void expectPreShareShareable(final Transaction txn,
|
||||
final Contact contact, final Blog blog,
|
||||
final Map<MessageId, BdfDictionary> sessions) throws Exception {
|
||||
final Group contactGroup =
|
||||
private void expectPreShareShareable(Transaction txn, Contact contact,
|
||||
Blog blog, Map<MessageId, BdfDictionary> sessions)
|
||||
throws Exception {
|
||||
Group contactGroup =
|
||||
new Group(new GroupId(getRandomId()), CLIENT_ID,
|
||||
getRandomBytes(42));
|
||||
final BdfDictionary sessionDict = new BdfDictionary();
|
||||
final Message message =
|
||||
BdfDictionary sessionDict = new BdfDictionary();
|
||||
Message message =
|
||||
new Message(new MessageId(getRandomId()), contactGroup.getId(),
|
||||
42L, getRandomBytes(1337));
|
||||
context.checking(new Expectations() {{
|
||||
@@ -217,11 +211,11 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
||||
}});
|
||||
}
|
||||
|
||||
private void testRemovingBlog(final Map<MessageId, BdfDictionary> sessions)
|
||||
private void testRemovingBlog(Map<MessageId, BdfDictionary> sessions)
|
||||
throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final BdfDictionary sessionDict = new BdfDictionary();
|
||||
final Session session = new Session(contactGroup.getId(), blog.getId());
|
||||
Transaction txn = new Transaction(null, false);
|
||||
BdfDictionary sessionDict = new BdfDictionary();
|
||||
Session session = new Session(contactGroup.getId(), blog.getId());
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).getContacts(txn);
|
||||
|
||||
@@ -175,7 +175,7 @@ public class BlogSharingValidatorTest extends SharingValidatorTest {
|
||||
invalidContent));
|
||||
}
|
||||
|
||||
private void expectCreateBlog(final String name, final byte[] key) {
|
||||
private void expectCreateBlog(String name, byte[] key) {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(authorFactory).createAuthor(name, key);
|
||||
will(returnValue(author));
|
||||
|
||||
@@ -129,9 +129,8 @@ public class ForumSharingIntegrationTest
|
||||
assertEquals(1, forumManager1.getForums().size());
|
||||
|
||||
// invitee has one invitation message from sharer
|
||||
List<InvitationMessage> list =
|
||||
new ArrayList<InvitationMessage>(forumSharingManager1
|
||||
.getInvitationMessages(contactId0From1));
|
||||
List<InvitationMessage> list = new ArrayList<>(
|
||||
forumSharingManager1.getInvitationMessages(contactId0From1));
|
||||
assertEquals(2, list.size());
|
||||
// check other things are alright with the forum message
|
||||
for (InvitationMessage m : list) {
|
||||
@@ -189,9 +188,8 @@ public class ForumSharingIntegrationTest
|
||||
assertEquals(0, forumSharingManager1.getInvitations().size());
|
||||
|
||||
// invitee has one invitation message from sharer and one response
|
||||
List<InvitationMessage> list =
|
||||
new ArrayList<InvitationMessage>(forumSharingManager1
|
||||
.getInvitationMessages(contactId0From1));
|
||||
List<InvitationMessage> list = new ArrayList<>(
|
||||
forumSharingManager1.getInvitationMessages(contactId0From1));
|
||||
assertEquals(2, list.size());
|
||||
// check things are alright with the forum message
|
||||
for (InvitationMessage m : list) {
|
||||
|
||||
@@ -165,7 +165,7 @@ public class ForumSharingValidatorTest extends SharingValidatorTest {
|
||||
invalidContent));
|
||||
}
|
||||
|
||||
private void expectCreateForum(final String name) {
|
||||
private void expectCreateForum(String name) {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(forumFactory).createForum(name, salt);
|
||||
will(returnValue(forum));
|
||||
|
||||
@@ -143,7 +143,7 @@ public abstract class SharingValidatorTest extends ValidatorTestCase {
|
||||
BdfList.of(ABORT.getValue(), groupId, previousMsgId, 123));
|
||||
}
|
||||
|
||||
protected void expectEncodeMetadata(final MessageType type) {
|
||||
protected void expectEncodeMetadata(MessageType type) {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageEncoder)
|
||||
.encodeMetadata(type, groupId, timestamp, false, false,
|
||||
|
||||
Reference in New Issue
Block a user