|
| 1 | +package com.baeldung.naming; |
| 2 | + |
| 3 | +import com.baeldung.naming.entity.Account; |
| 4 | +import org.assertj.core.api.SoftAssertions; |
| 5 | +import org.hibernate.boot.Metadata; |
| 6 | +import org.hibernate.mapping.PersistentClass; |
| 7 | +import org.hibernate.mapping.Table; |
| 8 | +import org.junit.Test; |
| 9 | +import org.junit.runner.RunWith; |
| 10 | +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
| 11 | +import org.springframework.test.context.TestPropertySource; |
| 12 | +import org.springframework.test.context.junit4.SpringRunner; |
| 13 | + |
| 14 | +@RunWith(SpringRunner.class) |
| 15 | +@DataJpaTest |
| 16 | +@TestPropertySource(properties = { |
| 17 | + "spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl", |
| 18 | + "spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl" |
| 19 | +}) |
| 20 | +public class LegacyJpaImplNamingIntegrationTest extends NamingConfig { |
| 21 | + |
| 22 | + @Test |
| 23 | + public void givenLegacyJpaImplNamingStrategy_whenCreateDatabase_thenGetStrategyNames() { |
| 24 | + Metadata metadata = MetadataExtractorIntegrator.INSTANCE.getMetadata(); |
| 25 | + String entity = Account.class.getCanonicalName(); |
| 26 | + PersistentClass persistentClass = metadata.getEntityBinding(entity); |
| 27 | + Table table = persistentClass.getTable(); |
| 28 | + String physicalNameExpected = "Secondary_Email"; |
| 29 | + String implicitNameExpected = "defaultEmail"; |
| 30 | + String tableNameExpected = "Account"; |
| 31 | + |
| 32 | + String tableNameCreated = table.getName(); |
| 33 | + boolean columnNameIsQuoted = table |
| 34 | + .getColumn(3) |
| 35 | + .isQuoted(); |
| 36 | + String physicalNameCreated = table |
| 37 | + .getColumn(3) |
| 38 | + .getName(); |
| 39 | + String implicitNameCreated = table |
| 40 | + .getColumn(2) |
| 41 | + .getName(); |
| 42 | + |
| 43 | + SoftAssertions.assertSoftly(softly -> { |
| 44 | + softly |
| 45 | + .assertThat(columnNameIsQuoted) |
| 46 | + .isTrue(); |
| 47 | + softly |
| 48 | + .assertThat(tableNameCreated) |
| 49 | + .isEqualTo(tableNameExpected); |
| 50 | + softly |
| 51 | + .assertThat(physicalNameCreated) |
| 52 | + .isEqualTo(physicalNameExpected); |
| 53 | + softly |
| 54 | + .assertThat(implicitNameCreated) |
| 55 | + .isEqualTo(implicitNameExpected); |
| 56 | + }); |
| 57 | + } |
| 58 | +} |
0 commit comments