From 446eb2d6ba5aff36a5dccdc8127a9f4fc2c15c87 Mon Sep 17 00:00:00 2001 From: Koen Aers Date: Fri, 23 Jun 2023 10:14:34 +0200 Subject: [PATCH] HBX-2390: Create a JBoss Tools adaptation layer in Hibernate Tools - Add new interface method 'org.hibernate.tool.orm.jbt.wrp.ConfigurationWrapperFactory.ConfigurationWrapper#setPreferBasicCompositeIds(boolean)' - Add new test case 'org.hibernate.tool.orm.jbt.wrp.ConfigurationWrapperFactoryTest#testSetPreferBasicCompositeIds()' Signed-off-by: Koen Aers --- .../jbt/wrp/ConfigurationWrapperFactory.java | 1 + .../wrp/ConfigurationWrapperFactoryTest.java | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/wrp/ConfigurationWrapperFactory.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/wrp/ConfigurationWrapperFactory.java index 2a321a5735..3fdc918c80 100644 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/wrp/ConfigurationWrapperFactory.java +++ b/jbt/src/main/java/org/hibernate/tool/orm/jbt/wrp/ConfigurationWrapperFactory.java @@ -61,6 +61,7 @@ static interface ConfigurationWrapper extends Wrapper { void buildMappings(); SessionFactory buildSessionFactory(); Iterator getClassMappings(); + void setPreferBasicCompositeIds(boolean b); } static class ConfigurationWrapperInvocationHandler implements InvocationHandler { diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/ConfigurationWrapperFactoryTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/ConfigurationWrapperFactoryTest.java index 669223be04..99215f848c 100644 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/ConfigurationWrapperFactoryTest.java +++ b/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/ConfigurationWrapperFactoryTest.java @@ -42,6 +42,7 @@ import org.hibernate.tool.orm.jbt.util.RevengConfiguration; import org.hibernate.tool.orm.jbt.wrp.ConfigurationWrapperFactory.ConfigurationWrapper; import org.hibernate.tool.orm.jbt.wrp.ConfigurationWrapperFactory.JpaConfigurationWrapperImpl; +import org.hibernate.tool.orm.jbt.wrp.ConfigurationWrapperFactory.NativeConfigurationWrapperImpl; import org.hibernate.tool.orm.jbt.wrp.ConfigurationWrapperFactory.RevengConfigurationWrapperImpl; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; @@ -605,6 +606,33 @@ public void testGetClassMappings() throws Exception { assertEquals(fooClassFacade.getEntityName(), FooBar.class.getName()); } + @Test + public void testSetPreferBasicCompositeIds() { + // For native configuration + try { + nativeConfigurationWrapper.setPreferBasicCompositeIds(false); + fail(); + } catch (RuntimeException e) { + assertEquals( + e.getMessage(), + "Method 'setPreferBasicCompositeIds' should not be called on instances of " + NativeConfigurationWrapperImpl.class.getName()); + } + // For reveng configuration + // the default is true + assertTrue(((RevengConfiguration)wrappedRevengConfiguration).preferBasicCompositeIds()); + revengConfigurationWrapper.setPreferBasicCompositeIds(false); + assertFalse(((RevengConfiguration)wrappedRevengConfiguration).preferBasicCompositeIds()); + // For jpa configuration + try { + jpaConfigurationWrapper.setPreferBasicCompositeIds(false); + fail(); + } catch (RuntimeException e) { + assertEquals( + e.getMessage(), + "Method 'setPreferBasicCompositeIds' should not be called on instances of " + JpaConfigurationWrapperImpl.class.getName()); + } + } + private void createPersistenceXml() throws Exception { File metaInf = new File(tempRoot, "META-INF"); metaInf.mkdirs();