Skip to content

Commit 75db26f

Browse files
committed
HHH-10174 - Add test for issue
1 parent 4ff1dcb commit 75db26f

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.test.boot.model.relational;
8+
9+
import org.hibernate.boot.model.naming.Identifier;
10+
import org.hibernate.boot.model.relational.QualifiedNameParser;
11+
12+
import org.junit.Test;
13+
14+
import org.hibernate.testing.TestForIssue;
15+
16+
import static org.hamcrest.CoreMatchers.is;
17+
import static org.hamcrest.CoreMatchers.nullValue;
18+
import static org.junit.Assert.assertThat;
19+
20+
/**
21+
* @author Andrea Boriero
22+
*/
23+
@TestForIssue(jiraKey = "HHH-10174")
24+
public class QualifiedNameParserTest {
25+
26+
private static final Identifier DEFAULT_SCHEMA = Identifier.toIdentifier( "schema" );
27+
private static final Identifier DEFAULT_CATALOG = Identifier.toIdentifier( "catalog" );
28+
29+
private static final QualifiedNameParser PARSER = new QualifiedNameParser();
30+
31+
@Test
32+
public void testStringSplittingWithSchema() {
33+
QualifiedNameParser.NameParts nameParts = PARSER.parse( "schema.MyEntity", null, DEFAULT_SCHEMA );
34+
35+
assertThat( nameParts.getCatalogName(), is( nullValue() ) );
36+
assertThat( nameParts.getSchemaName().getText(), is( DEFAULT_SCHEMA.getText() ) );
37+
assertThat( nameParts.getObjectName().getText(), is( "MyEntity" ) );
38+
}
39+
40+
@Test
41+
public void testStringSplittingWithCatalogAndSchema() {
42+
QualifiedNameParser.NameParts nameParts = PARSER.parse(
43+
"schema.catalog.MyEntity",
44+
DEFAULT_CATALOG,
45+
DEFAULT_SCHEMA
46+
);
47+
48+
assertThat( nameParts.getCatalogName().getText(), is( DEFAULT_CATALOG.getText() ) );
49+
assertThat( nameParts.getSchemaName().getText(), is( DEFAULT_SCHEMA.getText() ) );
50+
assertThat( nameParts.getObjectName().getText(), is( "MyEntity" ) );
51+
}
52+
53+
@Test
54+
public void testStringSplittingWithoutCatalogAndSchema() {
55+
QualifiedNameParser.NameParts nameParts = PARSER.parse(
56+
"MyEntity",
57+
null,
58+
null
59+
);
60+
61+
assertThat( nameParts.getCatalogName(), is( nullValue() ) );
62+
assertThat( nameParts.getSchemaName(), is( nullValue() ) );
63+
assertThat( nameParts.getObjectName().getText(), is( "MyEntity" ) );
64+
}
65+
}

0 commit comments

Comments
 (0)