Skip to content

Commit

Permalink
Merge branch 'main' into feat/RA-64-Containerisation-for-Distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
Kammerlo committed May 7, 2024
2 parents b9f9b66 + 3c42579 commit 697941d
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 13 deletions.
6 changes: 6 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,12 @@
<exclude>**/org/openapitools/**</exclude>
<exclude>**/model/**</exclude>
<exclude>**/entity/**</exclude>
<exclude>**/rosetta/config/**</exclude>
<exclude>**/rosetta/common/enumeration/NetworkId.java</exclude>
<exclude>**/rosetta/common/enumeration/OperationTypeStatus.java</exclude>
<exclude>**/rosetta/common/enumeration/RewardType.java</exclude>
<exclude>**/rosetta/common/enumeration/ScriptPurposetype.java</exclude>
<exclude>**/rosetta/common/enumeration/SyncStateType.java</exclude>
</excludes>
</configuration>
<executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public String getValue() {

@Override
public String toString() {
return String.valueOf(value);
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public String getLabel() {

@Override
public String toString() {
return String.valueOf(label);
return label;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@

public enum NetworkId {
TESTNET,
MAINNET;

private NetworkId() {
}
MAINNET
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@ public enum NetworkIdentifierType {
CARDANO_TESTNET_NETWORK("testnet", 0, 1097911063L),
CARDANO_PREPROD_NETWORK("preprod", 0, 1);

private String networkId;
private int value;
private long protocolMagic;
private final String networkId;
private final int value;
private final long protocolMagic;

NetworkIdentifierType(String networkId, int value, long protocolMagic) {
this.networkId = networkId;
this.value = value;
this.protocolMagic = protocolMagic;
}

NetworkIdentifierType() {
}

/**
* This method will return the NetworkIdentifierType based on the network value
* Thus, if the network value is 0,
* then it will return CARDANO_TESTNET_NETWORK or CARDANO_PREPROD_NETWORK
* (as both of them have the same network value)
*
* @param network - network value identifier
* @return a NetworkIdentifierType Enum instance
*/
public static NetworkIdentifierType find(int network) {
for (NetworkIdentifierType networkIdentifierType : NetworkIdentifierType.values()) {
if (network == networkIdentifierType.getValue()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public String getValue() {

@Override
public String toString() {
return String.valueOf(value);
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.cardanofoundation.rosetta.common.enumeration;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

class AddressTypeTest {

final AddressType[] addressTypes = AddressType.values();

@Test
void findByValue() {
for (AddressType addressType : addressTypes) {
AddressType actual = AddressType.findByValue(addressType.getValue());
assertEquals(addressType, actual);
// check toString() method to return the value
assertEquals(addressType.getValue(), actual.toString());
}
assertNull(AddressType.findByValue("Invalid"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.cardanofoundation.rosetta.common.enumeration;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

class CatalystDataIndexesTest {

final CatalystDataIndexes[] catalystDataIndexes = CatalystDataIndexes.values();

@Test
void findByValue() {
for (CatalystDataIndexes catalystDataIndex : catalystDataIndexes) {
CatalystDataIndexes actual = CatalystDataIndexes.findByValue(catalystDataIndex.getValue());
assertEquals(catalystDataIndex, actual);
assertEquals(String.valueOf(catalystDataIndex.getValue()), actual.toString());
}
assertNull(CatalystDataIndexes.findByValue(0L));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.cardanofoundation.rosetta.common.enumeration;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

class CatalystLabelsTest {

final CatalystLabels[] catalystLabels = CatalystLabels.values();

@Test
void findByValue() {
for (CatalystLabels catalystLabel : catalystLabels) {
CatalystLabels actual = CatalystLabels.findByValue(catalystLabel.getLabel());
assertEquals(catalystLabel, actual);
assertEquals(catalystLabel.getLabel(), actual.toString());
}
assertNull(CatalystLabels.findByValue("Invalid"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.cardanofoundation.rosetta.common.enumeration;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

class NetworkEnumTest {

final NetworkEnum[] networkEnums = NetworkEnum.values();

@Test
void fromValue() {
for (NetworkEnum networkEnum : networkEnums) {
NetworkEnum actual = NetworkEnum.fromValue(networkEnum.getValue());
assertEquals(networkEnum, actual);
}
assertNull(NetworkEnum.fromValue("Invalid"));
}

@Test
void fromProtocolMagic() {
for (NetworkEnum networkEnum : networkEnums) {
NetworkEnum actual = NetworkEnum.fromProtocolMagic(
networkEnum.getNetwork().getProtocolMagic());
assertEquals(networkEnum, actual);
}
assertNull(NetworkEnum.fromProtocolMagic(0L));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.cardanofoundation.rosetta.common.enumeration;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

class NetworkIdentifierTypeTest {

final NetworkIdentifierType[] networkIdentifierTypes = NetworkIdentifierType.values();

@Test
void find() {
assertEquals(NetworkIdentifierType.CARDANO_MAINNET_NETWORK, NetworkIdentifierType.find(1));
assertNull(NetworkIdentifierType.find(100));
}

@Test
void findByName() {
for (NetworkIdentifierType networkIdentifierType : networkIdentifierTypes) {
NetworkIdentifierType actual = NetworkIdentifierType.findByName(networkIdentifierType.getNetworkId());
assertEquals(networkIdentifierType, actual);
}
assertNull(NetworkIdentifierType.findByName("Invalid"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.cardanofoundation.rosetta.common.enumeration;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

class NonStakeAddressPrefixTest {

final NonStakeAddressPrefix[] nonStakeAddressPrefixes = NonStakeAddressPrefix.values();

@Test
void findByValue() {
for (NonStakeAddressPrefix nonStakeAddressPrefix : nonStakeAddressPrefixes) {
NonStakeAddressPrefix actual = NonStakeAddressPrefix.findByValue(
nonStakeAddressPrefix.getValue());
assertEquals(nonStakeAddressPrefix, actual);
assertEquals(String.valueOf(nonStakeAddressPrefix.getValue()), actual.toString());
}
assertNull(NonStakeAddressPrefix.findByValue("Invalid"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.cardanofoundation.rosetta.common.enumeration;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

class OperationTypeTest {

final OperationType[] operationTypes = OperationType.values();

@Test
void fromValue() {
for (OperationType operationType : operationTypes) {
OperationType actual = OperationType.fromValue(operationType.getValue());
assertEquals(operationType, actual);
}
assertNull(OperationType.fromValue("Invalid"));
}
}

0 comments on commit 697941d

Please sign in to comment.