-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preliminary work on
<entity/>
XML overrides
- Loading branch information
Showing
6 changed files
with
161 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...odels-orm/src/test/java/org/hibernate/models/orm/xml/override/SimpleOverrideXmlTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright: Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.models.orm.xml.override; | ||
|
||
import org.hibernate.models.orm.internal.ManagedResourcesImpl; | ||
import org.hibernate.models.orm.spi.AttributeMetadata; | ||
import org.hibernate.models.orm.spi.EntityHierarchy; | ||
import org.hibernate.models.orm.spi.EntityTypeMetadata; | ||
import org.hibernate.models.orm.spi.ManagedResources; | ||
import org.hibernate.models.orm.spi.ProcessResult; | ||
import org.hibernate.models.orm.spi.Processor; | ||
import org.hibernate.models.orm.xml.SimpleEntity; | ||
import org.hibernate.models.source.SourceModelTestHelper; | ||
import org.hibernate.models.source.internal.SourceModelBuildingContextImpl; | ||
import org.hibernate.models.source.spi.AnnotationUsage; | ||
|
||
import org.hibernate.testing.orm.junit.FailureExpected; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import org.jboss.jandex.Index; | ||
|
||
import jakarta.persistence.Basic; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Id; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.hibernate.models.internal.SimpleClassLoading.SIMPLE_CLASS_LOADING; | ||
|
||
/** | ||
* @author Steve Ebersole | ||
*/ | ||
public class SimpleOverrideXmlTests { | ||
@Test | ||
@FailureExpected | ||
void testSimpleCompleteEntity() { | ||
|
||
final ManagedResourcesImpl.Builder managedResourcesBuilder = new ManagedResourcesImpl.Builder(); | ||
managedResourcesBuilder.addXmlMappings( "mappings/override/simple-override.xml" ); | ||
final ManagedResources managedResources = managedResourcesBuilder.build(); | ||
|
||
final Index jandexIndex = SourceModelTestHelper.buildJandexIndex( | ||
SIMPLE_CLASS_LOADING, | ||
SimpleEntity.class | ||
); | ||
final SourceModelBuildingContextImpl buildingContext = SourceModelTestHelper.createBuildingContext( | ||
jandexIndex, | ||
SIMPLE_CLASS_LOADING | ||
); | ||
|
||
final ProcessResult processResult = Processor.process( | ||
managedResources, | ||
null, | ||
new Processor.Options() { | ||
@Override | ||
public boolean areGeneratorsGlobal() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean shouldIgnoreUnlistedClasses() { | ||
return false; | ||
} | ||
}, | ||
buildingContext | ||
); | ||
|
||
assertThat( processResult.getEntityHierarchies() ).hasSize( 1 ); | ||
|
||
final EntityHierarchy hierarchy = processResult.getEntityHierarchies().iterator().next(); | ||
final EntityTypeMetadata root = hierarchy.getRoot(); | ||
assertThat( root.getClassDetails().getClassName() ).isEqualTo( SimpleEntity.class.getName() ); | ||
assertThat( root.getNumberOfAttributes() ).isEqualTo( 2 ); | ||
|
||
final AttributeMetadata idAttribute = root.findAttribute( "id" ); | ||
assertThat( idAttribute.getNature() ).isEqualTo( AttributeMetadata.AttributeNature.BASIC ); | ||
assertThat( idAttribute.getMember().getAnnotationUsage( Id.class ) ).isNotNull(); | ||
|
||
final AttributeMetadata nameAttribute = root.findAttribute( "name" ); | ||
assertThat( nameAttribute.getNature() ).isEqualTo( AttributeMetadata.AttributeNature.BASIC ); | ||
assertThat( nameAttribute.getMember().getAnnotationUsage( Basic.class ) ).isNotNull(); | ||
final AnnotationUsage<Column> nameColumnAnn = nameAttribute.getMember().getAnnotationUsage( Column.class ); | ||
assertThat( nameColumnAnn ).isNotNull(); | ||
assertThat( nameColumnAnn.<String>getAttributeValue( "name" ) ).isEqualTo( "description" ); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
hibernate-models-orm/src/test/resources/mappings/override/simple-override.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!-- | ||
~ Hibernate, Relational Persistence for Idiomatic Java | ||
~ | ||
~ SPDX-License-Identifier: Apache-2.0 | ||
~ Copyright: Red Hat Inc. and Hibernate Authors | ||
--> | ||
<entity-mappings xmlns="http://www.hibernate.org/xsd/orm/mapping" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
version="3.1"> | ||
|
||
<entity class="org.hibernate.models.orm.xml.SimpleEntity" access="FIELD"> | ||
<attributes> | ||
<basic name="name"> | ||
<column name="description"/> | ||
</basic> | ||
</attributes> | ||
</entity> | ||
|
||
</entity-mappings> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters