2 * Sone - GetSoneCommandTest.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 java.util.Arrays.asList;
21 import static net.pterodactylus.sone.Verifiers.verifyAnswer;
22 import static net.pterodactylus.sone.Verifiers.verifyFollowedSone;
23 import static net.pterodactylus.sone.Verifiers.verifyNotFollowedSone;
24 import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT;
26 import java.util.Arrays;
28 import net.pterodactylus.sone.data.Mocks;
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.node.FSParseException;
35 import freenet.support.SimpleFieldSet;
37 import org.junit.Test;
40 * Unit test for {@link GetSoneCommand}.
42 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
44 public class GetSoneCommandTest {
46 private final Mocks mocks = new Mocks();
47 private final GetSoneCommand getSoneCommand = new GetSoneCommand(mocks.core);
50 public void gettingAFollowedSone() throws FcpException, FSParseException {
51 Sone followedSone = mocks.mockSone("FSone").withName("Followed Sone").withProfileName("F.", "Ollowed", "Sone").withTime(1000L).addProfileField("Field1", "Value1").create();
52 mocks.mockSone("LSone").withFriends(asList(followedSone.getId())).local().create();
53 SimpleFieldSet getSoneFieldSet = new SimpleFieldSetBuilder()
54 .put("Message", "GetSone")
56 .put("LocalSone", "LSone")
58 Response response = getSoneCommand.execute(getSoneFieldSet, null, DIRECT);
59 verifyAnswer(response, "Sone");
60 verifyFollowedSone(response.getReplyParameters(), "", followedSone);
64 public void gettingANotFollowedSone() throws FcpException, FSParseException {
65 Sone unfollowedSone = mocks.mockSone("FSone").withName("Followed Sone").withProfileName("F.", "Ollowed", "Sone").withTime(1000L).addProfileField("Field1", "Value1").create();
66 mocks.mockSone("LSone").withFriends(Arrays.<String>asList()).local().create();
67 SimpleFieldSet getSoneFieldSet = new SimpleFieldSetBuilder()
68 .put("Message", "GetSone")
70 .put("LocalSone", "LSone")
72 Response response = getSoneCommand.execute(getSoneFieldSet, null, DIRECT);
73 verifyAnswer(response, "Sone");
74 verifyNotFollowedSone(response.getReplyParameters(), "", unfollowedSone);
78 public void gettingASoneWithoutALocalSone() throws FcpException, FSParseException {
79 Sone sone = mocks.mockSone("Sone").withName("Some Sone").withProfileName("S.", "Ome", "Sone").withTime(1000L).addProfileField("Field1", "Value1").create();
80 SimpleFieldSet getSoneFieldSet = new SimpleFieldSetBuilder()
81 .put("Message", "GetSone")
84 Response response = getSoneCommand.execute(getSoneFieldSet, null, DIRECT);
85 verifyAnswer(response, "Sone");
86 verifyNotFollowedSone(response.getReplyParameters(), "", sone);
89 @Test(expected = FcpException.class)
90 public void gettingANonExistingSoneCausesAnError() throws FcpException {
91 SimpleFieldSet getSoneFieldSet = new SimpleFieldSetBuilder()
92 .put("Message", "GetSone")
95 getSoneCommand.execute(getSoneFieldSet, null, DIRECT);