Skip to content

Commit daedadc

Browse files
committed
HHH-19307 - Test for issue
Signed-off-by: Jan Schatteman <jschatte@redhat.com>
1 parent 09550e1 commit daedadc

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed

Diff for: hibernate-core/src/test/java/org/hibernate/orm/test/jpa/boot/BootFailureTest.java

+14-3
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@
1111
import java.util.HashMap;
1212
import java.util.List;
1313
import java.util.Map;
14+
1415
import jakarta.persistence.EntityManagerFactory;
1516
import jakarta.persistence.Persistence;
1617

18+
import org.hibernate.HibernateException;
1719
import org.hibernate.cfg.AvailableSettings;
1820
import org.hibernate.service.spi.ServiceException;
1921

2022
import org.hibernate.testing.boot.ClassLoaderServiceTestingImpl;
21-
import org.junit.jupiter.api.Assertions;
2223
import org.junit.jupiter.api.Test;
2324

25+
import static org.junit.jupiter.api.Assertions.assertThrows;
26+
2427
/**
2528
* Test to verify that a dump configuration error results in an exception being
2629
* thrown even when booting via the standard JPA boostrap API.
@@ -32,16 +35,24 @@ public class BootFailureTest {
3235

3336
@Test
3437
public void exceptionOnIllegalPUTest() {
35-
Assertions.assertThrows( ServiceException.class, () ->
38+
assertThrows( ServiceException.class, () ->
3639
bootstrapPersistenceUnit( "IntentionallyBroken" ) );
3740
}
3841

3942
@Test
4043
public void exceptionOnIllegalPUWithoutProviderTest() {
41-
Assertions.assertThrows( ServiceException.class, () ->
44+
assertThrows( ServiceException.class, () ->
4245
bootstrapPersistenceUnit( "IntentionallyBrokenWihoutExplicitProvider" ) );
4346
}
4447

48+
@Test
49+
public void missingClassPUTest() {
50+
assertThrows( HibernateException.class, () ->
51+
bootstrapPersistenceUnit( "IntentionallyMissingClass" ),
52+
"A HibernateException due to a missing class in the persistence.xml should have been thrown"
53+
);
54+
}
55+
4556
private void bootstrapPersistenceUnit(final String puName) {
4657
final Map<String, Object> properties = new HashMap<>();
4758
properties.put( AvailableSettings.CLASSLOADERS, Arrays.asList( new TestClassLoader() ) );
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.jpa.boot;
6+
7+
8+
import jakarta.persistence.Entity;
9+
import jakarta.persistence.Id;
10+
import jakarta.persistence.OneToOne;
11+
12+
/**
13+
* @author Jan Schatteman
14+
*/
15+
@Entity(name = "Event")
16+
public class Event {
17+
@Id
18+
@OneToOne
19+
private EventId id;
20+
21+
public EventId getId() {
22+
return id;
23+
}
24+
25+
public void setId(EventId id) {
26+
this.id = id;
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.jpa.boot;
6+
7+
8+
import jakarta.persistence.Entity;
9+
import jakarta.persistence.GeneratedValue;
10+
import jakarta.persistence.Id;
11+
12+
/**
13+
* @author Jan Schatteman
14+
*/
15+
@Entity(name = "EventId")
16+
public class EventId {
17+
18+
@Id
19+
@GeneratedValue
20+
private Long id;
21+
22+
}

Diff for: hibernate-core/src/test/resources/org/hibernate/orm/test/jpa/boot/META-INF/persistence.xml

+5
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@
2525
</properties>
2626
</persistence-unit>
2727

28+
<persistence-unit name="IntentionallyMissingClass">
29+
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
30+
<class>org.hibernate.orm.test.jpa.boot.Event</class>
31+
</persistence-unit>
32+
2833
</persistence>

0 commit comments

Comments
 (0)