import net.pterodactylus.fcp.test.TestFcpConnection;
import org.junit.Rule;
import org.junit.Test;
+import org.junit.experimental.runners.Enclosed;
import org.junit.rules.Timeout;
+import org.junit.runner.RunWith;
import java.io.IOException;
import java.util.HashMap;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThrows;
+@RunWith(Enclosed.class)
public class WebOfTrustPluginTest {
- @Test
- public void creatingIdentityWithoutKeysSendsCorrectMessage() throws IOException, FcpException {
- TestFcpConnection fcpConnection = createConnectionThatCreatesOwnIdentity();
- WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
- webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true);
- assertThat(fcpConnection.sentMessages.get(0), allOf(
- isNamed(equalTo("FCPPluginMessage")),
- hasField("Identifier", not(nullValue())),
- hasField("PluginName", equalTo("plugins.WebOfTrust.WebOfTrust")),
- hasField("Param.Message", equalTo("CreateIdentity")),
- hasField("Param.Nickname", equalTo("Test Nickname")),
- hasField("Param.Context", equalTo("test-context")),
- hasField("Param.PublishTrustList", equalTo("true")),
- hasField("Param.InsertURI", nullValue())
- ));
- }
+ public static class CreateIdentityTests extends Common {
+
+ @Test
+ public void creatingIdentityWithoutKeysSendsCorrectMessage() throws IOException, FcpException {
+ TestFcpConnection fcpConnection = createConnectionThatCreatesOwnIdentity();
+ WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+ webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true);
+ assertThat(fcpConnection.sentMessages.get(0), allOf(
+ isNamed(equalTo("FCPPluginMessage")),
+ hasField("Identifier", not(nullValue())),
+ hasField("PluginName", equalTo("plugins.WebOfTrust.WebOfTrust")),
+ hasField("Param.Message", equalTo("CreateIdentity")),
+ hasField("Param.Nickname", equalTo("Test Nickname")),
+ hasField("Param.Context", equalTo("test-context")),
+ hasField("Param.PublishTrustList", equalTo("true")),
+ hasField("Param.InsertURI", nullValue())
+ ));
+ }
- @Test
- public void creatingIdentityWithoutKeysCreatesCorrectOwnIdentityFromReply() throws IOException, FcpException {
- TestFcpConnection fcpConnection = createConnectionThatCreatesOwnIdentity();
- WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
- OwnIdentity ownIdentity = webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true);
- assertThat(ownIdentity, isOwnIdentity(equalTo("identity"), equalTo("Test Nickname"), equalTo("request-uri"), equalTo("insert-uri")));
- }
+ @Test
+ public void creatingIdentityWithoutKeysCreatesCorrectOwnIdentityFromReply() throws IOException, FcpException {
+ TestFcpConnection fcpConnection = createConnectionThatCreatesOwnIdentity();
+ WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+ OwnIdentity ownIdentity = webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true);
+ assertThat(ownIdentity, isOwnIdentity(equalTo("identity"), equalTo("Test Nickname"), equalTo("request-uri"), equalTo("insert-uri")));
+ }
- @Test
- public void creatingIdentityWithInsertKeySendsCorrectMessage() throws IOException, FcpException {
- TestFcpConnection fcpConnection = createConnectionThatCreatesOwnIdentity();
- WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
- webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true, "insert-uri");
- assertThat(fcpConnection.sentMessages.get(0), allOf(
- isNamed(equalTo("FCPPluginMessage")),
- hasField("Identifier", not(nullValue())),
- hasField("PluginName", equalTo("plugins.WebOfTrust.WebOfTrust")),
- hasField("Param.Message", equalTo("CreateIdentity")),
- hasField("Param.Nickname", equalTo("Test Nickname")),
- hasField("Param.Context", equalTo("test-context")),
- hasField("Param.PublishTrustList", equalTo("true")),
- hasField("Param.InsertURI", equalTo("insert-uri"))
- ));
- }
+ @Test
+ public void creatingIdentityWithInsertKeySendsCorrectMessage() throws IOException, FcpException {
+ TestFcpConnection fcpConnection = createConnectionThatCreatesOwnIdentity();
+ WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+ webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true, "insert-uri");
+ assertThat(fcpConnection.sentMessages.get(0), allOf(
+ isNamed(equalTo("FCPPluginMessage")),
+ hasField("Identifier", not(nullValue())),
+ hasField("PluginName", equalTo("plugins.WebOfTrust.WebOfTrust")),
+ hasField("Param.Message", equalTo("CreateIdentity")),
+ hasField("Param.Nickname", equalTo("Test Nickname")),
+ hasField("Param.Context", equalTo("test-context")),
+ hasField("Param.PublishTrustList", equalTo("true")),
+ hasField("Param.InsertURI", equalTo("insert-uri"))
+ ));
+ }
- @Test
- public void creatingIdentityWithInsertKeyCreatesCorrectOwnIdentityFromReply() throws IOException, FcpException {
- TestFcpConnection fcpConnection = createConnectionThatCreatesOwnIdentity();
- WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
- OwnIdentity ownIdentity = webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true, "insert-uri");
- assertThat(ownIdentity, isOwnIdentity(equalTo("identity"), equalTo("Test Nickname"), equalTo("request-uri"), equalTo("insert-uri")));
- }
+ @Test
+ public void creatingIdentityWithInsertKeyCreatesCorrectOwnIdentityFromReply() throws IOException, FcpException {
+ TestFcpConnection fcpConnection = createConnectionThatCreatesOwnIdentity();
+ WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+ OwnIdentity ownIdentity = webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true, "insert-uri");
+ assertThat(ownIdentity, isOwnIdentity(equalTo("identity"), equalTo("Test Nickname"), equalTo("request-uri"), equalTo("insert-uri")));
+ }
- @Test
- public void creatingIdentityWithInsertAndRequestKeysSendsCorrectMessage() throws IOException, FcpException {
- TestFcpConnection fcpConnection = createConnectionThatCreatesOwnIdentity();
- WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
- webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true, "some-request-uri", "insert-uri");
- assertThat(fcpConnection.sentMessages.get(0), allOf(
- isNamed(equalTo("FCPPluginMessage")),
- hasField("Identifier", not(nullValue())),
- hasField("PluginName", equalTo("plugins.WebOfTrust.WebOfTrust")),
- hasField("Param.Message", equalTo("CreateIdentity")),
- hasField("Param.Nickname", equalTo("Test Nickname")),
- hasField("Param.Context", equalTo("test-context")),
- hasField("Param.PublishTrustList", equalTo("true")),
- hasField("Param.InsertURI", equalTo("insert-uri"))
- ));
- }
+ @Test
+ public void creatingIdentityWithInsertAndRequestKeysSendsCorrectMessage() throws IOException, FcpException {
+ TestFcpConnection fcpConnection = createConnectionThatCreatesOwnIdentity();
+ WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+ webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true, "some-request-uri", "insert-uri");
+ assertThat(fcpConnection.sentMessages.get(0), allOf(
+ isNamed(equalTo("FCPPluginMessage")),
+ hasField("Identifier", not(nullValue())),
+ hasField("PluginName", equalTo("plugins.WebOfTrust.WebOfTrust")),
+ hasField("Param.Message", equalTo("CreateIdentity")),
+ hasField("Param.Nickname", equalTo("Test Nickname")),
+ hasField("Param.Context", equalTo("test-context")),
+ hasField("Param.PublishTrustList", equalTo("true")),
+ hasField("Param.InsertURI", equalTo("insert-uri"))
+ ));
+ }
- @Test
- public void creatingIdentityWithInsertAndRequestKeysCreatesCorrectOwnIdentityFromReply() throws IOException, FcpException {
- TestFcpConnection fcpConnection = createConnectionThatCreatesOwnIdentity();
- WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
- OwnIdentity ownIdentity = webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true, "some-request-uri", "insert-uri");
- assertThat(ownIdentity, isOwnIdentity(equalTo("identity"), equalTo("Test Nickname"), equalTo("request-uri"), equalTo("insert-uri")));
- }
+ @Test
+ public void creatingIdentityWithInsertAndRequestKeysCreatesCorrectOwnIdentityFromReply() throws IOException, FcpException {
+ TestFcpConnection fcpConnection = createConnectionThatCreatesOwnIdentity();
+ WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+ OwnIdentity ownIdentity = webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true, "some-request-uri", "insert-uri");
+ assertThat(ownIdentity, isOwnIdentity(equalTo("identity"), equalTo("Test Nickname"), equalTo("request-uri"), equalTo("insert-uri")));
+ }
- private TestFcpConnection createConnectionThatCreatesOwnIdentity() {
- return createFcpConnection(message -> (listener, connection) -> {
- Map<String, String> fields = createWebOfTrustReplyFields("IdentityCreated", true,
- "ID", "identity", "InsertURI", "insert-uri", "RequestURI", "request-uri");
- FcpMessage replyMessage = createPluginReply(message, fields);
- listener.receivedFCPPluginReply(connection, new FCPPluginReply(replyMessage, null));
- });
- }
+ private TestFcpConnection createConnectionThatCreatesOwnIdentity() {
+ return createFcpConnection(message -> (listener, connection) -> {
+ Map<String, String> fields = createWebOfTrustReplyFields("IdentityCreated", true,
+ "ID", "identity", "InsertURI", "insert-uri", "RequestURI", "request-uri");
+ FcpMessage replyMessage = createPluginReply(message, fields);
+ listener.receivedFCPPluginReply(connection, new FCPPluginReply(replyMessage, null));
+ });
+ }
- @Test
- public void creatingIdentityFailsWithoutKeysFailsWhenDifferentReplyIsSentByPlugin() {
- FcpConnection fcpConnection = createConnectionThatSendsOtherMessage();
- WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
- assertThrows(FcpException.class, () -> webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true));
- }
+ @Test
+ public void creatingIdentityFailsWithoutKeysFailsWhenDifferentReplyIsSentByPlugin() {
+ FcpConnection fcpConnection = createConnectionThatSendsOtherMessage();
+ WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+ assertThrows(FcpException.class, () -> webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true));
+ }
- @Test
- public void creatingIdentityFailsWithInsertKeyFailsWhenDifferentReplyIsSentByPlugin() {
- FcpConnection fcpConnection = createConnectionThatSendsOtherMessage();
- WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
- assertThrows(FcpException.class, () -> webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true, "insert-uri"));
- }
+ @Test
+ public void creatingIdentityFailsWithInsertKeyFailsWhenDifferentReplyIsSentByPlugin() {
+ FcpConnection fcpConnection = createConnectionThatSendsOtherMessage();
+ WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+ assertThrows(FcpException.class, () -> webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true, "insert-uri"));
+ }
- @Test
- public void creatingIdentityWithInsertAndRequestKeyFailsWhenDifferentReplyIsSentByPlugin() {
- FcpConnection fcpConnection = createConnectionThatSendsOtherMessage();
- WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
- assertThrows(FcpException.class, () -> webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true, "some-request-uri", "insert-uri"));
- }
+ @Test
+ public void creatingIdentityWithInsertAndRequestKeyFailsWhenDifferentReplyIsSentByPlugin() {
+ FcpConnection fcpConnection = createConnectionThatSendsOtherMessage();
+ WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+ assertThrows(FcpException.class, () -> webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true, "some-request-uri", "insert-uri"));
+ }
- @Test
- public void gettingOwnIdentitiesSendsCorrectMessage() throws Exception {
- TestFcpConnection fcpConnection = createConnectionThatDeliversOwnIdentities();
- WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
- webOfTrustPlugin.getOwnIdentities();
- assertThat(fcpConnection.sentMessages.get(0), allOf(
- isNamed(equalTo("FCPPluginMessage")),
- hasField("Identifier", not(nullValue())),
- hasField("PluginName", equalTo("plugins.WebOfTrust.WebOfTrust")),
- hasField("Param.Message", equalTo("GetOwnIdentities"))
- ));
}
- @Test
- public void gettingOwnIdentitiesParsesOwnIdentitiesCorrectly() throws Exception {
- TestFcpConnection fcpConnection = createConnectionThatDeliversOwnIdentities();
- WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
- Set<OwnIdentity> ownIdentities = webOfTrustPlugin.getOwnIdentities();
- assertThat(ownIdentities, containsInAnyOrder(
- allOf(isOwnIdentity(equalTo("identity-0"), equalTo("Nick 0"), equalTo("request-uri-0"), equalTo("insert-uri-0")),
- hasContexts(containsInAnyOrder("test-context-1", "test-context-2")),
- hasProperties(allOf(aMapWithSize(2), hasEntry("prop1", "value1"), hasEntry("prop2", "value2")))),
- allOf(isOwnIdentity(equalTo("identity-1"), equalTo("Nick 1"), equalTo("request-uri-1"), equalTo("insert-uri-1")),
- hasContexts(containsInAnyOrder("test-context-2", "test-context-3")),
- hasProperties(allOf(aMapWithSize(2), hasEntry("prop3", "value3"), hasEntry("prop4", "value4"))))
- ));
- }
+ public static class GetOwnIdentityTests extends Common {
+
+ @Test
+ public void gettingOwnIdentitiesSendsCorrectMessage() throws Exception {
+ TestFcpConnection fcpConnection = createConnectionThatDeliversOwnIdentities();
+ WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+ webOfTrustPlugin.getOwnIdentities();
+ assertThat(fcpConnection.sentMessages.get(0), allOf(
+ isNamed(equalTo("FCPPluginMessage")),
+ hasField("Identifier", not(nullValue())),
+ hasField("PluginName", equalTo("plugins.WebOfTrust.WebOfTrust")),
+ hasField("Param.Message", equalTo("GetOwnIdentities"))
+ ));
+ }
- @Test
- public void gettingOwnIdentitiesUsingDeprecatedMethodSendsCorrectMessage() throws Exception {
- TestFcpConnection fcpConnection = createConnectionThatDeliversOwnIdentities();
- WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
- webOfTrustPlugin.getOwnIdentites();
- assertThat(fcpConnection.sentMessages.get(0), allOf(
- isNamed(equalTo("FCPPluginMessage")),
- hasField("Identifier", not(nullValue())),
- hasField("PluginName", equalTo("plugins.WebOfTrust.WebOfTrust")),
- hasField("Param.Message", equalTo("GetOwnIdentities"))
- ));
- }
+ @Test
+ public void gettingOwnIdentitiesParsesOwnIdentitiesCorrectly() throws Exception {
+ TestFcpConnection fcpConnection = createConnectionThatDeliversOwnIdentities();
+ WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+ Set<OwnIdentity> ownIdentities = webOfTrustPlugin.getOwnIdentities();
+ assertThat(ownIdentities, containsInAnyOrder(
+ allOf(isOwnIdentity(equalTo("identity-0"), equalTo("Nick 0"), equalTo("request-uri-0"), equalTo("insert-uri-0")),
+ hasContexts(containsInAnyOrder("test-context-1", "test-context-2")),
+ hasProperties(allOf(aMapWithSize(2), hasEntry("prop1", "value1"), hasEntry("prop2", "value2")))),
+ allOf(isOwnIdentity(equalTo("identity-1"), equalTo("Nick 1"), equalTo("request-uri-1"), equalTo("insert-uri-1")),
+ hasContexts(containsInAnyOrder("test-context-2", "test-context-3")),
+ hasProperties(allOf(aMapWithSize(2), hasEntry("prop3", "value3"), hasEntry("prop4", "value4"))))
+ ));
+ }
- @Test
- public void gettingOwnIdentitiesUsingDeprecatedMethodParsesOwnIdentitiesCorrectly() throws Exception {
- TestFcpConnection fcpConnection = createConnectionThatDeliversOwnIdentities();
- WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
- Set<OwnIdentity> ownIdentities = webOfTrustPlugin.getOwnIdentites();
- assertThat(ownIdentities, containsInAnyOrder(
- allOf(isOwnIdentity(equalTo("identity-0"), equalTo("Nick 0"), equalTo("request-uri-0"), equalTo("insert-uri-0")),
- hasContexts(containsInAnyOrder("test-context-1", "test-context-2")),
- hasProperties(allOf(aMapWithSize(2), hasEntry("prop1", "value1"), hasEntry("prop2", "value2")))),
- allOf(isOwnIdentity(equalTo("identity-1"), equalTo("Nick 1"), equalTo("request-uri-1"), equalTo("insert-uri-1")),
- hasContexts(containsInAnyOrder("test-context-2", "test-context-3")),
- hasProperties(allOf(aMapWithSize(2), hasEntry("prop3", "value3"), hasEntry("prop4", "value4"))))
- ));
- }
+ @Test
+ public void gettingOwnIdentitiesUsingDeprecatedMethodSendsCorrectMessage() throws Exception {
+ TestFcpConnection fcpConnection = createConnectionThatDeliversOwnIdentities();
+ WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+ webOfTrustPlugin.getOwnIdentites();
+ assertThat(fcpConnection.sentMessages.get(0), allOf(
+ isNamed(equalTo("FCPPluginMessage")),
+ hasField("Identifier", not(nullValue())),
+ hasField("PluginName", equalTo("plugins.WebOfTrust.WebOfTrust")),
+ hasField("Param.Message", equalTo("GetOwnIdentities"))
+ ));
+ }
- private TestFcpConnection createConnectionThatDeliversOwnIdentities() {
- return createFcpConnection(message -> (listener, connection) -> {
- Map<String, String> fields = createWebOfTrustReplyFields("OwnIdentities", true,
- "Amount", "2", "Identity0", "identity-0", "Nickname0", "Nick 0", "RequestURI0", "request-uri-0", "InsertURI0", "insert-uri-0",
- "Contexts0.Context0", "test-context-1", "Contexts0.Context1", "test-context-2", "Properties0.Property0.Name", "prop1", "Properties0.Property0.Value", "value1", "Properties0.Property1.Name", "prop2", "Properties0.Property1.Value", "value2",
- "Identity1", "identity-1", "Nickname1", "Nick 1", "RequestURI1", "request-uri-1", "InsertURI1", "insert-uri-1",
- "Contexts1.Context0", "test-context-2", "Contexts1.Context1", "test-context-3", "Properties1.Property0.Name", "prop3", "Properties1.Property0.Value", "value3", "Properties1.Property1.Name", "prop4", "Properties1.Property1.Value", "value4"
- );
- FcpMessage replyMessage = createPluginReply(message, fields);
- listener.receivedFCPPluginReply(connection, new FCPPluginReply(replyMessage, null));
- });
- }
+ @Test
+ public void gettingOwnIdentitiesUsingDeprecatedMethodParsesOwnIdentitiesCorrectly() throws Exception {
+ TestFcpConnection fcpConnection = createConnectionThatDeliversOwnIdentities();
+ WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+ Set<OwnIdentity> ownIdentities = webOfTrustPlugin.getOwnIdentites();
+ assertThat(ownIdentities, containsInAnyOrder(
+ allOf(isOwnIdentity(equalTo("identity-0"), equalTo("Nick 0"), equalTo("request-uri-0"), equalTo("insert-uri-0")),
+ hasContexts(containsInAnyOrder("test-context-1", "test-context-2")),
+ hasProperties(allOf(aMapWithSize(2), hasEntry("prop1", "value1"), hasEntry("prop2", "value2")))),
+ allOf(isOwnIdentity(equalTo("identity-1"), equalTo("Nick 1"), equalTo("request-uri-1"), equalTo("insert-uri-1")),
+ hasContexts(containsInAnyOrder("test-context-2", "test-context-3")),
+ hasProperties(allOf(aMapWithSize(2), hasEntry("prop3", "value3"), hasEntry("prop4", "value4"))))
+ ));
+ }
- @Test
- public void getOwnIdentitiesFailsWhenDifferentReplyIsSentByPlugin() {
- FcpConnection fcpConnection = createConnectionThatSendsOtherMessage();
- WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
- assertThrows(FcpException.class, webOfTrustPlugin::getOwnIdentities);
- }
+ private TestFcpConnection createConnectionThatDeliversOwnIdentities() {
+ return createFcpConnection(message -> (listener, connection) -> {
+ Map<String, String> fields = createWebOfTrustReplyFields("OwnIdentities", true,
+ "Amount", "2", "Identity0", "identity-0", "Nickname0", "Nick 0", "RequestURI0", "request-uri-0", "InsertURI0", "insert-uri-0",
+ "Contexts0.Context0", "test-context-1", "Contexts0.Context1", "test-context-2", "Properties0.Property0.Name", "prop1", "Properties0.Property0.Value", "value1", "Properties0.Property1.Name", "prop2", "Properties0.Property1.Value", "value2",
+ "Identity1", "identity-1", "Nickname1", "Nick 1", "RequestURI1", "request-uri-1", "InsertURI1", "insert-uri-1",
+ "Contexts1.Context0", "test-context-2", "Contexts1.Context1", "test-context-3", "Properties1.Property0.Name", "prop3", "Properties1.Property0.Value", "value3", "Properties1.Property1.Name", "prop4", "Properties1.Property1.Value", "value4"
+ );
+ FcpMessage replyMessage = createPluginReply(message, fields);
+ listener.receivedFCPPluginReply(connection, new FCPPluginReply(replyMessage, null));
+ });
+ }
- @Test
- public void getOwnIdentitiesWithDeprecatedMethodFailsWhenDifferentReplyIsSentByPlugin() {
- FcpConnection fcpConnection = createConnectionThatSendsOtherMessage();
- WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
- assertThrows(FcpException.class, webOfTrustPlugin::getOwnIdentites);
- }
+ @Test
+ public void getOwnIdentitiesFailsWhenDifferentReplyIsSentByPlugin() {
+ FcpConnection fcpConnection = createConnectionThatSendsOtherMessage();
+ WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+ assertThrows(FcpException.class, webOfTrustPlugin::getOwnIdentities);
+ }
- @Test
- public void getIdentityTrustSendsCorrectMessage() throws Exception {
- TestFcpConnection fcpConnection = createConnectionThatDeliversIdentityTrustAndScore();
- WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
- OwnIdentity ownIdentity = new OwnIdentity("own-id", "Own ID", "own-pub", "own-priv", emptySet(), emptyMap());
- webOfTrustPlugin.getIdentityTrust(ownIdentity, "other-id");
- assertThat(fcpConnection.sentMessages.get(0), allOf(
- isNamed(equalTo("FCPPluginMessage")),
- hasField("Identifier", not(nullValue())),
- hasField("PluginName", equalTo("plugins.WebOfTrust.WebOfTrust")),
- hasField("Param.Message", equalTo("GetIdentity")),
- hasField("Param.Truster", equalTo("own-id")),
- hasField("Param.Identity", equalTo("other-id"))
- ));
- }
+ @Test
+ public void getOwnIdentitiesWithDeprecatedMethodFailsWhenDifferentReplyIsSentByPlugin() {
+ FcpConnection fcpConnection = createConnectionThatSendsOtherMessage();
+ WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+ assertThrows(FcpException.class, webOfTrustPlugin::getOwnIdentites);
+ }
- @Test
- public void getIdentityTrustParsesTrustCorrectly() throws Exception {
- TestFcpConnection fcpConnection = createConnectionThatDeliversIdentityTrustAndScore();
- WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
- OwnIdentity ownIdentity = new OwnIdentity("own-id", "Own ID", "own-pub", "own-priv", emptySet(), emptyMap());
- CalculatedTrust calculatedTrust = webOfTrustPlugin.getIdentityTrust(ownIdentity, "other-id");
- assertThat(calculatedTrust.getTrust(), equalTo((byte) 56));
- assertThat(calculatedTrust.getScore(), equalTo(56));
- assertThat(calculatedTrust.getRank(), equalTo(1));
}
- private TestFcpConnection createConnectionThatDeliversIdentityTrustAndScore() {
- return createFcpConnection(message -> (listener, connection) -> {
- Map<String, String> fields = createWebOfTrustReplyFields("Identity", true,
- "Identities.Amount", "1",
- "Identities.0.Type", "Identity", "Identities.0.Nickname", "Nick Name", "Identities.0.ReqestURI", "nick-pub", "Identities.0.ID", "nick-id", "Identities.0.VersionID", "0-0", "Identities.0.PublishesTrustList", "true", "Identities.0.CurrentEditionFetchState", "Fetched",
- "Identities.0.Contexts.0.Name", "context-1", "Identities.0.Contexts.1.Name", "context-2", "Identities.0.Contexts.Amount", "2",
- "Identities.0.Properties.0.Name", "prop1", "Identities.0.Properties.0.Value", "value1", "Identities.0.Properties.1.Name", "prop2", "Identities.0.Properties.1.Value", "value2", "Identities.0.Properties.Amount", "2",
- "Trusts.Amount", "1", "Trusts.0.Truster", "own-id", "Trusts.0.Trustee", "nick-id", "Trusts.0.Value", "56", "Trusts.0.Comment", "some trust", "Trusts.0.TrusterEdition", "123", "Trusts.0.VersionID", "1-1",
- "Scores.Amount", "1", "Scores.0.Truster", "own-id", "Scores.0.Trustee", "nick-id", "Scores.0.Capacity", "40", "Scores.0.Rank", "1", "Scores.0.Value", "56", "Scores.0.VersionID", "2-2"
- );
- FcpMessage replyMessage = createPluginReply(message, fields);
- listener.receivedFCPPluginReply(connection, new FCPPluginReply(replyMessage, null));
- });
- }
+ public static class GetIdentityTrustTests extends Common {
+
+ @Test
+ public void getIdentityTrustSendsCorrectMessage() throws Exception {
+ TestFcpConnection fcpConnection = createConnectionThatDeliversIdentityTrustAndScore();
+ WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+ OwnIdentity ownIdentity = new OwnIdentity("own-id", "Own ID", "own-pub", "own-priv", emptySet(), emptyMap());
+ webOfTrustPlugin.getIdentityTrust(ownIdentity, "other-id");
+ assertThat(fcpConnection.sentMessages.get(0), allOf(
+ isNamed(equalTo("FCPPluginMessage")),
+ hasField("Identifier", not(nullValue())),
+ hasField("PluginName", equalTo("plugins.WebOfTrust.WebOfTrust")),
+ hasField("Param.Message", equalTo("GetIdentity")),
+ hasField("Param.Truster", equalTo("own-id")),
+ hasField("Param.Identity", equalTo("other-id"))
+ ));
+ }
- @Test
- public void getIdentityTrustFailsWhenDifferentReplyIsSentByPlugin() {
- FcpConnection fcpConnection = createConnectionThatSendsOtherMessage();
- WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
- OwnIdentity ownIdentity = new OwnIdentity("own-id", "Own ID", "own-pub", "own-priv", emptySet(), emptyMap());
- assertThrows(FcpException.class, () -> webOfTrustPlugin.getIdentityTrust(ownIdentity, "other-id"));
- }
+ @Test
+ public void getIdentityTrustParsesTrustCorrectly() throws Exception {
+ TestFcpConnection fcpConnection = createConnectionThatDeliversIdentityTrustAndScore();
+ WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+ OwnIdentity ownIdentity = new OwnIdentity("own-id", "Own ID", "own-pub", "own-priv", emptySet(), emptyMap());
+ CalculatedTrust calculatedTrust = webOfTrustPlugin.getIdentityTrust(ownIdentity, "other-id");
+ assertThat(calculatedTrust.getTrust(), equalTo((byte) 56));
+ assertThat(calculatedTrust.getScore(), equalTo(56));
+ assertThat(calculatedTrust.getRank(), equalTo(1));
+ }
- private FcpConnection createConnectionThatSendsOtherMessage() {
- return createFcpConnection(message -> (listener, connection) -> {
- Map<String, String> fields = createWebOfTrustReplyFields("OtherMessage", true);
- FcpMessage replyMessage = createPluginReply(message, fields);
- listener.receivedFCPPluginReply(connection, new FCPPluginReply(replyMessage, null));
- });
- }
+ private TestFcpConnection createConnectionThatDeliversIdentityTrustAndScore() {
+ return createFcpConnection(message -> (listener, connection) -> {
+ Map<String, String> fields = createWebOfTrustReplyFields("Identity", true,
+ "Identities.Amount", "1",
+ "Identities.0.Type", "Identity", "Identities.0.Nickname", "Nick Name", "Identities.0.RequestURI", "nick-pub", "Identities.0.ID", "nick-id", "Identities.0.VersionID", "0-0", "Identities.0.PublishesTrustList", "true", "Identities.0.CurrentEditionFetchState", "Fetched",
+ "Identities.0.Contexts.0.Name", "context-1", "Identities.0.Contexts.1.Name", "context-2", "Identities.0.Contexts.Amount", "2",
+ "Identities.0.Properties.0.Name", "prop1", "Identities.0.Properties.0.Value", "value1", "Identities.0.Properties.1.Name", "prop2", "Identities.0.Properties.1.Value", "value2", "Identities.0.Properties.Amount", "2",
+ "Trusts.Amount", "1", "Trusts.0.Truster", "own-id", "Trusts.0.Trustee", "nick-id", "Trusts.0.Value", "56", "Trusts.0.Comment", "some trust", "Trusts.0.TrusterEdition", "123", "Trusts.0.VersionID", "1-1",
+ "Scores.Amount", "1", "Scores.0.Truster", "own-id", "Scores.0.Trustee", "nick-id", "Scores.0.Capacity", "40", "Scores.0.Rank", "1", "Scores.0.Value", "56", "Scores.0.VersionID", "2-2"
+ );
+ FcpMessage replyMessage = createPluginReply(message, fields);
+ listener.receivedFCPPluginReply(connection, new FCPPluginReply(replyMessage, null));
+ });
+ }
+
+ @Test
+ public void getIdentityTrustFailsWhenDifferentReplyIsSentByPlugin() {
+ FcpConnection fcpConnection = createConnectionThatSendsOtherMessage();
+ WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+ OwnIdentity ownIdentity = new OwnIdentity("own-id", "Own ID", "own-pub", "own-priv", emptySet(), emptyMap());
+ assertThrows(FcpException.class, () -> webOfTrustPlugin.getIdentityTrust(ownIdentity, "other-id"));
+ }
- private static WebOfTrustPlugin createWebOfTrustPlugin(FcpConnection fcpConnection) {
- return new WebOfTrustPlugin(new FcpClient(fcpConnection));
}
- private Map<String, String> createWebOfTrustReplyFields(String message, boolean success, String... fields) {
- Map<String, String> replyFields = new HashMap<>();
- replyFields.put("Success", String.valueOf(success));
- replyFields.put("Replies.Message", message);
- for (int fieldIndex = 0; fieldIndex < fields.length - 1; fieldIndex += 2) {
- replyFields.put("Replies." + fields[fieldIndex], fields[fieldIndex + 1]);
+ private static class Common {
+
+ protected FcpConnection createConnectionThatSendsOtherMessage() {
+ return createFcpConnection(message -> (listener, connection) -> {
+ Map<String, String> fields = createWebOfTrustReplyFields("OtherMessage", true);
+ FcpMessage replyMessage = createPluginReply(message, fields);
+ listener.receivedFCPPluginReply(connection, new FCPPluginReply(replyMessage, null));
+ });
}
- return replyFields;
- }
- private FcpMessage createPluginReply(FcpMessage pluginMessage, Map<String, String> fields) {
- FcpMessage replyMessage = new FcpMessage("FCPPluginReply");
- replyMessage.setField("Identifier", pluginMessage.getField("Identifier"));
- replyMessage.setField("PluginName", pluginMessage.getField("PluginName"));
- fields.forEach(replyMessage::setField);
- return replyMessage;
- }
+ protected WebOfTrustPlugin createWebOfTrustPlugin(FcpConnection fcpConnection) {
+ return new WebOfTrustPlugin(new FcpClient(fcpConnection));
+ }
- private static TestFcpConnection createFcpConnection(Function<FcpMessage, BiConsumer<FcpListener, FcpConnection>> messageConsumer) {
- return new TestFcpConnection(messageConsumer);
- }
+ protected Map<String, String> createWebOfTrustReplyFields(String message, boolean success, String... fields) {
+ Map<String, String> replyFields = new HashMap<>();
+ replyFields.put("Success", String.valueOf(success));
+ replyFields.put("Replies.Message", message);
+ for (int fieldIndex = 0; fieldIndex < fields.length - 1; fieldIndex += 2) {
+ replyFields.put("Replies." + fields[fieldIndex], fields[fieldIndex + 1]);
+ }
+ return replyFields;
+ }
- @Rule
- public final Timeout timeout = Timeout.seconds(5);
+ protected FcpMessage createPluginReply(FcpMessage pluginMessage, Map<String, String> fields) {
+ FcpMessage replyMessage = new FcpMessage("FCPPluginReply");
+ replyMessage.setField("Identifier", pluginMessage.getField("Identifier"));
+ replyMessage.setField("PluginName", pluginMessage.getField("PluginName"));
+ fields.forEach(replyMessage::setField);
+ return replyMessage;
+ }
+
+ protected TestFcpConnection createFcpConnection(Function<FcpMessage, BiConsumer<FcpListener, FcpConnection>> messageConsumer) {
+ return new TestFcpConnection(messageConsumer);
+ }
+
+ @Rule
+ public final Timeout timeout = Timeout.seconds(5);
+
+ }
}