2 * Sone - DeleteReplyCommandTest.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 net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT;
21 import static org.hamcrest.MatcherAssert.assertThat;
22 import static org.hamcrest.Matchers.is;
23 import static org.hamcrest.Matchers.notNullValue;
24 import static org.mockito.ArgumentCaptor.forClass;
25 import static org.mockito.Mockito.doNothing;
27 import net.pterodactylus.sone.data.Mocks;
28 import net.pterodactylus.sone.data.PostReply;
29 import net.pterodactylus.sone.data.Sone;
30 import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
31 import net.pterodactylus.sone.freenet.fcp.Command.Response;
32 import net.pterodactylus.sone.freenet.fcp.FcpException;
34 import freenet.support.SimpleFieldSet;
36 import org.junit.Test;
37 import org.mockito.ArgumentCaptor;
40 * Unit test for {@link DeleteReplyCommand}.
42 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
44 public class DeleteReplyCommandTest {
46 private final Mocks mocks = new Mocks();
47 private final DeleteReplyCommand deleteReplyCommand = new DeleteReplyCommand(mocks.core);
50 public void verifyThatDeletingAReplyWorks() throws FcpException {
51 Sone sone = mocks.mockLocalSone("SoneId");
52 PostReply postReply = mocks.mockPostReply(sone, "ReplyId");
53 ArgumentCaptor<PostReply> postReplyCaptor = forClass(PostReply.class);
54 doNothing().when(mocks.core).deleteReply(postReplyCaptor.capture());
55 SimpleFieldSet deleteReplyFieldSet = new SimpleFieldSetBuilder()
56 .put("Message", "DeleteReply")
57 .put("Reply", "ReplyId")
59 Response response = deleteReplyCommand.execute(deleteReplyFieldSet, null, DIRECT);
60 assertThat(response, notNullValue());
61 assertThat(postReplyCaptor.getValue(), is(postReply));
62 assertThat(response.getReplyParameters(), notNullValue());
63 assertThat(response.getReplyParameters().get("Message"), is("ReplyDeleted"));
66 @Test(expected = FcpException.class)
67 public void verifyThatDeletingAReplyWithAnInvalidReplyIdCausesAnError() throws FcpException {
68 SimpleFieldSet deleteReplyFieldSet = new SimpleFieldSetBuilder()
69 .put("Message", "DeleteReply")
70 .put("Reply", "ReplyId")
72 deleteReplyCommand.execute(deleteReplyFieldSet, null, DIRECT);
75 @Test(expected = FcpException.class)
76 public void verifyThatDeletingAReplyWithoutReplyIdCausesAnError() throws FcpException {
77 SimpleFieldSet deleteReplyFieldSet = new SimpleFieldSetBuilder()
78 .put("Message", "DeleteReply")
80 deleteReplyCommand.execute(deleteReplyFieldSet, null, DIRECT);
84 public void verifyThatDeletingAReplyFromANonLocalSoneCausesAnError() throws FcpException {
85 Sone sone = mocks.mockRemoteSone("SoneId");
86 mocks.mockPostReply(sone, "ReplyId");
87 SimpleFieldSet deleteReplyFieldSet = new SimpleFieldSetBuilder()
88 .put("Message", "DeleteReply")
89 .put("Reply", "ReplyId")
91 Response response = deleteReplyCommand.execute(deleteReplyFieldSet, null, DIRECT);
92 assertThat(response, notNullValue());
93 assertThat(response.getReplyParameters(), notNullValue());
94 assertThat(response.getReplyParameters().get("Message"), is("Error"));
95 assertThat(response.getReplyParameters().get("ErrorCode"), is("401"));