X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FAbstractSoneCommandTest.java;h=5c210712e8d490d7c0d5fe1a4b110f178ba88271;hb=ec0589a84453ee2018a5aab6341b90924fde467f;hp=3ac732831eca55458323bbde61a79554b49c4ef7;hpb=959c51e271d7da6566ecd13b912ede0d5e627b3d;p=Sone.git diff --git a/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java index 3ac7328..5c21071 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java @@ -401,11 +401,15 @@ public class AbstractSoneCommandTest { Post post = createPost(sone, null, (long) (Math.random() * Long.MAX_VALUE), "Some Text."); SimpleFieldSet postFieldSet = abstractSoneCommand.encodePost(post, "Post."); assertThat(postFieldSet, notNullValue()); - assertThat(postFieldSet.get("Post.ID"), is(post.getId())); - assertThat(postFieldSet.get("Post.Sone"), is(sone.getId())); - assertThat(postFieldSet.get("Post.Recipient"), nullValue()); - assertThat(postFieldSet.getLong("Post.Time"), is(post.getTime())); - assertThat(postFieldSet.get("Post.Text"), is(post.getText())); + verifyPost(postFieldSet, "Post.", post); + } + + private void verifyPost(SimpleFieldSet postFieldSet, String prefix, Post post) throws FSParseException { + assertThat(postFieldSet.get(prefix + "ID"), is(post.getId())); + assertThat(postFieldSet.get(prefix + "Sone"), is(post.getSone().getId())); + assertThat(postFieldSet.get(prefix + "Recipient"), is(post.getRecipientId().orNull())); + assertThat(postFieldSet.getLong(prefix + "Time"), is(post.getTime())); + assertThat(postFieldSet.get(prefix + "Text"), is(post.getText())); } @Test @@ -414,11 +418,7 @@ public class AbstractSoneCommandTest { Post post = createPost(sone, "KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg", (long) (Math.random() * Long.MAX_VALUE), "Some Text."); SimpleFieldSet postFieldSet = abstractSoneCommand.encodePost(post, "Post."); assertThat(postFieldSet, notNullValue()); - assertThat(postFieldSet.get("Post.ID"), is(post.getId())); - assertThat(postFieldSet.get("Post.Sone"), is(sone.getId())); - assertThat(postFieldSet.get("Post.Recipient"), is("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg")); - assertThat(postFieldSet.getLong("Post.Time"), is(post.getTime())); - assertThat(postFieldSet.get("Post.Text"), is(post.getText())); + verifyPost(postFieldSet, "Post.", post); } @Test @@ -429,11 +429,7 @@ public class AbstractSoneCommandTest { when(post.getReplies()).thenReturn(asList(postReply)); SimpleFieldSet postFieldSet = abstractSoneCommand.encodePostWithReplies(post, "Post."); assertThat(postFieldSet, notNullValue()); - assertThat(postFieldSet.get("Post.ID"), is(post.getId())); - assertThat(postFieldSet.get("Post.Sone"), is(sone.getId())); - assertThat(postFieldSet.get("Post.Recipient"), nullValue()); - assertThat(postFieldSet.getLong("Post.Time"), is(post.getTime())); - assertThat(postFieldSet.get("Post.Text"), is(post.getText())); + verifyPost(postFieldSet, "Post.", post); assertThat(postFieldSet.getInt("Post.Replies.Count"), is(1)); assertThat(postFieldSet.get("Post.Replies.0.ID"), is(postReply.getId())); assertThat(postFieldSet.get("Post.Replies.0.Sone"), is(postReply.getSone().getId())); @@ -449,11 +445,7 @@ public class AbstractSoneCommandTest { when(post.getReplies()).thenReturn(asList(postReply)); SimpleFieldSet postFieldSet = abstractSoneCommand.encodePostWithReplies(post, "Post."); assertThat(postFieldSet, notNullValue()); - assertThat(postFieldSet.get("Post.ID"), is(post.getId())); - assertThat(postFieldSet.get("Post.Sone"), is(sone.getId())); - assertThat(postFieldSet.get("Post.Recipient"), nullValue()); - assertThat(postFieldSet.getLong("Post.Time"), is(post.getTime())); - assertThat(postFieldSet.get("Post.Text"), is(post.getText())); + verifyPost(postFieldSet, "Post.", post); assertThat(postFieldSet.getInt("Post.Replies.Count"), is(0)); assertThat(postFieldSet.get("Post.Replies.0.ID"), nullValue()); assertThat(postFieldSet.get("Post.Replies.0.Sone"), nullValue()); @@ -469,11 +461,7 @@ public class AbstractSoneCommandTest { when(post.getReplies()).thenReturn(asList(postReply)); SimpleFieldSet postFieldSet = abstractSoneCommand.encodePostWithReplies(post, "Post."); assertThat(postFieldSet, notNullValue()); - assertThat(postFieldSet.get("Post.ID"), is(post.getId())); - assertThat(postFieldSet.get("Post.Sone"), is(sone.getId())); - assertThat(postFieldSet.get("Post.Recipient"), is("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg")); - assertThat(postFieldSet.getLong("Post.Time"), is(post.getTime())); - assertThat(postFieldSet.get("Post.Text"), is(post.getText())); + verifyPost(postFieldSet, "Post.", post); assertThat(postFieldSet.getInt("Post.Replies.Count"), is(1)); assertThat(postFieldSet.get("Post.Replies.0.ID"), is(postReply.getId())); assertThat(postFieldSet.get("Post.Replies.0.Sone"), is(postReply.getSone().getId())); @@ -481,4 +469,147 @@ public class AbstractSoneCommandTest { assertThat(postFieldSet.get("Post.Replies.0.Text"), is(postReply.getText())); } + @Test + public void testEncodingPostsWithoutRecipientAndReplies() throws FSParseException { + Sone sone1 = createSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E", "Test1", "Alpha", "A.", "First", (long) (Math.random() * Long.MAX_VALUE)); + Sone sone2 = createSone("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg", "Test2", "Beta", "B.", "Second", (long) (Math.random() * Long.MAX_VALUE)); + Post post1 = createPost(sone1, null, (long) (Math.random() * Long.MAX_VALUE), "Some Text."); + Post post2 = createPost(sone2, null, (long) (Math.random() * Long.MAX_VALUE), "Some other Text."); + SimpleFieldSet postFieldSet = abstractSoneCommand.encodePosts(asList(post1, post2), "Posts."); + assertThat(postFieldSet, notNullValue()); + assertThat(postFieldSet.getInt("Posts.Count"), is(2)); + assertThat(postFieldSet.get("Posts.0.ID"), is(post1.getId())); + assertThat(postFieldSet.get("Posts.0.Sone"), is(sone1.getId())); + assertThat(postFieldSet.get("Posts.0.Recipient"), nullValue()); + assertThat(postFieldSet.getLong("Posts.0.Time"), is(post1.getTime())); + assertThat(postFieldSet.get("Posts.0.Text"), is(post1.getText())); + assertThat(postFieldSet.get("Posts.1.ID"), is(post2.getId())); + assertThat(postFieldSet.get("Posts.1.Sone"), is(sone2.getId())); + assertThat(postFieldSet.get("Posts.1.Recipient"), nullValue()); + assertThat(postFieldSet.getLong("Posts.1.Time"), is(post2.getTime())); + assertThat(postFieldSet.get("Posts.1.Text"), is(post2.getText())); + } + + @Test + public void testEncodingPostsWithRecipientWithoutReplies() throws FSParseException { + Sone sone1 = createSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E", "Test1", "Alpha", "A.", "First", (long) (Math.random() * Long.MAX_VALUE)); + Sone sone2 = createSone("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg", "Test2", "Beta", "B.", "Second", (long) (Math.random() * Long.MAX_VALUE)); + Post post1 = createPost(sone1, "KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg", (long) (Math.random() * Long.MAX_VALUE), "Some Text."); + Post post2 = createPost(sone2, "jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E", (long) (Math.random() * Long.MAX_VALUE), "Some other Text."); + SimpleFieldSet postFieldSet = abstractSoneCommand.encodePosts(asList(post1, post2), "Posts."); + assertThat(postFieldSet, notNullValue()); + assertThat(postFieldSet.getInt("Posts.Count"), is(2)); + assertThat(postFieldSet.get("Posts.0.ID"), is(post1.getId())); + assertThat(postFieldSet.get("Posts.0.Sone"), is(sone1.getId())); + assertThat(postFieldSet.get("Posts.0.Recipient"), is("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg")); + assertThat(postFieldSet.getLong("Posts.0.Time"), is(post1.getTime())); + assertThat(postFieldSet.get("Posts.0.Text"), is(post1.getText())); + assertThat(postFieldSet.get("Posts.1.ID"), is(post2.getId())); + assertThat(postFieldSet.get("Posts.1.Sone"), is(sone2.getId())); + assertThat(postFieldSet.get("Posts.1.Recipient"), is("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E")); + assertThat(postFieldSet.getLong("Posts.1.Time"), is(post2.getTime())); + assertThat(postFieldSet.get("Posts.1.Text"), is(post2.getText())); + } + + @Test + public void testEncodingPostsWithoutRecipientWithReplies() throws FSParseException { + Sone sone1 = createSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E", "Test1", "Alpha", "A.", "First", (long) (Math.random() * Long.MAX_VALUE)); + Sone sone2 = createSone("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg", "Test2", "Beta", "B.", "Second", (long) (Math.random() * Long.MAX_VALUE)); + Post post1 = createPost(sone1, null, (long) (Math.random() * Long.MAX_VALUE), "Some Text."); + Post post2 = createPost(sone2, null, (long) (Math.random() * Long.MAX_VALUE), "Some other Text."); + PostReply postReply1 = createPostReply(sone2, "Reply from 2 to 1"); + PostReply postReply2 = createPostReply(sone1, "Reply from 1 to 2"); + when(post1.getReplies()).thenReturn(asList(postReply1)); + when(post2.getReplies()).thenReturn(asList(postReply2)); + SimpleFieldSet postFieldSet = abstractSoneCommand.encodePostsWithReplies(asList(post1, post2), "Posts."); + assertThat(postFieldSet, notNullValue()); + assertThat(postFieldSet.getInt("Posts.Count"), is(2)); + assertThat(postFieldSet.get("Posts.0.ID"), is(post1.getId())); + assertThat(postFieldSet.get("Posts.0.Sone"), is(sone1.getId())); + assertThat(postFieldSet.get("Posts.0.Recipient"), nullValue()); + assertThat(postFieldSet.getLong("Posts.0.Time"), is(post1.getTime())); + assertThat(postFieldSet.get("Posts.0.Text"), is(post1.getText())); + assertThat(postFieldSet.getInt("Posts.0.Replies.Count"), is(1)); + assertThat(postFieldSet.get("Posts.0.Replies.0.ID"), is(postReply1.getId())); + assertThat(postFieldSet.get("Posts.0.Replies.0.Sone"), is(postReply1.getSone().getId())); + assertThat(postFieldSet.getLong("Posts.0.Replies.0.Time"), is(postReply1.getTime())); + assertThat(postFieldSet.get("Posts.0.Replies.0.Text"), is(postReply1.getText())); + assertThat(postFieldSet.get("Posts.1.ID"), is(post2.getId())); + assertThat(postFieldSet.get("Posts.1.Sone"), is(sone2.getId())); + assertThat(postFieldSet.get("Posts.1.Recipient"), nullValue()); + assertThat(postFieldSet.getLong("Posts.1.Time"), is(post2.getTime())); + assertThat(postFieldSet.get("Posts.1.Text"), is(post2.getText())); + assertThat(postFieldSet.getInt("Posts.1.Replies.Count"), is(1)); + assertThat(postFieldSet.get("Posts.1.Replies.0.ID"), is(postReply2.getId())); + assertThat(postFieldSet.get("Posts.1.Replies.0.Sone"), is(postReply2.getSone().getId())); + assertThat(postFieldSet.getLong("Posts.1.Replies.0.Time"), is(postReply2.getTime())); + assertThat(postFieldSet.get("Posts.1.Replies.0.Text"), is(postReply2.getText())); + } + + @Test + public void testEncodingPostsWithRecipientAndReplies() throws FSParseException { + Sone sone1 = createSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E", "Test1", "Alpha", "A.", "First", (long) (Math.random() * Long.MAX_VALUE)); + Sone sone2 = createSone("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg", "Test2", "Beta", "B.", "Second", (long) (Math.random() * Long.MAX_VALUE)); + Post post1 = createPost(sone1, "KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg", (long) (Math.random() * Long.MAX_VALUE), "Some Text."); + Post post2 = createPost(sone2, "jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E", (long) (Math.random() * Long.MAX_VALUE), "Some other Text."); + PostReply postReply1 = createPostReply(sone2, "Reply from 2 to 1"); + PostReply postReply2 = createPostReply(sone1, "Reply from 1 to 2"); + when(post1.getReplies()).thenReturn(asList(postReply1)); + when(post2.getReplies()).thenReturn(asList(postReply2)); + SimpleFieldSet postFieldSet = abstractSoneCommand.encodePostsWithReplies(asList(post1, post2), "Posts."); + assertThat(postFieldSet, notNullValue()); + assertThat(postFieldSet.getInt("Posts.Count"), is(2)); + assertThat(postFieldSet.get("Posts.0.ID"), is(post1.getId())); + assertThat(postFieldSet.get("Posts.0.Sone"), is(sone1.getId())); + assertThat(postFieldSet.get("Posts.0.Recipient"), is("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg")); + assertThat(postFieldSet.getLong("Posts.0.Time"), is(post1.getTime())); + assertThat(postFieldSet.get("Posts.0.Text"), is(post1.getText())); + assertThat(postFieldSet.getInt("Posts.0.Replies.Count"), is(1)); + assertThat(postFieldSet.get("Posts.0.Replies.0.ID"), is(postReply1.getId())); + assertThat(postFieldSet.get("Posts.0.Replies.0.Sone"), is(postReply1.getSone().getId())); + assertThat(postFieldSet.getLong("Posts.0.Replies.0.Time"), is(postReply1.getTime())); + assertThat(postFieldSet.get("Posts.0.Replies.0.Text"), is(postReply1.getText())); + assertThat(postFieldSet.get("Posts.1.ID"), is(post2.getId())); + assertThat(postFieldSet.get("Posts.1.Sone"), is(sone2.getId())); + assertThat(postFieldSet.get("Posts.1.Recipient"), is("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E")); + assertThat(postFieldSet.getLong("Posts.1.Time"), is(post2.getTime())); + assertThat(postFieldSet.get("Posts.1.Text"), is(post2.getText())); + assertThat(postFieldSet.getInt("Posts.1.Replies.Count"), is(1)); + assertThat(postFieldSet.get("Posts.1.Replies.0.ID"), is(postReply2.getId())); + assertThat(postFieldSet.get("Posts.1.Replies.0.Sone"), is(postReply2.getSone().getId())); + assertThat(postFieldSet.getLong("Posts.1.Replies.0.Time"), is(postReply2.getTime())); + assertThat(postFieldSet.get("Posts.1.Replies.0.Text"), is(postReply2.getText())); + } + + @Test + public void testEncodingPostsWithRecipientAndFutureReplies() throws FSParseException { + Sone sone1 = createSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E", "Test1", "Alpha", "A.", "First", (long) (Math.random() * Long.MAX_VALUE)); + Sone sone2 = createSone("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg", "Test2", "Beta", "B.", "Second", (long) (Math.random() * Long.MAX_VALUE)); + Post post1 = createPost(sone1, "KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg", (long) (Math.random() * Long.MAX_VALUE), "Some Text."); + Post post2 = createPost(sone2, "jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E", (long) (Math.random() * Long.MAX_VALUE), "Some other Text."); + PostReply postReply1 = createPostReply(sone2, "Reply from 2 to 1"); + PostReply postReply2 = createFuturePostReply(sone1, "Reply from 1 to 2"); + when(post1.getReplies()).thenReturn(asList(postReply1)); + when(post2.getReplies()).thenReturn(asList(postReply2)); + SimpleFieldSet postFieldSet = abstractSoneCommand.encodePostsWithReplies(asList(post1, post2), "Posts."); + assertThat(postFieldSet, notNullValue()); + assertThat(postFieldSet.getInt("Posts.Count"), is(2)); + assertThat(postFieldSet.get("Posts.0.ID"), is(post1.getId())); + assertThat(postFieldSet.get("Posts.0.Sone"), is(sone1.getId())); + assertThat(postFieldSet.get("Posts.0.Recipient"), is("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg")); + assertThat(postFieldSet.getLong("Posts.0.Time"), is(post1.getTime())); + assertThat(postFieldSet.get("Posts.0.Text"), is(post1.getText())); + assertThat(postFieldSet.getInt("Posts.0.Replies.Count"), is(1)); + assertThat(postFieldSet.get("Posts.0.Replies.0.ID"), is(postReply1.getId())); + assertThat(postFieldSet.get("Posts.0.Replies.0.Sone"), is(postReply1.getSone().getId())); + assertThat(postFieldSet.getLong("Posts.0.Replies.0.Time"), is(postReply1.getTime())); + assertThat(postFieldSet.get("Posts.0.Replies.0.Text"), is(postReply1.getText())); + assertThat(postFieldSet.get("Posts.1.ID"), is(post2.getId())); + assertThat(postFieldSet.get("Posts.1.Sone"), is(sone2.getId())); + assertThat(postFieldSet.get("Posts.1.Recipient"), is("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E")); + assertThat(postFieldSet.getLong("Posts.1.Time"), is(post2.getTime())); + assertThat(postFieldSet.get("Posts.1.Text"), is(post2.getText())); + assertThat(postFieldSet.getInt("Posts.1.Replies.Count"), is(0)); + } + }