|
| 1 | +/* |
| 2 | + * Hibernate, Relational Persistence for Idiomatic Java |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + * Copyright: Red Hat Inc. and Hibernate Authors |
| 6 | + */ |
| 7 | + |
| 8 | +package org.hibernate.models.annotations; |
| 9 | + |
| 10 | +import org.hibernate.models.UnknownAnnotationAttributeException; |
| 11 | +import org.hibernate.models.internal.SourceModelBuildingContextImpl; |
| 12 | +import org.hibernate.models.internal.dynamic.DynamicAnnotationUsage; |
| 13 | +import org.hibernate.models.internal.dynamic.DynamicClassDetails; |
| 14 | +import org.hibernate.models.orm.JpaAnnotations; |
| 15 | + |
| 16 | +import org.junit.jupiter.api.Test; |
| 17 | + |
| 18 | +import jakarta.persistence.SequenceGenerator; |
| 19 | + |
| 20 | +import static org.assertj.core.api.Assertions.assertThat; |
| 21 | +import static org.assertj.core.api.Fail.fail; |
| 22 | +import static org.hibernate.models.SourceModelTestHelper.createBuildingContext; |
| 23 | + |
| 24 | +/** |
| 25 | + * @author Steve Ebersole |
| 26 | + */ |
| 27 | +public class DynamicAnnotationTests { |
| 28 | + @Test |
| 29 | + void testBasicUsage() { |
| 30 | + final SourceModelBuildingContextImpl buildingContext = createBuildingContext(); |
| 31 | + final DynamicClassDetails dynamicEntity = new DynamicClassDetails( "DynamicEntity", buildingContext ); |
| 32 | + final DynamicAnnotationUsage<SequenceGenerator> generatorAnn = new DynamicAnnotationUsage<>( |
| 33 | + JpaAnnotations.SEQUENCE_GENERATOR, |
| 34 | + dynamicEntity |
| 35 | + ); |
| 36 | + assertThat( generatorAnn.getString( "name" ) ).isEqualTo( "" ); |
| 37 | + assertThat( generatorAnn.getString( "sequenceName" ) ).isEqualTo( "" ); |
| 38 | + assertThat( generatorAnn.getString( "catalog" ) ).isEqualTo( "" ); |
| 39 | + assertThat( generatorAnn.getString( "schema" ) ).isEqualTo( "" ); |
| 40 | + assertThat( generatorAnn.getInteger( "initialValue" ) ).isEqualTo( 1 ); |
| 41 | + assertThat( generatorAnn.getInteger( "allocationSize" ) ).isEqualTo( 50 ); |
| 42 | + |
| 43 | + try { |
| 44 | + generatorAnn.getInteger( "incrementBy" ); |
| 45 | + fail( "Expecting UnknownAnnotationAttributeException" ); |
| 46 | + } |
| 47 | + catch (UnknownAnnotationAttributeException expected) { |
| 48 | + // ignore |
| 49 | + } |
| 50 | + |
| 51 | + } |
| 52 | +} |
0 commit comments