diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java index d4bab3996..2555f44c2 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java @@ -356,38 +356,34 @@ public void testDBSchemasForDashedCatalogNameWithPattern() throws SQLException { @Tag(Constants.xAzureSQLDB) public void testDBSchemasForSchemaPatternWithWildcards() throws SQLException { UUID id = UUID.randomUUID(); - String testCatalog = "catalog" + id; - String[] schemas = {"some_schema", "some%schema", "some[schema"}; - String[] schemaPatterns = {"some\\_schema", "some\\%schema", "some\\[schema"}; + String testCatalog = "dash-catalog" + id; + String testSchema = "some_schema" + id; try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { TestUtils.dropDatabaseIfExists(testCatalog, connectionString); stmt.execute(String.format("CREATE DATABASE [%s]", testCatalog)); stmt.execute(String.format("USE [%s]", testCatalog)); + stmt.execute(String.format("CREATE SCHEMA [%s]", testSchema)); - for (int i = 0; i < schemas.length; ++i) { - stmt.execute(String.format("CREATE SCHEMA [%s]", schemas[i])); - - try (ResultSet rs = conn.getMetaData().getSchemas(testCatalog, schemaPatterns[i])) { - - MessageFormat schemaEmptyFormat = new MessageFormat(TestResource.getResource("R_nameEmpty")); - Object[] schemaMsgArgs = {schemas[i]}; - Object[] catalogMsgArgs = {testCatalog}; + try (ResultSet rs = conn.getMetaData().getSchemas(testCatalog, "some\\_%")) { - boolean hasResults = false; - while (rs.next()) { - hasResults = true; - String schemaName = rs.getString(1); - String catalogName = rs.getString(2); - assertTrue(!StringUtils.isEmpty(schemaName), schemaEmptyFormat.format(schemaMsgArgs)); - assertTrue(!StringUtils.isEmpty(catalogName), schemaEmptyFormat.format(catalogMsgArgs)); - assertEquals(schemaName, schemaMsgArgs[0]); - assertEquals(catalogName, catalogMsgArgs[0]); - } + MessageFormat schemaEmptyFormat = new MessageFormat(TestResource.getResource("R_nameEmpty")); + Object[] schemaMsgArgs = {testSchema}; + Object[] catalogMsgArgs = {testCatalog}; - MessageFormat atLeastOneFoundFormat = new MessageFormat(TestResource.getResource("R_atLeastOneFound")); - assertTrue(hasResults, atLeastOneFoundFormat.format(schemaMsgArgs)); + boolean hasResults = false; + while (rs.next()) { + hasResults = true; + String schemaName = rs.getString(1); + String catalogName = rs.getString(2); + assertTrue(!StringUtils.isEmpty(schemaName), schemaEmptyFormat.format(schemaMsgArgs)); + assertTrue(!StringUtils.isEmpty(catalogName), schemaEmptyFormat.format(catalogMsgArgs)); + assertEquals(schemaName, schemaMsgArgs[0]); + assertEquals(catalogName, catalogMsgArgs[0]); } + + MessageFormat atLeastOneFoundFormat = new MessageFormat(TestResource.getResource("R_atLeastOneFound")); + assertTrue(hasResults, atLeastOneFoundFormat.format(schemaMsgArgs)); } } catch (Exception e) { fail(TestResource.getResource("R_unexpectedErrorMessage") + e.getMessage());