From 70cc22b10e526f3b2f155f0f3b08477cd4215c22 Mon Sep 17 00:00:00 2001 From: zhangliang Date: Tue, 24 Sep 2024 12:30:21 +0800 Subject: [PATCH] Add more test cases on DatabaseMetaDataNode --- .../node/DatabaseMetaDataNodeTest.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/kernel/metadata/core/src/test/java/org/apache/shardingsphere/metadata/persist/node/DatabaseMetaDataNodeTest.java b/kernel/metadata/core/src/test/java/org/apache/shardingsphere/metadata/persist/node/DatabaseMetaDataNodeTest.java index 9d03e62b7672b..6ae6e5134f5b6 100644 --- a/kernel/metadata/core/src/test/java/org/apache/shardingsphere/metadata/persist/node/DatabaseMetaDataNodeTest.java +++ b/kernel/metadata/core/src/test/java/org/apache/shardingsphere/metadata/persist/node/DatabaseMetaDataNodeTest.java @@ -23,10 +23,31 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; class DatabaseMetaDataNodeTest { + @Test + void assertGetDatabaseNamePath() { + assertThat(DatabaseMetaDataNode.getDatabaseNamePath("foo_db"), is("/metadata/foo_db")); + } + + @Test + void assertGetMetaDataSchemaPath() { + assertThat(DatabaseMetaDataNode.getMetaDataSchemaPath("foo_db", "foo_schema"), is("/metadata/foo_db/schemas/foo_schema")); + } + + @Test + void assertGetMetaDataSchemasPath() { + assertThat(DatabaseMetaDataNode.getMetaDataSchemasPath("foo_db"), is("/metadata/foo_db/schemas")); + } + + @Test + void assertGetMetaDataTablesPath() { + assertThat(DatabaseMetaDataNode.getMetaDataTablesPath("foo_db", "foo_schema"), is("/metadata/foo_db/schemas/foo_schema/tables")); + } + @Test void assertGetDatabaseName() { Optional actual = DatabaseMetaDataNode.getDatabaseName("/metadata/foo_db"); @@ -34,6 +55,11 @@ void assertGetDatabaseName() { assertThat(actual.get(), is("foo_db")); } + @Test + void assertGetDatabaseNameIfNotFound() { + assertFalse(DatabaseMetaDataNode.getDatabaseName("/metadata").isPresent()); + } + @Test void assertGetDatabaseNameBySchemaNode() { Optional actual = DatabaseMetaDataNode.getDatabaseNameBySchemaNode("/metadata/foo_db/schemas/foo_schema"); @@ -41,6 +67,11 @@ void assertGetDatabaseNameBySchemaNode() { assertThat(actual.get(), is("foo_db")); } + @Test + void assertGetDatabaseNameBySchemaNodeIfNotFound() { + assertFalse(DatabaseMetaDataNode.getDatabaseNameBySchemaNode("/xxx/foo_db").isPresent()); + } + @Test void assertGetSchemaName() { Optional actual = DatabaseMetaDataNode.getSchemaName("/metadata/foo_db/schemas/foo_schema"); @@ -48,10 +79,30 @@ void assertGetSchemaName() { assertThat(actual.get(), is("foo_schema")); } + @Test + void assertGetSchemaNameIfNotFound() { + assertFalse(DatabaseMetaDataNode.getSchemaName("/metadata/foo_db/xxx/foo_schema").isPresent()); + } + @Test void assertGetSchemaNameByTableNode() { Optional actual = DatabaseMetaDataNode.getSchemaNameByTableNode("/metadata/foo_db/schemas/foo_schema/tables"); assertTrue(actual.isPresent()); assertThat(actual.get(), is("foo_schema")); } + + @Test + void assertGetSchemaNameByTableNodeIfNotFound() { + assertFalse(DatabaseMetaDataNode.getSchemaNameByTableNode("/xxx/foo_db/schemas/foo_schema/tables").isPresent()); + } + + @Test + void assertGetVersionNodeByActiveVersionPath() { + assertThat(DatabaseMetaDataNode.getVersionNodeByActiveVersionPath("foo_rule", "1"), is("foo_rule/1")); + } + + @Test + void assertGetMetaDataNode() { + assertThat(DatabaseMetaDataNode.getMetaDataNode(), is("/metadata")); + } }