import net.pterodactylus.fcp.FcpMessage;
import net.pterodactylus.fcp.highlevel.FcpClient;
import net.pterodactylus.fcp.highlevel.FcpException;
+import net.pterodactylus.fcp.test.IdentityTrustMatchers;
import net.pterodactylus.fcp.test.TestFcpConnection;
import org.junit.Rule;
import org.junit.Test;
import static net.pterodactylus.fcp.test.IdentityMatchers.hasNickname;
import static net.pterodactylus.fcp.test.IdentityMatchers.hasProperties;
import static net.pterodactylus.fcp.test.IdentityMatchers.hasRequestUri;
+import static net.pterodactylus.fcp.test.IdentityTrustMatchers.hasComment;
import static net.pterodactylus.fcp.test.Matchers.hasField;
import static net.pterodactylus.fcp.test.Matchers.isNamed;
import static net.pterodactylus.fcp.test.TrustMatchers.hasNoRank;
}
+ public static class GetTrustersTests extends Common {
+
+ @Test
+ public void getTrustersSendsCorrectCommand() throws Exception {
+ TestFcpConnection fcpConnection = createConnectionThatSendsTrusters();
+ WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+ Identity identity = new Identity("test-owner", "Test Owner", "request-uri", emptySet(), emptyMap());
+ webOfTrustPlugin.getTrusters(identity, "test");
+ assertThat(fcpConnection.sentMessages.get(0), allOf(
+ isNamed(equalTo("FCPPluginMessage")),
+ hasField("Identifier", notNullValue()),
+ hasField("PluginName", equalTo("plugins.WebOfTrust.WebOfTrust")),
+ hasField("Param.Message", equalTo("GetTrusters")),
+ hasField("Param.Identity", equalTo("test-owner")),
+ hasField("Param.Context", equalTo("test"))
+ ));
+ }
+
+ @Test
+ public void getTrustersThrowsExceptionWhenDifferentReplyIsSentByPlugin() {
+ FcpConnection fcpConnection = createConnectionThatSendsOtherMessage();
+ WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+ Identity identity = new Identity("test-owner", "Test Owner", "request-uri", emptySet(), emptyMap());
+ assertThrows(FcpException.class, () -> webOfTrustPlugin.getTrusters(identity, "test"));
+ }
+
+ @Test
+ public void getTrustersParsesResponseCorrectly() throws Exception {
+ TestFcpConnection fcpConnection = createConnectionThatSendsTrusters();
+ WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+ Identity identity = new Identity("test-owner", "Test Owner", "request-uri", emptySet(), emptyMap());
+ Map<Identity, IdentityTrust> trusters = webOfTrustPlugin.getTrusters(identity, "test");
+ assertThat(trusters, allOf(
+ aMapWithSize(2),
+ hasEntry(hasId("id0"), allOf(IdentityTrustMatchers.hasTrust(123), hasComment("comment0"))),
+ hasEntry(hasId("id1"), allOf(IdentityTrustMatchers.hasTrust(99), hasComment("comment1")))
+ ));
+ }
+
+ private TestFcpConnection createConnectionThatSendsTrusters() {
+ return createConnection("Identities",
+ entries("Identity0", "id0", "Nickname0", "nickname0", "RequestURI0", "request-uri0", "Value0", "123", "Comment0", "comment0"),
+ entries("Identity1", "id1", "Nickname1", "nickname1", "RequestURI1", "request-uri1", "Value1", "99", "Comment1", "comment1")
+ );
+ }
+
+ }
+
private static class Common {
@SafeVarargs