Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Properties getProperties() {

@Override
public void start() {
List<Binding<JaxbHbmHibernateMapping>> hbmBindings = getHbmMappings();
List<Binding<JaxbHbmHibernateMapping>> hbmBindings = getHbmBindings();
Marshaller marshaller = createMarshaller(mappingBinder);
MetadataSources metadataSources = new MetadataSources( createServiceRegistry() );
hbmBindings.forEach( metadataSources::addHbmXmlBinding );
Expand Down Expand Up @@ -86,20 +86,19 @@ private MappingBinder createMappingBinder() {
UnsupportedFeatureHandling.ERROR);
}

private List<Binding<JaxbHbmHibernateMapping>> getHbmMappings() {
private List<Binding<JaxbHbmHibernateMapping>> getHbmBindings() {
List<Binding<JaxbHbmHibernateMapping>> result = new ArrayList<>();
hbmXmlFiles.forEach((hbmXmlFile) -> {
final String fullPath = hbmXmlFile.getAbsolutePath();
LOGGER.info("Adding file: '" + fullPath + "' to the list to be transformed.");
HbmXmlOrigin origin = new HbmXmlOrigin( hbmXmlFile );
Binding<JaxbHbmHibernateMapping> binding = bindMapping( mappingBinder, origin );
Binding<JaxbHbmHibernateMapping> binding = bindHbmXml( origin );
result.add(binding);
});
return result;
}

private Binding<JaxbHbmHibernateMapping> bindMapping(
MappingBinder mappingBinder, HbmXmlOrigin origin) {
private Binding<JaxbHbmHibernateMapping> bindHbmXml(HbmXmlOrigin origin) {
File hbmXmlFile = origin.getHbmXmlFile();
try ( final FileInputStream fileStream = new FileInputStream(hbmXmlFile) ) {
return mappingBinder.bind( fileStream, origin );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,20 @@ public void testCreateMappingBinder()
}

@Test
public void testBindMapping() throws Exception{
public void testBindHbmXml() throws Exception{
Method bindMappingMethod = MappingExporter.class.getDeclaredMethod(
"bindMapping",
MappingBinder.class,
"bindHbmXml",
HbmXmlOrigin.class);
assertNotNull(bindMappingMethod);
bindMappingMethod.setAccessible(true);
File file = new File(this.tempDir, "foo.bar");
Files.writeString(file.toPath(), "foobar");
final MappingBinder mappingBinder = new TestMappingBinder(file, "barfoo");
Field mappingBinderField = MappingExporter.class.getDeclaredField("mappingBinder");
mappingBinderField.setAccessible(true);
mappingBinderField.set(mappingExporter, mappingBinder);
assertNotEquals("barfoo", Files.readString(file.toPath()));
Object object = bindMappingMethod.invoke(mappingExporter, mappingBinder, new HbmXmlOrigin(file));
Object object = bindMappingMethod.invoke(mappingExporter, new HbmXmlOrigin(file));
assertInstanceOf(Binding.class, object);
Origin origin = ((Binding<?>)object).getOrigin();
assertInstanceOf(HbmXmlOrigin.class, origin);
Expand All @@ -111,8 +113,8 @@ public void testBindMapping() throws Exception{
}

@Test
public void testGetHbmMappings() throws Exception {
Method getHbmMappingsMethod = MappingExporter.class.getDeclaredMethod("getHbmMappings");
public void testGetHbmBindings() throws Exception {
Method getHbmMappingsMethod = MappingExporter.class.getDeclaredMethod("getHbmBindings");
assertNotNull(getHbmMappingsMethod);
getHbmMappingsMethod.setAccessible(true);
Field hbmFilesField = MappingExporter.class.getDeclaredField("hbmXmlFiles");
Expand Down