Skip to content

Commit 45cc405

Browse files
marko-bekhtasebersole
authored andcommitted
HHH-19183 Add NamingHelper tests
1 parent 7bc86c7 commit 45cc405

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* SPDX-License-Identifier: LGPL-2.1-or-later
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.bootstrap.binding.naming;
6+
7+
import org.hibernate.boot.model.naming.Identifier;
8+
import org.hibernate.boot.model.naming.NamingHelper;
9+
import org.junit.jupiter.params.ParameterizedTest;
10+
import org.junit.jupiter.params.provider.Arguments;
11+
import org.junit.jupiter.params.provider.MethodSource;
12+
13+
import java.nio.charset.StandardCharsets;
14+
import java.util.List;
15+
import java.util.stream.Collectors;
16+
import java.util.stream.Stream;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
20+
class NamingHelperTest {
21+
22+
@ParameterizedTest
23+
@MethodSource("args")
24+
void smoke(String charset, String prefix, String tableName, String referencedTableName, List<String> columnNames, String expectedFkName, String expectedConstraintName) {
25+
assertThat( NamingHelper.withCharset( charset )
26+
.generateHashedFkName(
27+
prefix,
28+
Identifier.toIdentifier( tableName ),
29+
Identifier.toIdentifier( referencedTableName ),
30+
columnNames.stream().map( Identifier::toIdentifier )
31+
.collect( Collectors.toUnmodifiableList() ) ) )
32+
.isEqualTo( expectedFkName );
33+
34+
assertThat( NamingHelper.withCharset( charset )
35+
.generateHashedFkName(
36+
prefix,
37+
Identifier.toIdentifier( tableName ),
38+
Identifier.toIdentifier( referencedTableName ),
39+
columnNames.stream().map( Identifier::toIdentifier )
40+
.toArray( Identifier[]::new ) ) )
41+
.isEqualTo( expectedFkName );
42+
43+
assertThat( NamingHelper.withCharset( charset )
44+
.generateHashedConstraintName(
45+
prefix,
46+
Identifier.toIdentifier( tableName ),
47+
columnNames.stream().map( Identifier::toIdentifier )
48+
.collect( Collectors.toUnmodifiableList() ) ) )
49+
.isEqualTo( expectedConstraintName );
50+
51+
assertThat( NamingHelper.withCharset( charset )
52+
.generateHashedConstraintName(
53+
prefix,
54+
Identifier.toIdentifier( tableName ),
55+
columnNames.stream().map( Identifier::toIdentifier )
56+
.toArray( Identifier[]::new ) ) )
57+
.isEqualTo( expectedConstraintName );
58+
}
59+
60+
private static Stream<Arguments> args() {
61+
// String charset, String prefix, String tableName, String referencedTableName,
62+
// List<String> columnNames, String expectedFkName, String expectedConstraintName
63+
return Stream.of(
64+
Arguments.of(
65+
StandardCharsets.UTF_8.name(),
66+
"fk_", "table_name", "other_table_name", List.of( "col1", "col2", "col3" ),
67+
"fk_f4u43ook9b825fxbm3exb18q6", "fk_1o8k3sa4q2a2wb596v4htt8qf" ),
68+
Arguments.of(
69+
StandardCharsets.ISO_8859_1.name(),
70+
"fk_", "table_name", "other_table_name", List.of( "col1", "col2", "col3" ),
71+
"fk_f4u43ook9b825fxbm3exb18q6", "fk_1o8k3sa4q2a2wb596v4htt8qf" ),
72+
Arguments.of(
73+
StandardCharsets.UTF_8.name(),
74+
"fk_", "café", "le_déjeuner", List.of( "col1", "col2", "col3" ),
75+
"fk_jdvsrk14lxab6a829ok160vyj", "fk_h34kugb2bguwmcn1g5h1q3snf" ),
76+
Arguments.of(
77+
StandardCharsets.ISO_8859_1.name(),
78+
"fk_", "café", "le_déjeuner", List.of( "col1", "col2", "col3" ),
79+
"fk_g1py0mkjd1tu46tr8c2e1vm2l", "fk_1pitt5gtytwpy6ea02o7l5men" ),
80+
Arguments.of(
81+
StandardCharsets.UTF_8.name(),
82+
"fk_", "abcdefghijklmnopqrstuvwxyzäöüß", "stuvwxyzäöüß", List.of( "col1" ),
83+
"fk_q11mlivmrc3sdfnncd2hwkpqp", "fk_gm8xsqu7ayucv5w5w2gj2dfly" ),
84+
Arguments.of(
85+
StandardCharsets.ISO_8859_1.name(),
86+
"fk_", "abcdefghijklmnopqrstuvwxyzäöüß", "stuvwxyzäöüß", List.of( "col1" )
87+
, "fk_fua9hgc6dn6eno8hlqt58j72o", "fk_3iig3yrgsf5bjlbdo05d7mp2" )
88+
);
89+
}
90+
91+
}

0 commit comments

Comments
 (0)