2 * Sone - AbstractSoneCommandTest.java - Copyright © 2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.fcp;
20 import static com.google.common.base.Optional.of;
21 import static java.lang.System.currentTimeMillis;
22 import static java.util.Arrays.asList;
23 import static java.util.UUID.randomUUID;
24 import static java.util.concurrent.TimeUnit.DAYS;
25 import static net.pterodactylus.sone.fcp.AbstractSoneCommand.encodeSone;
26 import static net.pterodactylus.sone.fcp.AbstractSoneCommand.encodeString;
27 import static net.pterodactylus.sone.fcp.Verifiers.verifyPostWithReplies;
28 import static net.pterodactylus.sone.fcp.Verifiers.verifyPosts;
29 import static net.pterodactylus.sone.fcp.Verifiers.verifyPostsWithReplies;
30 import static net.pterodactylus.sone.template.SoneAccessor.getNiceName;
31 import static org.hamcrest.CoreMatchers.is;
32 import static org.hamcrest.CoreMatchers.notNullValue;
33 import static org.hamcrest.CoreMatchers.nullValue;
34 import static org.hamcrest.MatcherAssert.assertThat;
35 import static org.mockito.Mockito.mock;
36 import static org.mockito.Mockito.when;
38 import java.util.List;
40 import net.pterodactylus.sone.data.Mocks;
41 import net.pterodactylus.sone.data.Post;
42 import net.pterodactylus.sone.data.PostReply;
43 import net.pterodactylus.sone.data.Sone;
44 import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
45 import net.pterodactylus.sone.freenet.fcp.FcpException;
47 import freenet.node.FSParseException;
48 import freenet.support.SimpleFieldSet;
49 import freenet.support.api.Bucket;
51 import com.google.common.base.Optional;
52 import org.junit.Test;
53 import org.mockito.Matchers;
56 * Unit test for {@link AbstractSoneCommand}.
58 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
60 public class AbstractSoneCommandTest {
62 private final Mocks mocks = new Mocks();
63 private final AbstractSoneCommand abstractSoneCommand = new AbstractSoneCommand(mocks.core) {
65 public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
71 public void testStringEncoding() {
72 String testString = prepareStringToBeEncoded();
74 String encodedString = encodeString(testString);
75 assertThat(encodedString, notNullValue());
76 assertThat(encodedString.length(), is(testString.length() + 3));
79 private String prepareStringToBeEncoded() {
80 StringBuilder testString = new StringBuilder();
81 for (int i = 0; i < 4000; ++i) {
82 testString.append((char) i);
84 return testString.toString();
88 public void testEncodingASone() throws FSParseException {
89 Sone sone = mocks.mockSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withName("test").withProfileName("First", "M.", "Last").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
90 SimpleFieldSet soneFieldSet = encodeSone(sone, "Prefix.", Optional.<Sone>absent());
91 assertThat(soneFieldSet, notNullValue());
92 assertThat(soneFieldSet.get("Prefix.Name"), is("test"));
93 assertThat(soneFieldSet.get("Prefix.NiceName"), is("First M. Last"));
94 assertThat(soneFieldSet.getLong("Prefix.LastUpdated"), is(sone.getTime()));
95 assertThat(soneFieldSet.get("Prefix.Followed"), nullValue());
96 assertThat(soneFieldSet.getInt("Prefix.Field.Count"), is(1));
97 assertThat(soneFieldSet.get("Prefix.Field.0.Name"), is("Test1"));
98 assertThat(soneFieldSet.get("Prefix.Field.0.Value"), is("Value1"));
102 public void testEncodingAFollowedSone() throws FSParseException {
103 Sone sone = mocks.mockSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withName("test").withProfileName("First", "M.", "Last").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
104 Sone localSone = prepareLocalSoneThatFollowsEverybody();
105 SimpleFieldSet soneFieldSet = encodeSone(sone, "Prefix.", of(localSone));
106 assertThat(soneFieldSet, notNullValue());
107 assertThat(soneFieldSet.get("Prefix.Name"), is("test"));
108 assertThat(soneFieldSet.get("Prefix.NiceName"), is("First M. Last"));
109 assertThat(soneFieldSet.getLong("Prefix.LastUpdated"), is(sone.getTime()));
110 assertThat(soneFieldSet.get("Prefix.Followed"), is("true"));
111 assertThat(soneFieldSet.getInt("Prefix.Field.Count"), is(1));
112 assertThat(soneFieldSet.get("Prefix.Field.0.Name"), is("Test1"));
113 assertThat(soneFieldSet.get("Prefix.Field.0.Value"), is("Value1"));
117 public void testEncodingANotFollowedSone() throws FSParseException {
118 Sone sone = mocks.mockSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withName("test").withProfileName("First", "M.", "Last").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
119 Sone localSone = prepareLocalSoneThatFollowsNobody();
120 SimpleFieldSet soneFieldSet = encodeSone(sone, "Prefix.", of(localSone));
121 assertThat(soneFieldSet, notNullValue());
122 assertThat(soneFieldSet.get("Prefix.Name"), is("test"));
123 assertThat(soneFieldSet.get("Prefix.NiceName"), is("First M. Last"));
124 assertThat(soneFieldSet.getLong("Prefix.LastUpdated"), is(sone.getTime()));
125 assertThat(soneFieldSet.get("Prefix.Followed"), is("false"));
126 assertThat(soneFieldSet.getInt("Prefix.Field.Count"), is(1));
127 assertThat(soneFieldSet.get("Prefix.Field.0.Name"), is("Test1"));
128 assertThat(soneFieldSet.get("Prefix.Field.0.Value"), is("Value1"));
131 private Sone prepareLocalSoneThatFollowsEverybody() {
132 Sone sone = mock(Sone.class);
133 when(sone.hasFriend(Matchers.<String>any())).thenReturn(true);
137 private Sone prepareLocalSoneThatFollowsNobody() {
138 Sone sone = mock(Sone.class);
139 when(sone.hasFriend(Matchers.<String>any())).thenReturn(false);
144 public void testEncodingMultipleSones() throws FSParseException {
145 List<Sone> sones = prepareMultipleSones();
146 SimpleFieldSet sonesFieldSet = AbstractSoneCommand.encodeSones(sones, "Prefix.");
147 assertThat(sonesFieldSet, notNullValue());
148 assertThat(sonesFieldSet.getInt("Prefix.Count"), is(sones.size()));
149 assertThat(sonesFieldSet.get("Prefix.0.ID"), is(sones.get(0).getId()));
150 assertThat(sonesFieldSet.get("Prefix.0.Name"), is(sones.get(0).getName()));
151 assertThat(sonesFieldSet.get("Prefix.0.NiceName"), is(getNiceName(sones.get(0))));
152 assertThat(sonesFieldSet.getLong("Prefix.0.Time"), is(sones.get(0).getTime()));
153 assertThat(sonesFieldSet.get("Prefix.1.ID"), is(sones.get(1).getId()));
154 assertThat(sonesFieldSet.get("Prefix.1.Name"), is(sones.get(1).getName()));
155 assertThat(sonesFieldSet.get("Prefix.1.NiceName"), is(getNiceName(sones.get(1))));
156 assertThat(sonesFieldSet.getLong("Prefix.1.Time"), is(sones.get(1).getTime()));
157 assertThat(sonesFieldSet.get("Prefix.2.ID"), is(sones.get(2).getId()));
158 assertThat(sonesFieldSet.get("Prefix.2.Name"), is(sones.get(2).getName()));
159 assertThat(sonesFieldSet.get("Prefix.2.NiceName"), is(getNiceName(sones.get(2))));
160 assertThat(sonesFieldSet.getLong("Prefix.2.Time"), is(sones.get(2).getTime()));
163 private List<Sone> prepareMultipleSones() {
164 Sone sone1 = mocks.mockSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withName("Test1").withProfileName("Alpha", "A.", "First").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
165 Sone sone2 = mocks.mockSone("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg").withName("Test2").withProfileName("Beta", "B.", "Second").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
166 Sone sone3 = mocks.mockSone("-1Q6LhHvx91C1mSjOS3zznRSNUC4OxoHUbhIgBAyW1U").withName("Test3").withProfileName("Gamma", "C.", "Third").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
167 return asList(sone1, sone2, sone3);
171 public void testEncodingReplies() throws FSParseException {
172 List<PostReply> postReplies = preparePostReplies();
173 SimpleFieldSet postRepliesFieldSet = AbstractSoneCommand.encodeReplies(postReplies, "Prefix.");
174 assertThat(postRepliesFieldSet, notNullValue());
175 assertThat(postRepliesFieldSet.getInt("Prefix.Replies.Count"), is(postReplies.size()));
176 assertThat(postRepliesFieldSet.get("Prefix.Replies.0.ID"), is(postReplies.get(0).getId()));
177 assertThat(postRepliesFieldSet.get("Prefix.Replies.0.Sone"), is(postReplies.get(0).getSone().getId()));
178 assertThat(postRepliesFieldSet.getLong("Prefix.Replies.0.Time"), is(postReplies.get(0).getTime()));
179 assertThat(postRepliesFieldSet.get("Prefix.Replies.0.Text"), is(postReplies.get(0).getText()));
180 assertThat(postRepliesFieldSet.get("Prefix.Replies.1.ID"), is(postReplies.get(1).getId()));
181 assertThat(postRepliesFieldSet.get("Prefix.Replies.1.Sone"), is(postReplies.get(1).getSone().getId()));
182 assertThat(postRepliesFieldSet.getLong("Prefix.Replies.1.Time"), is(postReplies.get(1).getTime()));
183 assertThat(postRepliesFieldSet.get("Prefix.Replies.1.Text"), is(postReplies.get(1).getText()));
184 assertThat(postRepliesFieldSet.get("Prefix.Replies.2.ID"), is(postReplies.get(2).getId()));
185 assertThat(postRepliesFieldSet.get("Prefix.Replies.2.Sone"), is(postReplies.get(2).getSone().getId()));
186 assertThat(postRepliesFieldSet.getLong("Prefix.Replies.2.Time"), is(postReplies.get(2).getTime()));
187 assertThat(postRepliesFieldSet.get("Prefix.Replies.2.Text"), is(postReplies.get(2).getText()));
190 private List<PostReply> preparePostReplies() {
191 Sone sone1 = mocks.mockSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withName("Test1").withProfileName("Alpha", "A.", "First").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
192 Sone sone2 = mocks.mockSone("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg").withName("Test2").withProfileName("Beta", "B.", "Second").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
193 Sone sone3 = mocks.mockSone("-1Q6LhHvx91C1mSjOS3zznRSNUC4OxoHUbhIgBAyW1U").withName("Test3").withProfileName("Gamma", "C.", "Third").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
194 PostReply postReply1 = mocks.mockPostReply(sone1, randomUUID().toString()).withTime(currentTimeMillis()).withText("Text 1").create();
195 PostReply postReply2 = mocks.mockPostReply(sone2, randomUUID().toString()).withTime(currentTimeMillis()).withText("Text 2").create();
196 PostReply postReply3 = mocks.mockPostReply(sone3, randomUUID().toString()).withTime(currentTimeMillis()).withText("Text 3").create();
197 return asList(postReply1, postReply2, postReply3);
201 public void testEncodingLikes() throws FSParseException {
202 List<Sone> likes = prepareMultipleSones();
203 SimpleFieldSet likesFieldSet = AbstractSoneCommand.encodeLikes(likes, "Prefix.");
204 assertThat(likesFieldSet, notNullValue());
205 assertThat(likesFieldSet.getInt("Prefix.Count"), is(likes.size()));
206 assertThat(likesFieldSet.get("Prefix.0.ID"), is(likes.get(0).getId()));
207 assertThat(likesFieldSet.get("Prefix.1.ID"), is(likes.get(1).getId()));
208 assertThat(likesFieldSet.get("Prefix.2.ID"), is(likes.get(2).getId()));
212 public void testParsingAMandatorySone() throws FcpException {
213 Sone sone = mocks.mockSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withName("Test").withProfileName("First", "M.", "Last").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
214 SimpleFieldSet soneFieldSet = new SimpleFieldSetBuilder().put("Sone", "jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").get();
215 Sone parsedSone = abstractSoneCommand.getMandatorySone(soneFieldSet, "Sone");
216 assertThat(parsedSone, notNullValue());
217 assertThat(parsedSone, is(sone));
220 @Test(expected = FcpException.class)
221 public void testParsingANonExistingMandatorySoneCausesAnError() throws FcpException {
222 SimpleFieldSet soneFieldSet = new SimpleFieldSetBuilder().put("Sone", "jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").get();
223 abstractSoneCommand.getMandatorySone(soneFieldSet, "Sone");
226 @Test(expected = FcpException.class)
227 public void testParsingAMandatorySoneFromANonExistingFieldCausesAnError() throws FcpException {
228 SimpleFieldSet soneFieldSet = new SimpleFieldSetBuilder().put("Sone", "jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").get();
229 abstractSoneCommand.getMandatorySone(soneFieldSet, "RealSone");
233 public void testParsingAMandatoryLocalSone() throws FcpException {
234 Sone sone = mocks.mockSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").local().withName("Test").withProfileName("First", "M.", "Last").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
235 SimpleFieldSet soneFieldSet = new SimpleFieldSetBuilder().put("Sone", "jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").get();
236 Sone parsedSone = abstractSoneCommand.getMandatoryLocalSone(soneFieldSet, "Sone");
237 assertThat(parsedSone, notNullValue());
238 assertThat(parsedSone, is(sone));
239 assertThat(parsedSone.isLocal(), is(true));
242 @Test(expected = FcpException.class)
243 public void testParsingANonLocalSoneAsMandatoryLocalSoneCausesAnError() throws FcpException {
244 Sone sone = mocks.mockSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withName("Test").withProfileName("First", "M.", "Last").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
245 SimpleFieldSet soneFieldSet = new SimpleFieldSetBuilder().put("Sone", "jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").get();
246 abstractSoneCommand.getMandatoryLocalSone(soneFieldSet, "Sone");
249 @Test(expected = FcpException.class)
250 public void testParsingAMandatoryLocalSoneFromANonExistingFieldCausesAnError() throws FcpException {
251 SimpleFieldSet soneFieldSet = new SimpleFieldSetBuilder().put("Sone", "jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").get();
252 abstractSoneCommand.getMandatoryLocalSone(soneFieldSet, "RealSone");
256 public void testParsingAnExistingOptionalSone() throws FcpException {
257 Sone sone = mocks.mockSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withName("Test").withProfileName("First", "M.", "Last").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
258 SimpleFieldSet soneFieldSet = new SimpleFieldSetBuilder().put("Sone", "jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").get();
259 Optional<Sone> parsedSone = abstractSoneCommand.getOptionalSone(soneFieldSet, "Sone");
260 assertThat(parsedSone, notNullValue());
261 assertThat(parsedSone.isPresent(), is(true));
262 assertThat(parsedSone.get(), is(sone));
266 public void testParsingANonExistingOptionalSone() throws FcpException {
267 SimpleFieldSet soneFieldSet = new SimpleFieldSetBuilder().put("Sone", "jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").get();
268 Optional<Sone> parsedSone = abstractSoneCommand.getOptionalSone(soneFieldSet, "Sone");
269 assertThat(parsedSone, notNullValue());
270 assertThat(parsedSone.isPresent(), is(false));
273 @Test(expected = FcpException.class)
274 public void testParsingAnOptionalSoneFromANonExistingFieldCausesAnError() throws FcpException {
275 SimpleFieldSet soneFieldSet = new SimpleFieldSetBuilder().put("Sone", "jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").get();
276 abstractSoneCommand.getOptionalSone(soneFieldSet, "RealSone");
280 public void testParsingAPost() throws FcpException {
281 Sone sone = mocks.mockSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withName("Test").withProfileName("First", "M.", "Last").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
282 Post post = mocks.mockPost(sone, randomUUID().toString()).withRecipient(null).withTime((long) (Math.random() * Long.MAX_VALUE)).withText("Some Text.").create();
283 SimpleFieldSet postFieldSet = new SimpleFieldSetBuilder().put("Post", post.getId()).get();
284 Post parsedPost = abstractSoneCommand.getPost(postFieldSet, "Post");
285 assertThat(parsedPost, notNullValue());
286 assertThat(parsedPost, is(post));
289 @Test(expected = FcpException.class)
290 public void testThatTryingToParseANonExistingPostCausesAnError() throws FcpException {
291 SimpleFieldSet postFieldSet = new SimpleFieldSetBuilder().put("Post", "InvalidPostId").get();
292 abstractSoneCommand.getPost(postFieldSet, "Post");
295 @Test(expected = FcpException.class)
296 public void testThatTryingToParseAPostFromANonExistingFieldCausesAnError() throws FcpException {
297 SimpleFieldSet postFieldSet = new SimpleFieldSetBuilder().get();
298 abstractSoneCommand.getPost(postFieldSet, "Post");
302 public void testParsingAReply() throws FcpException {
303 Sone sone = mocks.mockSone(randomUUID().toString()).create();
304 PostReply reply = mocks.mockPostReply(sone, randomUUID().toString()).create();
305 SimpleFieldSet replyFieldSet = new SimpleFieldSetBuilder().put("Reply", reply.getId()).get();
306 PostReply parsedReply = abstractSoneCommand.getReply(replyFieldSet, "Reply");
307 assertThat(parsedReply, notNullValue());
308 assertThat(parsedReply, is(reply));
311 @Test(expected = FcpException.class)
312 public void testParsingANonExistingReply() throws FcpException {
313 SimpleFieldSet replyFieldSet = new SimpleFieldSetBuilder().put("Reply", "InvalidReplyId").get();
314 abstractSoneCommand.getReply(replyFieldSet, "Reply");
317 @Test(expected = FcpException.class)
318 public void testParsingAReplyFromANonExistingField() throws FcpException {
319 SimpleFieldSet replyFieldSet = new SimpleFieldSetBuilder().get();
320 abstractSoneCommand.getReply(replyFieldSet, "Reply");
324 public void testEncodingAPostWithoutRecipientAndReplies() throws FSParseException {
325 Sone sone = mocks.mockSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withName("Test").withProfileName("First", "M.", "Last").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
326 Post post = mocks.mockPost(sone, randomUUID().toString()).withRecipient(null).withTime((long) (Math.random() * Long.MAX_VALUE)).withText("Some Text.").create();
327 SimpleFieldSet postFieldSet = abstractSoneCommand.encodePost(post, "Post.");
328 assertThat(postFieldSet, notNullValue());
329 verifyPost(postFieldSet, "Post.", post);
332 private void verifyPost(SimpleFieldSet postFieldSet, String prefix, Post post) throws FSParseException {
333 assertThat(postFieldSet.get(prefix + "ID"), is(post.getId()));
334 assertThat(postFieldSet.get(prefix + "Sone"), is(post.getSone().getId()));
335 assertThat(postFieldSet.get(prefix + "Recipient"), is(post.getRecipientId().orNull()));
336 assertThat(postFieldSet.getLong(prefix + "Time"), is(post.getTime()));
337 assertThat(postFieldSet.get(prefix + "Text"), is(post.getText()));
341 public void testEncodingAPostWithRecipientWithoutReplies() throws FSParseException {
342 Sone sone = mocks.mockSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withName("Test").withProfileName("First", "M.", "Last").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
343 Post post = mocks.mockPost(sone, randomUUID().toString()).withRecipient("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg").withTime((long) (Math.random() * Long.MAX_VALUE)).withText("Some Text.").create();
344 SimpleFieldSet postFieldSet = abstractSoneCommand.encodePost(post, "Post.");
345 assertThat(postFieldSet, notNullValue());
346 verifyPost(postFieldSet, "Post.", post);
350 public void testEncodingAPostWithoutRecipientWithReplies() throws FSParseException {
351 Sone sone = mocks.mockSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withName("Test").withProfileName("First", "M.", "Last").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
352 Post post = mocks.mockPost(sone, randomUUID().toString()).withRecipient(null).withTime((long) (Math.random() * Long.MAX_VALUE)).withText("Some Text.").create();
353 PostReply postReply = mocks.mockPostReply(sone, randomUUID().toString()).withTime(currentTimeMillis()).withText("Reply.").create();
354 when(post.getReplies()).thenReturn(asList(postReply));
355 SimpleFieldSet postFieldSet = abstractSoneCommand.encodePostWithReplies(post, "Post.");
356 assertThat(postFieldSet, notNullValue());
357 verifyPostWithReplies(postFieldSet, "Post.", post);
361 public void testEncodingAPostWithoutRecipientWithFutureReplies() throws FSParseException {
362 Sone sone = mocks.mockSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withName("Test").withProfileName("First", "M.", "Last").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
363 Post post = mocks.mockPost(sone, randomUUID().toString()).withRecipient(null).withTime((long) (Math.random() * Long.MAX_VALUE)).withText("Some Text.").create();
364 PostReply postReply = mocks.mockPostReply(sone, randomUUID().toString()).withTime(currentTimeMillis() + DAYS.toMillis(1)).withText("Reply.").create();
365 when(post.getReplies()).thenReturn(asList(postReply));
366 SimpleFieldSet postFieldSet = abstractSoneCommand.encodePostWithReplies(post, "Post.");
367 assertThat(postFieldSet, notNullValue());
368 verifyPostWithReplies(postFieldSet, "Post.", post);
372 public void testEncodingAPostWithRecipientAndReplies() throws FSParseException {
373 Sone sone = mocks.mockSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withName("Test").withProfileName("First", "M.", "Last").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
374 Post post = mocks.mockPost(sone, randomUUID().toString()).withRecipient("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg").withTime((long) (Math.random() * Long.MAX_VALUE)).withText("Some Text.").create();
375 PostReply postReply = mocks.mockPostReply(sone, randomUUID().toString()).withTime(currentTimeMillis()).withText("Reply.").create();
376 when(post.getReplies()).thenReturn(asList(postReply));
377 SimpleFieldSet postFieldSet = abstractSoneCommand.encodePostWithReplies(post, "Post.");
378 assertThat(postFieldSet, notNullValue());
379 verifyPostWithReplies(postFieldSet, "Post.", post);
383 public void testEncodingPostsWithoutRecipientAndReplies() throws FSParseException {
384 Sone sone1 = mocks.mockSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withName("Test1").withProfileName("Alpha", "A.", "First").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
385 Sone sone2 = mocks.mockSone("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg").withName("Test2").withProfileName("Beta", "B.", "Second").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
386 Post post1 = mocks.mockPost(sone1, randomUUID().toString()).withRecipient(null).withTime((long) (Math.random() * Long.MAX_VALUE)).withText("Some Text.").create();
387 Post post2 = mocks.mockPost(sone2, randomUUID().toString()).withRecipient(null).withTime((long) (Math.random() * Long.MAX_VALUE)).withText("Some other Text.").create();
388 SimpleFieldSet postFieldSet = abstractSoneCommand.encodePosts(asList(post1, post2), "Posts.");
389 assertThat(postFieldSet, notNullValue());
390 verifyPosts(postFieldSet, "Posts.", asList(post1, post2));
394 public void testEncodingPostsWithRecipientWithoutReplies() throws FSParseException {
395 Sone sone1 = mocks.mockSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withName("Test1").withProfileName("Alpha", "A.", "First").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
396 Sone sone2 = mocks.mockSone("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg").withName("Test2").withProfileName("Beta", "B.", "Second").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
397 Post post1 = mocks.mockPost(sone1, randomUUID().toString()).withRecipient("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg").withTime((long) (Math.random() * Long.MAX_VALUE)).withText("Some Text.").create();
398 Post post2 = mocks.mockPost(sone2, randomUUID().toString()).withRecipient("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withTime((long) (Math.random() * Long.MAX_VALUE)).withText("Some other Text.").create();
399 SimpleFieldSet postFieldSet = abstractSoneCommand.encodePosts(asList(post1, post2), "Posts.");
400 assertThat(postFieldSet, notNullValue());
401 verifyPosts(postFieldSet, "Posts.", asList(post1, post2));
405 public void testEncodingPostsWithoutRecipientWithReplies() throws FSParseException {
406 Sone sone1 = mocks.mockSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withName("Test1").withProfileName("Alpha", "A.", "First").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
407 Sone sone2 = mocks.mockSone("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg").withName("Test2").withProfileName("Beta", "B.", "Second").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
408 Post post1 = mocks.mockPost(sone1, randomUUID().toString()).withRecipient(null).withTime((long) (Math.random() * Long.MAX_VALUE)).withText("Some Text.").create();
409 Post post2 = mocks.mockPost(sone2, randomUUID().toString()).withRecipient(null).withTime((long) (Math.random() * Long.MAX_VALUE)).withText("Some other Text.").create();
410 PostReply postReply1 = mocks.mockPostReply(sone2, randomUUID().toString()).withTime(currentTimeMillis()).withText("Reply from 2 to 1").create();
411 PostReply postReply2 = mocks.mockPostReply(sone1, randomUUID().toString()).withTime(currentTimeMillis()).withText("Reply from 1 to 2").create();
412 when(post1.getReplies()).thenReturn(asList(postReply1));
413 when(post2.getReplies()).thenReturn(asList(postReply2));
414 SimpleFieldSet postFieldSet = abstractSoneCommand.encodePostsWithReplies(asList(post1, post2), "Posts.");
415 assertThat(postFieldSet, notNullValue());
416 verifyPostsWithReplies(postFieldSet, "Posts.", asList(post1, post2));
420 public void testEncodingPostsWithRecipientAndReplies() throws FSParseException {
421 Sone sone1 = mocks.mockSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withName("Test1").withProfileName("Alpha", "A.", "First").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
422 Sone sone2 = mocks.mockSone("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg").withName("Test2").withProfileName("Beta", "B.", "Second").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
423 Post post1 = mocks.mockPost(sone1, randomUUID().toString()).withRecipient("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg").withTime((long) (Math.random() * Long.MAX_VALUE)).withText("Some Text.").create();
424 Post post2 = mocks.mockPost(sone2, randomUUID().toString()).withRecipient("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withTime((long) (Math.random() * Long.MAX_VALUE)).withText("Some other Text.").create();
425 PostReply postReply1 = mocks.mockPostReply(sone2, randomUUID().toString()).withTime(currentTimeMillis()).withText("Reply from 2 to 1").create();
426 PostReply postReply2 = mocks.mockPostReply(sone1, randomUUID().toString()).withTime(currentTimeMillis()).withText("Reply from 1 to 2").create();
427 when(post1.getReplies()).thenReturn(asList(postReply1));
428 when(post2.getReplies()).thenReturn(asList(postReply2));
429 SimpleFieldSet postFieldSet = abstractSoneCommand.encodePostsWithReplies(asList(post1, post2), "Posts.");
430 assertThat(postFieldSet, notNullValue());
431 verifyPostsWithReplies(postFieldSet, "Posts.", asList(post1, post2));
435 public void testEncodingPostsWithRecipientAndFutureReplies() throws FSParseException {
436 Sone sone1 = mocks.mockSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withName("Test1").withProfileName("Alpha", "A.", "First").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
437 Sone sone2 = mocks.mockSone("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg").withName("Test2").withProfileName("Beta", "B.", "Second").addProfileField("Test1", "Value1").withTime((long) (Math.random() * Long.MAX_VALUE)).create();
438 Post post1 = mocks.mockPost(sone1, randomUUID().toString()).withRecipient("KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg").withTime((long) (Math.random() * Long.MAX_VALUE)).withText("Some Text.").create();
439 Post post2 = mocks.mockPost(sone2, randomUUID().toString()).withRecipient("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E").withTime((long) (Math.random() * Long.MAX_VALUE)).withText("Some other Text.").create();
440 PostReply postReply1 = mocks.mockPostReply(sone2, randomUUID().toString()).withTime(currentTimeMillis()).withText("Reply from 2 to 1").create();
441 PostReply postReply2 = mocks.mockPostReply(sone1, randomUUID().toString()).withTime(currentTimeMillis() + DAYS.toMillis(1)).withText("Reply from 1 to 2").create();
442 when(post1.getReplies()).thenReturn(asList(postReply1));
443 when(post2.getReplies()).thenReturn(asList(postReply2));
444 SimpleFieldSet postFieldSet = abstractSoneCommand.encodePostsWithReplies(asList(post1, post2), "Posts.");
445 assertThat(postFieldSet, notNullValue());
446 verifyPostsWithReplies(postFieldSet, "Posts.", asList(post1, post2));