From 3262906eefdedf6e272398defe3602b35fd0d521 Mon Sep 17 00:00:00 2001 From: Koen Aers Date: Tue, 27 Jun 2023 17:33:57 +0200 Subject: [PATCH] HBX-2390: Create a JBoss Tools adaptation layer in Hibernate Tools - Add new test case 'org.hibernate.tool.orm.jbt.wrp.ExporterWrapperFactoryTest#testSetCustomProperties()' - Add new interface method 'org.hibernate.tool.orm.jbt.wrp.ExporterWrapperFactory#setCustomProperties(Properties)' Signed-off-by: Koen Aers --- .../orm/jbt/wrp/ExporterWrapperFactory.java | 5 +++++ .../jbt/wrp/ExporterWrapperFactoryTest.java | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/wrp/ExporterWrapperFactory.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/wrp/ExporterWrapperFactory.java index d42c5ade5a..6531bf8f6e 100644 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/wrp/ExporterWrapperFactory.java +++ b/jbt/src/main/java/org/hibernate/tool/orm/jbt/wrp/ExporterWrapperFactory.java @@ -102,6 +102,11 @@ default QueryExporterWrapper getQueryExporter() { return null; } } + default void setCustomProperties(Properties properties) { + if (getWrappedObject() instanceof CfgExporter) { + ((CfgExporter)getWrappedObject()).setCustomProperties(properties); + } + } } static class ExporterWrapperImpl implements ExporterWrapper { diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/ExporterWrapperFactoryTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/ExporterWrapperFactoryTest.java index 7352215caf..c9f0e93b32 100644 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/ExporterWrapperFactoryTest.java +++ b/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/ExporterWrapperFactoryTest.java @@ -171,10 +171,28 @@ public void testGetQueryExporter() { assertSame(exporterTarget, queryExporterTarget); } + @Test + public void testSetCustomProperties() { + Properties properties = new Properties(); + // 'setCustomProperties()' should not be called on other exporters than CfgExporter + TestExporter wrappedTestExporter = (TestExporter)exporterWrapper.getWrappedObject(); + assertNull(wrappedTestExporter.props); + exporterWrapper.setCustomProperties(null); + assertNull(wrappedTestExporter.props); + // try now with CfgExporter + exporterWrapper = ExporterWrapperFactory.create(CfgExporter.class.getName()); + CfgExporter wrappedCfgExporter = (CfgExporter)exporterWrapper.getWrappedObject(); + assertNotSame(properties, wrappedCfgExporter.getCustomProperties()); + exporterWrapper.setCustomProperties(properties); + assertSame(properties, wrappedCfgExporter.getCustomProperties()); + } + public static class TestExporter extends AbstractExporter { private boolean started = false; + private Properties props = null; @Override protected void doStart() {} @Override public void start() { started = true; } + void setCustomProperties(Properties p) { props = p; } } }