forked from sebersole/hibernate-models2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sebersole#26 Create AnnotationUsage for tenant-id in XML
- Loading branch information
Showing
9 changed files
with
246 additions
and
19 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
6 changes: 6 additions & 0 deletions
6
hibernate-models-orm/src/test/java/org/hibernate/models/orm/xml/dynamic/RowIdTest.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
84 changes: 84 additions & 0 deletions
84
hibernate-models-orm/src/test/java/org/hibernate/models/orm/xml/dynamic/TenantIdTest.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,84 @@ | ||
/* | ||
* 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.dynamic; | ||
|
||
import java.util.Set; | ||
|
||
import org.hibernate.annotations.TenantId; | ||
import org.hibernate.boot.internal.BootstrapContextImpl; | ||
import org.hibernate.boot.internal.MetadataBuilderImpl; | ||
import org.hibernate.boot.model.process.spi.ManagedResources; | ||
import org.hibernate.boot.registry.StandardServiceRegistry; | ||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; | ||
import org.hibernate.models.orm.categorize.spi.CategorizedDomainModel; | ||
import org.hibernate.models.orm.categorize.spi.EntityHierarchy; | ||
import org.hibernate.models.orm.categorize.spi.EntityTypeMetadata; | ||
import org.hibernate.models.orm.process.ManagedResourcesImpl; | ||
import org.hibernate.models.source.spi.AnnotationUsage; | ||
import org.hibernate.models.source.spi.FieldDetails; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jakarta.persistence.Basic; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.FetchType; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.hibernate.models.orm.categorize.spi.ManagedResourcesProcessor.processManagedResources; | ||
|
||
public class TenantIdTest { | ||
@Test | ||
void testSimpleDynamicModel() { | ||
final ManagedResources managedResources = new ManagedResourcesImpl.Builder() | ||
.addXmlMappings( "mappings/dynamic/dynamic-tenantid.xml" ) | ||
.build(); | ||
try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build()) { | ||
final BootstrapContextImpl bootstrapContext = new BootstrapContextImpl( | ||
serviceRegistry, | ||
new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) | ||
); | ||
final CategorizedDomainModel categorizedDomainModel = processManagedResources( | ||
managedResources, | ||
bootstrapContext | ||
); | ||
|
||
final Set<EntityHierarchy> entityHierarchies = categorizedDomainModel.getEntityHierarchies(); | ||
assertThat( entityHierarchies ).hasSize( 2 ); | ||
|
||
entityHierarchies.forEach( | ||
entityHierarchy -> { | ||
final EntityTypeMetadata root = entityHierarchy.getRoot(); | ||
final AnnotationUsage<TenantId> tenantIdAnnotationUsage = root.getClassDetails() | ||
.getAnnotationUsage( TenantId.class ); | ||
final String entityName = root.getEntityName(); | ||
if ( entityName.equals( "EntityWithoutTenantId" ) ) { | ||
assertThat( tenantIdAnnotationUsage ).isNull(); | ||
} | ||
else { | ||
assertThat( tenantIdAnnotationUsage ).isNotNull(); | ||
assertThat( tenantIdAnnotationUsage.getString( "name" ) ).isEqualTo( "tenantId" ); | ||
|
||
final FieldDetails fieldDetails = root.getClassDetails().findFieldByName( "tenantId" ); | ||
|
||
final AnnotationUsage<Basic> basicAnnotationUsage = fieldDetails.getAnnotationUsage( Basic.class ); | ||
assertThat( basicAnnotationUsage ).isNotNull(); | ||
assertThat( basicAnnotationUsage.<FetchType>getAttributeValue( "fetch" ) ) | ||
.isEqualTo( FetchType.EAGER ); | ||
assertThat( basicAnnotationUsage.getBoolean( "optional" ) ).isTrue(); | ||
|
||
final AnnotationUsage<Column> columnAnnotationUsage = fieldDetails. | ||
getAnnotationUsage( Column.class ); | ||
assertThat( basicAnnotationUsage ).isNotNull(); | ||
assertThat( columnAnnotationUsage.getString( "name" ) ).isEqualTo( "TENANT_ID" ); | ||
assertThat( columnAnnotationUsage.getBoolean( "insertable" ) ).isFalse(); | ||
|
||
} | ||
} | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.