-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1117 from jpmorganchase/partyinfo_domain_seperation
Partyinfo communication-domain seperation
- Loading branch information
Showing
84 changed files
with
948 additions
and
408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
dependencies { | ||
implementation project(':tessera-partyinfo') | ||
implementation project(':encryption:encryption-api') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.jpmorgan.quorum</groupId> | ||
<artifactId>tessera-jaxrs</artifactId> | ||
<version>0.10.7-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>partyinfo-model</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.jpmorgan.quorum</groupId> | ||
<artifactId>tessera-partyinfo</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
29 changes: 29 additions & 0 deletions
29
...-jaxrs/partyinfo-model/src/main/java/com/quorum/tessera/partyinfo/model/NodeInfoUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.quorum.tessera.partyinfo.model; | ||
|
||
import com.quorum.tessera.partyinfo.node.NodeInfo; | ||
import com.quorum.tessera.partyinfo.node.Recipient; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public interface NodeInfoUtil { | ||
|
||
static NodeInfo from(PartyInfo partyInfo, Collection<String> versions) { | ||
|
||
List<Recipient> recipients = partyInfo.getRecipients().stream() | ||
.map(r -> Recipient.of(r.getKey(),r.getUrl())).collect(Collectors.toList()); | ||
|
||
List<com.quorum.tessera.partyinfo.node.Party> parties = partyInfo.getParties().stream() | ||
.map(Party::getUrl).map(com.quorum.tessera.partyinfo.node.Party::new).collect(Collectors.toList()); | ||
|
||
return NodeInfo.Builder.create() | ||
.withUrl(partyInfo.getUrl()) | ||
.withRecipients(recipients) | ||
.withParties(parties) | ||
.withSupportedApiVersions(versions) | ||
.build(); | ||
|
||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
tessera-jaxrs/partyinfo-model/src/main/java/com/quorum/tessera/partyinfo/model/Party.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.quorum.tessera.partyinfo.model; | ||
|
||
import com.quorum.tessera.partyinfo.URLNormalizer; | ||
import java.time.Instant; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Contains a URL of another known node on the network | ||
*/ | ||
public class Party { | ||
|
||
private final String url; | ||
|
||
private Instant lastContacted; | ||
|
||
public Party(final String url) { | ||
this.url = URLNormalizer.create().normalize(url); | ||
} | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
|
||
@Override | ||
public final boolean equals(final Object o) { | ||
return (o instanceof Party) && Objects.equals(url, ((Party) o).url); | ||
} | ||
|
||
@Override | ||
public final int hashCode() { | ||
return Objects.hash(url); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Party{" + "url=" + url + '}'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
38 changes: 38 additions & 0 deletions
38
...rs/partyinfo-model/src/test/java/com/quorum/tessera/partyinfo/model/NodeInfoUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.quorum.tessera.partyinfo.model; | ||
|
||
import com.quorum.tessera.encryption.PublicKey; | ||
import com.quorum.tessera.partyinfo.node.NodeInfo; | ||
import com.quorum.tessera.partyinfo.node.VersionInfo; | ||
import org.junit.Test; | ||
|
||
import java.util.Set; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class NodeInfoUtilTest { | ||
|
||
@Test | ||
public void from() { | ||
|
||
PartyInfo partyInfo = mock(PartyInfo.class); | ||
VersionInfo versionInfo = mock(VersionInfo.class); | ||
Recipient recipient = Recipient.of(mock(PublicKey.class),"someurl"); | ||
|
||
when(partyInfo.getUrl()).thenReturn("someurl"); | ||
when(versionInfo.supportedApiVersions()).thenReturn(Set.of("v1","v3")); | ||
when(partyInfo.getRecipients()).thenReturn(Set.of(recipient)); | ||
|
||
|
||
NodeInfo nodeInfo = NodeInfoUtil.from(partyInfo,Set.of("v1","v3")); | ||
|
||
assertThat(nodeInfo).isNotNull(); | ||
|
||
assertThat(nodeInfo.getUrl()).isEqualTo("someurl"); | ||
assertThat(nodeInfo.supportedApiVersions()).isEqualTo(Set.of("v3","v1")); | ||
assertThat(nodeInfo.getRecipients()).hasSize(1); | ||
assertThat(nodeInfo.getRecipients().iterator().next().getUrl()).isEqualTo("someurl"); | ||
|
||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...jaxrs/partyinfo-model/src/test/java/com/quorum/tessera/partyinfo/model/PartyInfoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.quorum.tessera.partyinfo.model; | ||
|
||
import com.quorum.tessera.partyinfo.node.NodeInfo; | ||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
|
||
public class PartyInfoTest { | ||
|
||
@Test | ||
public void createSimple() { | ||
String url = "someurl"; | ||
Set<Recipient> recipients = Set.of(mock(Recipient.class)); | ||
Set<Party> parties = Set.of(mock(Party.class)); | ||
|
||
PartyInfo partyInfo = new PartyInfo(url,recipients,parties); | ||
|
||
assertThat(partyInfo.getParties()).isEqualTo(parties); | ||
assertThat(partyInfo.getRecipients()).isEqualTo(recipients); | ||
assertThat(partyInfo.getUrl()).isSameAs(url); | ||
|
||
} | ||
|
||
@Test | ||
public void fromNodeInfo() { | ||
com.quorum.tessera.partyinfo.node.Recipient recipient = mock(com.quorum.tessera.partyinfo.node.Recipient.class); | ||
|
||
NodeInfo nodeInfo = NodeInfo.Builder.create() | ||
.withUrl("url") | ||
.withRecipients(List.of(recipient)) | ||
.build(); | ||
|
||
PartyInfo partyInfo = PartyInfo.from(nodeInfo); | ||
assertThat(partyInfo.getUrl()).isEqualTo("url"); | ||
} | ||
|
||
} |
Oops, something went wrong.