diff --git a/backend/src/main/java/djmil/cordacheckers/cordaclient/pojo/holdingIdentity.java b/backend/src/main/java/djmil/cordacheckers/cordaclient/pojo/holdingIdentity.java index 3ecdce1..f2b88c9 100644 --- a/backend/src/main/java/djmil/cordacheckers/cordaclient/pojo/holdingIdentity.java +++ b/backend/src/main/java/djmil/cordacheckers/cordaclient/pojo/holdingIdentity.java @@ -1,6 +1,22 @@ package djmil.cordacheckers.cordaclient.pojo; +import javax.naming.InvalidNameException; +import javax.naming.ldap.LdapName; +import javax.naming.ldap.Rdn; + import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonIgnoreProperties(ignoreUnknown = true) -public record holdingIdentity(String x500Name, String shortHash) { } +public record holdingIdentity(String x500Name, String shortHash) { + public String getName() throws InvalidNameException { + LdapName ln = new LdapName(x500Name); + + for(Rdn rdn : ln.getRdns()) { + if(rdn.getType().equalsIgnoreCase("CN")) { + return rdn.getValue().toString(); + } + } + + throw new IllegalArgumentException("CN was not found"); + } +} diff --git a/backend/src/test/java/djmil/cordacheckers/CordaClientTest.java b/backend/src/test/java/djmil/cordacheckers/CordaClientTest.java new file mode 100644 index 0000000..4821dc8 --- /dev/null +++ b/backend/src/test/java/djmil/cordacheckers/CordaClientTest.java @@ -0,0 +1,33 @@ +package djmil.cordacheckers; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import djmil.cordacheckers.cordaclient.CordaClient; +import djmil.cordacheckers.cordaclient.pojo.holdingIdentity; +import djmil.cordacheckers.cordaclient.pojo.virtualNodes; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.util.List; + +import javax.naming.InvalidNameException; + +@SpringBootTest +public class CordaClientTest { + @Autowired + CordaClient cordaclient; + + @Test + void whenGetVirtualnode_thenListHoldingIdentity() throws GeneralSecurityException, IOException, InvalidNameException { + List vNodes = cordaclient.getVirtualnode(); + + holdingIdentity identity = vNodes.get(0).holdingIdentity(); + assertThat(identity.getName()).isEqualTo("NotaryRep1"); + } + +}