* @throws FcpException
* if an FCP error occurs
*/
- public void setTrust(OwnIdentity ownIdentity, Identity identity, byte trust, String comment) throws IOException, FcpException {
+ public void setTrust(OwnIdentity ownIdentity, Identity identity, int trust, String comment) throws IOException, FcpException {
Map<String, String> replies = fcpClient.sendPluginMessage(webOfTrustPluginName, createParameters("Message", "SetTrust", "Truster", ownIdentity.getIdentifier(), "Trustee", identity.getIdentifier(), "Value", String.valueOf(trust), "Comment", comment));
if (!replies.get("Message").equals("TrustSet")) {
throw new FcpException("WebOfTrust Plugin did not reply with “TrustSet” message!");
import org.junit.rules.Timeout;
import org.junit.runner.RunWith;
+import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static java.util.Collections.emptySet;
import static net.pterodactylus.fcp.test.IdentityMatchers.hasContexts;
}
+ public static class SetTrustTests extends Common {
+
+ @Test
+ public void setTrustSendsCorrectCommand() throws Exception {
+ TestFcpConnection fcpConnection = createConnectionThatSendsTrustSet();
+ WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+ webOfTrustPlugin.setTrust(ownIdentity, identity, 123, "Test Trust");
+ assertThat(fcpConnection.sentMessages.get(0), allOf(
+ isNamed(equalTo("FCPPluginMessage")),
+ hasField("Identifier", notNullValue()),
+ hasField("PluginName", equalTo("plugins.WebOfTrust.WebOfTrust")),
+ hasField("Param.Message", equalTo("SetTrust")),
+ hasField("Param.Truster", equalTo("own-id")),
+ hasField("Param.Trustee", equalTo("ext-id")),
+ hasField("Param.Value", equalTo("123")),
+ hasField("Param.Comment", equalTo("Test Trust"))
+ ));
+ }
+
+ @Test
+ public void setTrustThrowsExceptionWhenDifferentReplyIsSentByPlugin() {
+ FcpConnection fcpConnection = createConnectionThatSendsOtherMessage();
+ WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+ assertThrows(FcpException.class, () -> webOfTrustPlugin.setTrust(ownIdentity, identity, 123, "Test Trust"));
+ }
+
+ private TestFcpConnection createConnectionThatSendsTrustSet() {
+ return createConnection("TrustSet");
+ }
+
+ private final OwnIdentity ownIdentity = new OwnIdentity("own-id", "Own ID", "or", "ir", emptyList(), emptyMap());
+ private final Identity identity = new Identity("ext-id", "Ext ID", "er", emptyList(), emptyMap());
+
+ }
+
private static class Common {
@SafeVarargs