Skip to content

Commit

Permalink
Merge pull request #1579 from corda/tlawson/ES-2045/enumsForConfigValues
Browse files Browse the repository at this point in the history
ES-2045: Create Enum for ConfigKeys
  • Loading branch information
tlawson3 authored Mar 26, 2024
2 parents f0a3a49 + 6a0299f commit 40a136a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,44 @@ private ConfigKeys() {
public static final String SECURITY_CONFIG = "corda.security";
public static final String VNODE_DATASOURCE_CONFIG = "corda.vnode.datasource";

// An enum to hold all the root config keys
public enum RootConfigKey {

BOOT(BOOT_CONFIG),
CRYPTO(CRYPTO_CONFIG),
DB(DB_CONFIG),
FLOW(FLOW_CONFIG),
MESSAGING(MESSAGING_CONFIG),
EXTERNAL_MESSAGING(EXTERNAL_MESSAGING_CONFIG),
STATE_MANAGER(STATE_MANAGER_CONFIG),
UTXO_LEDGER(UTXO_LEDGER_CONFIG),
P2P_LINK_MANAGER(P2P_LINK_MANAGER_CONFIG),
P2P_GATEWAY(P2P_GATEWAY_CONFIG),
REST(REST_CONFIG),
RBAC(RBAC_CONFIG),
SECRETS(SECRETS_CONFIG),
SANDBOX(SANDBOX_CONFIG),
RECONCILIATION(RECONCILIATION_CONFIG),
MEMBERSHIP(MEMBERSHIP_CONFIG),
SECURITY(SECURITY_CONFIG),
VNODE_DATASOURCE(VNODE_DATASOURCE_CONFIG);

private final String value;

RootConfigKey(String value) {
this.value = value;
}

public String getValue() {
return value;
}

@Override
public String toString() {
return getValue();
}
}

// REST
public static final String REST_ADDRESS = "address";
public static final String REST_CONTEXT_DESCRIPTION = "context.description";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
package net.corda.schema.configuration.provider.impl

import net.corda.schema.configuration.ConfigKeys.CRYPTO_CONFIG
import net.corda.schema.configuration.ConfigKeys.DB_CONFIG
import net.corda.schema.configuration.ConfigKeys.EXTERNAL_MESSAGING_CONFIG
import net.corda.schema.configuration.ConfigKeys.FLOW_CONFIG
import net.corda.schema.configuration.ConfigKeys.MEMBERSHIP_CONFIG
import net.corda.schema.configuration.ConfigKeys.MESSAGING_CONFIG
import net.corda.schema.configuration.ConfigKeys.P2P_GATEWAY_CONFIG
import net.corda.schema.configuration.ConfigKeys.P2P_LINK_MANAGER_CONFIG
import net.corda.schema.configuration.ConfigKeys.RBAC_CONFIG
import net.corda.schema.configuration.ConfigKeys.RECONCILIATION_CONFIG
import net.corda.schema.configuration.ConfigKeys.REST_CONFIG
import net.corda.schema.configuration.ConfigKeys.SANDBOX_CONFIG
import net.corda.schema.configuration.ConfigKeys.SECRETS_CONFIG
import net.corda.schema.configuration.ConfigKeys.STATE_MANAGER_CONFIG
import net.corda.schema.configuration.ConfigKeys.UTXO_LEDGER_CONFIG
import net.corda.schema.configuration.ConfigKeys.RootConfigKey
import net.corda.schema.configuration.provider.ConfigSchemaException
import net.corda.schema.configuration.provider.SchemaProviderConfigFactory
import net.corda.v5.base.versioning.Version
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
Expand All @@ -24,29 +11,12 @@ import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.Arguments.arguments
import org.junit.jupiter.params.provider.MethodSource
import java.util.stream.Stream
import net.corda.schema.configuration.provider.SchemaProviderConfigFactory

class SchemaProviderConfigImplTest {

companion object {
// All the top level config keys excluding the boot config, which is handled differently.
private val CONFIG_KEYS = listOf(
CRYPTO_CONFIG,
DB_CONFIG,
FLOW_CONFIG,
MESSAGING_CONFIG,
EXTERNAL_MESSAGING_CONFIG,
UTXO_LEDGER_CONFIG,
P2P_LINK_MANAGER_CONFIG,
P2P_GATEWAY_CONFIG,
REST_CONFIG,
RBAC_CONFIG,
SECRETS_CONFIG,
SANDBOX_CONFIG,
RECONCILIATION_CONFIG,
MEMBERSHIP_CONFIG,
STATE_MANAGER_CONFIG
)
private val CONFIG_KEYS = RootConfigKey.values().filterNot { it == RootConfigKey.BOOT }
private val VERSIONS = listOf("1.0")

// This is a bit dubious as it assumes that all keys will update schema version at the same time. Either this is
Expand All @@ -55,7 +25,7 @@ class SchemaProviderConfigImplTest {
@JvmStatic
private fun schemaSources(): Stream<Arguments> {
return CONFIG_KEYS.stream().flatMap { key ->
VERSIONS.stream().map { version -> arguments(key, version) }
VERSIONS.stream().map { version -> arguments(key.value, version) }
}
}

Expand Down Expand Up @@ -85,7 +55,7 @@ class SchemaProviderConfigImplTest {
fun `throws if provided version is not valid`() {
val provider = SchemaProviderConfigFactory.getSchemaProvider()
assertThrows<ConfigSchemaException> {
provider.getSchema(MESSAGING_CONFIG, Version(0, 0))
provider.getSchema(RootConfigKey.MESSAGING.value, Version(0, 0))
}
}

Expand Down

0 comments on commit 40a136a

Please sign in to comment.