From 1e5cd268f063ea4570de8e8067db62c09a8e67a2 Mon Sep 17 00:00:00 2001 From: Koen Aers Date: Thu, 22 Jun 2023 14:00:18 +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#addClass(Class)' - Add new test case 'org.hibernate.tool.orm.jbt.wrp.ConfigurationWrapperFactoryTest#testAddClass()' Signed-off-by: Koen Aers --- .../jbt/wrp/ConfigurationWrapperFactory.java | 1 + .../wrp/ConfigurationWrapperFactoryTest.java | 45 +++++++++++++++++++ 2 files changed, 46 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 5319af1bb8..9e0547e9b5 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 @@ -54,6 +54,7 @@ static interface ConfigurationWrapper extends Wrapper { Configuration configure(Document document); Configuration configure(File cfgXmlFile); Configuration configure(); + Configuration addClass(Class class1); } 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 b33d94ee71..7901c56882 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 @@ -413,4 +413,49 @@ public void testConfigureDefault() throws Exception { } } + @Test + public void testAddClass() throws Exception { + String fooHbmXmlFilePath = "org/hibernate/tool/orm/jbt/wrp"; + String fooHbmXmlFileName = "ConfigurationWrapperFactoryTest$Foo.hbm.xml"; + String fooClassName = + "org.hibernate.tool.orm.jbt.wrp.ConfigurationWrapperFactoryTest$Foo"; + URL url = getClass().getProtectionDomain().getCodeSource().getLocation(); + File hbmXmlFileDir = new File(new File(url.toURI()),fooHbmXmlFilePath); + hbmXmlFileDir.deleteOnExit(); + hbmXmlFileDir.mkdirs(); + File hbmXmlFile = new File(hbmXmlFileDir, fooHbmXmlFileName); + hbmXmlFile.deleteOnExit(); + FileWriter fileWriter = new FileWriter(hbmXmlFile); + fileWriter.write(TEST_HBM_XML_STRING); + fileWriter.close(); + + // For native configuration + Metadata metadata = MetadataHelper.getMetadata(wrappedNativeConfiguration); + assertNull(metadata.getEntityBinding(fooClassName)); + Field metadataField = NativeConfiguration.class.getDeclaredField("metadata"); + metadataField.setAccessible(true); + metadataField.set(wrappedNativeConfiguration, null); + nativeConfigurationWrapper.addClass(Foo.class); + metadata = MetadataHelper.getMetadata(wrappedNativeConfiguration); + assertNotNull(metadata.getEntityBinding(fooClassName)); + // For reveng configuration + try { + revengConfigurationWrapper.addClass(Foo.class); + fail(); + } catch (RuntimeException e) { + assertEquals( + e.getMessage(), + "Method 'addClass' should not be called on instances of " + RevengConfigurationWrapperImpl.class.getName()); + } + // For jpa configuration + try { + jpaConfigurationWrapper.addClass(Foo.class); + fail(); + } catch (RuntimeException e) { + assertEquals( + e.getMessage(), + "Method 'addClass' should not be called on instances of " + JpaConfigurationWrapperImpl.class.getName()); + } + } + }