@Override public void process(ProcessClassContext processClassContext) { final Class<?> cls = processClassContext.getCls(); final PersistenceCapable annotation = Annotations.getAnnotation(cls, PersistenceCapable.class); if (annotation == null) { return; } String annotationTableAttribute = annotation.table(); if (StringUtils.isNullOrEmpty(annotationTableAttribute)) { annotationTableAttribute = cls.getSimpleName(); } final IdentityType annotationIdentityType = annotation.identityType(); FacetUtil.addFacet( new JdoPersistenceCapableFacetAnnotation( annotationTableAttribute, annotationIdentityType, processClassContext.getFacetHolder())); return; }
@SuppressWarnings("rawtypes") @Test public void searchAndTest() { Reflections reflections = new Reflections("org.estatio.dom"); System.out.println("EstatioDomainObjectContractTestAll_jdoAnnotations"); Set<Class<? extends UdoDomainObject>> subtypes = reflections.getSubTypesOf(UdoDomainObject.class); for (Class<? extends UdoDomainObject> subtype : subtypes) { if (subtype.isAnonymousClass() || subtype.isLocalClass() || subtype.isMemberClass() || subtype.getName().endsWith("ForTesting")) { // skip (probably a testing class) continue; } if (UdoDomainObject.class == subtype || EstatioDomainObject.class == subtype) { // skip continue; } System.out.println(">>> " + subtype.getName()); // must have a @PersistenceCapable(identityType=...) annotation final PersistenceCapable persistenceCapable = subtype.getAnnotation(PersistenceCapable.class); assertThat( "Class " + subtype.getName() + " inherits from EstatioDomainObject " + "but is not annotated with @PersistenceCapable", persistenceCapable, is(not(nullValue()))); IdentityType identityType = persistenceCapable.identityType(); assertThat( "Class " + subtype.getName() + " @PersistenceCapable annotation " + "does not specify the identityType", identityType, is(not(nullValue()))); if (identityType == IdentityType.DATASTORE) { // NOT mandatory to have a @DatastoreIdentity, but if does, then @DatastoreIdentity(..., // column="id") final DatastoreIdentity datastoreIdentity = subtype.getAnnotation(DatastoreIdentity.class); if (datastoreIdentity != null) { assertThat( "Class " + subtype.getName() + " @DataStoreIdentity annotation does not specify column=\"id\"", datastoreIdentity.column(), is("id")); } } Inheritance inheritance = subtype.getAnnotation(Inheritance.class); if (inheritance != null && inheritance.strategy() == InheritanceStrategy.SUPERCLASS_TABLE) { // must NOT have a @Discriminator(..., column="discriminator") final Annotation[] declaredAnnotations = subtype.getDeclaredAnnotations(); for (Annotation declaredAnnotation : declaredAnnotations) { if (declaredAnnotation.annotationType() == Discriminator.class) { Assert.fail( "Class " + subtype.getName() + " inherits from " + subtype.getSuperclass().getName() + "and has (incorrectly) been annotated with @Discriminator"); } } // check if supertype has discriminator // must have a @Discriminator(..., column="discriminator") on one of its supertypes final Discriminator superDiscriminator = subtype.getSuperclass().getAnnotation(Discriminator.class); assertThat( "Class " + subtype.getSuperclass().getName() + " is inherited by " + subtype.getName() + "but is not annotated with @Discriminator", superDiscriminator, is(not(nullValue()))); assertThat( "Class " + subtype.getName() + " @Discriminator annotation does not specify column=\"discriminator\"", superDiscriminator.column(), is("discriminator")); } if (subtype.getSuperclass().equals(UdoDomainObject.class)) { // must have a @Version(..., column="version") final Version version = getAnnotationOfTypeOfItsSupertypes(subtype, Version.class); assertThat( "Class " + subtype.getName() + " inherits from EstatioMutableObject " + "but is not annotated with @Version", version, is(not(nullValue()))); assertThat( "Class " + subtype.getName() + " @Version annotation does not specify have column=\"version\"", version.column(), is("version")); } } }