Skip to content

Commit

Permalink
HBX-2390: Create a JBoss Tools adaptation layer in Hibernate Tools
Browse files Browse the repository at this point in the history
  - 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 <[email protected]>
  • Loading branch information
koentsje committed Jun 22, 2023
1 parent 41b7674 commit 1e5cd26
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

}

0 comments on commit 1e5cd26

Please sign in to comment.