Skip to content

Commit

Permalink
Add more test cases on DatabaseMetaDataNode
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Sep 24, 2024
1 parent 8365016 commit 70cc22b
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,86 @@

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<String> actual = DatabaseMetaDataNode.getDatabaseName("/metadata/foo_db");
assertTrue(actual.isPresent());
assertThat(actual.get(), is("foo_db"));
}

@Test
void assertGetDatabaseNameIfNotFound() {
assertFalse(DatabaseMetaDataNode.getDatabaseName("/metadata").isPresent());
}

@Test
void assertGetDatabaseNameBySchemaNode() {
Optional<String> actual = DatabaseMetaDataNode.getDatabaseNameBySchemaNode("/metadata/foo_db/schemas/foo_schema");
assertTrue(actual.isPresent());
assertThat(actual.get(), is("foo_db"));
}

@Test
void assertGetDatabaseNameBySchemaNodeIfNotFound() {
assertFalse(DatabaseMetaDataNode.getDatabaseNameBySchemaNode("/xxx/foo_db").isPresent());
}

@Test
void assertGetSchemaName() {
Optional<String> actual = DatabaseMetaDataNode.getSchemaName("/metadata/foo_db/schemas/foo_schema");
assertTrue(actual.isPresent());
assertThat(actual.get(), is("foo_schema"));
}

@Test
void assertGetSchemaNameIfNotFound() {
assertFalse(DatabaseMetaDataNode.getSchemaName("/metadata/foo_db/xxx/foo_schema").isPresent());
}

@Test
void assertGetSchemaNameByTableNode() {
Optional<String> 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"));
}
}

0 comments on commit 70cc22b

Please sign in to comment.