ClassFieldMetamodelProcessor { void processField(Field field) { LOG.trace("processing field: {}", field); if (EntityPropertiesUtils.isFieldTransient(field)) { if (!EntityPropertiesUtils.isFieldStatic(field)) { LOG.trace("Skipping transient field {}", field); } return; } if (field.getType().isPrimitive()) { throw new MetamodelInitializationException( "Primitive types cannot be used for entity fields. Field " + field + " in class " + cls); } final Class<?> fieldValueCls = getFieldValueType(field); field.setAccessible(true); final InferenceInfo inference = processInferenceInfo(field); if (isTypesField(field)) { processTypesField(field, fieldValueCls, inference); return; } if (isPropertiesField(field)) { processPropertiesField(field, fieldValueCls, inference); return; } final PropertyAttributes propertyAtt = PropertyAttributes.create(field, mappingValidator, context); propertyAtt.resolve(field, metamodelBuilder, fieldValueCls); if (propertyAtt.isKnownOwlProperty()) { createAttribute(field, inference, propertyAtt); } else if (!isAspectIntegrationField(field)) { final boolean success = processIdentifierField(field); if (!success) { throw new MetamodelInitializationException( "Unable to process field " + field + ". It is not transient but has no mapping information."); } } } ClassFieldMetamodelProcessor(TypeBuilderContext<X> context, MetamodelBuilder metamodelBuilder);   }
@Test void processingNonTransientFieldWithoutPropertyInfoThrowsException() throws Exception { final EntityTypeImpl<InvalidClass> etMock = mock(EntityTypeImpl.class); when(etMock.getJavaType()).thenReturn(InvalidClass.class); final ClassFieldMetamodelProcessor<InvalidClass> processor = new ClassFieldMetamodelProcessor<>(new TypeBuilderContext<>(etMock, new NamespaceResolver()), metamodelBuilder); final Field field = InvalidClass.class.getDeclaredField("invalidAttribute"); assertThrows(MetamodelInitializationException.class, () -> processor.processField(field)); }
@Test void processPluralFieldWithNonEmptyCardinalityConstraintAddsTheConstraintToAttributeSpecification() throws Exception { final EntityTypeImpl<OWLClassJ> etMock = mock(EntityTypeImpl.class); when(etMock.getJavaType()).thenReturn(OWLClassJ.class); final TypeBuilderContext<OWLClassJ> context = new TypeBuilderContext<>(etMock, new NamespaceResolver()); context.setConverterResolver(new ConverterResolver(new Converters(new Configuration()))); final ClassFieldMetamodelProcessor<OWLClassJ> processor = new ClassFieldMetamodelProcessor<>(context, metamodelBuilder); final Field field = OWLClassJ.getOwlClassAField(); processor.processField(field); final ArgumentCaptor<AbstractAttribute> captor = ArgumentCaptor.forClass(AbstractAttribute.class); verify(etMock).addDeclaredAttribute(eq(field.getName()), captor.capture()); assertTrue(captor.getValue().isNonEmpty()); }