FieldStrategy { static <X> FieldStrategy<? extends FieldSpecification<? super X, ?>, X> createFieldStrategy( EntityType<X> et, FieldSpecification<? super X, ?> att, Descriptor entityDescriptor, EntityMappingHelper mapper) { if (att.equals(et.getIdentifier())) { return new IdentifierFieldStrategy<>(et, (Identifier<? super X, ?>) att, entityDescriptor, mapper); } if (att instanceof TypesSpecification) { return new TypesFieldStrategy<>(et, (TypesSpecification<? super X, ?>) att, entityDescriptor, mapper); } else if (att instanceof PropertiesSpecification) { return new PropertiesFieldStrategy<>(et, (PropertiesSpecification<? super X, ?, ?, ?>) att, entityDescriptor, mapper); } final AbstractAttribute<? super X, ?> attribute = (AbstractAttribute<? super X, ?>) att; if (attribute.isCollection()) { switch (attribute.getPersistentAttributeType()) { case ANNOTATION: return createPluralAnnotationPropertyStrategy(et, (AbstractPluralAttribute<? super X, ?, ?>) attribute, entityDescriptor, mapper); case DATA: return createPluralDataPropertyStrategy(et, (AbstractPluralAttribute<? super X, ?, ?>) attribute, entityDescriptor, mapper); case OBJECT: return createPluralObjectPropertyStrategy(et, (AbstractPluralAttribute<? super X, ?, ?>) attribute, entityDescriptor, mapper); default: break; } } else { switch (attribute.getPersistentAttributeType()) { case ANNOTATION: return createSingularAnnotationPropertyStrategy(et, attribute, entityDescriptor, mapper); case DATA: return createSingularDataPropertyStrategy(et, attribute, entityDescriptor, mapper); case OBJECT: return new SingularObjectPropertyStrategy<>(et, attribute, entityDescriptor, mapper); default: break; } } throw new IllegalArgumentException(); } FieldStrategy(EntityType<X> et, T att, Descriptor entityDescriptor, EntityMappingHelper mapper);   }
@Test void createFieldStrategyCreatesPluralDataPropertyStrategyForDataPropertyCollectionAttribute() { final EntityType et = mock(EntityType.class); final CollectionAttributeImpl att = mock(CollectionAttributeImpl.class); when(att.isCollection()).thenReturn(true); when(att.getCollectionType()).thenReturn(PluralAttribute.CollectionType.COLLECTION); when(att.isAssociation()).thenReturn(false); when(att.getBindableJavaType()).thenReturn(String.class); when(att.getElementType()).thenReturn(BasicTypeImpl.get(String.class)); when(att.getPersistentAttributeType()).thenReturn(Attribute.PersistentAttributeType.DATA); final FieldStrategy<?, ?> result = FieldStrategy.createFieldStrategy(et, att, descriptor, mapperMock); assertThat(result, instanceOf(PluralDataPropertyStrategy.class)); }
@Test void createFieldStrategyCreatesSimpleSetStrategyForObjectPropertyCollectionAttribute() { final EntityType et = mock(EntityType.class); final CollectionAttributeImpl att = mock(CollectionAttributeImpl.class); when(att.isCollection()).thenReturn(true); when(att.getCollectionType()).thenReturn(PluralAttribute.CollectionType.COLLECTION); when(att.isAssociation()).thenReturn(true); when(att.getBindableJavaType()).thenReturn(OWLClassA.class); when(att.getElementType()).thenReturn(metamodelMocks.forOwlClassA().entityType()); when(att.getPersistentAttributeType()).thenReturn(Attribute.PersistentAttributeType.OBJECT); final FieldStrategy<?, ?> result = FieldStrategy.createFieldStrategy(et, att, descriptor, mapperMock); assertThat(result, instanceOf(SimpleSetPropertyStrategy.class)); }
@Test void createFieldStrategyCreatesSingularMultilingualStringFieldStrategyForSingularMultilingualStringAttributeMappingDataProperty() { final FieldStrategy<?, ?> result = FieldStrategy.createFieldStrategy(metamodelMocks.forOwlClassU().entityType(), metamodelMocks.forOwlClassU().uSingularStringAtt(), descriptor, mapperMock); assertThat(result, instanceOf(SingularMultilingualStringFieldStrategy.class)); }
@Test void createFieldStrategyCreatesSingularMultilingualStringFieldStrategyForSingularMultilingualStringAttributeMappingAnnotationProperty() { final AbstractAttribute<?, ?> att = metamodelMocks.forOwlClassU().uSingularStringAtt(); when(att.getPersistentAttributeType()).thenReturn(Attribute.PersistentAttributeType.ANNOTATION); final FieldStrategy<?, ?> result = FieldStrategy.createFieldStrategy(metamodelMocks.forOwlClassU().entityType(), metamodelMocks.forOwlClassU().uSingularStringAtt(), descriptor, mapperMock); assertThat(result, instanceOf(SingularMultilingualStringFieldStrategy.class)); }