Niclas Hedhman wrote: > The @Constraints on the Composite is no longer needed and possibly > placed onto the Constrain annotation itself. So take away the > Constraints (it should not make a practical difference) > > Ok, good to know. What about the ValidatableAbstractComposite? I think I just tried that out of desperation, but do I need that?
> Instead they are declared on the annotation itself. I see that > @NonEmptyString is utilizing the cascaded constraint feature, i.e. > says that NonEmptyString ---> NotNull & MinLength=1 > > Hmm... well I tried changing the constraint just to NotNull and all the tests still pass. I've stepped through the Qi4j code and the EntityPropertyInstance doesn't do any Constraint checking. It's parent, the PropertyInstance class does, but the one for Entities doesn't. I would assume this is so it can be done when the unit of work is complete, but I've stepped through all the unit of work completion code and can't find anywhere the constraints are checked. > My guess is that you stumbled on a bug in the recursive resolution of > the constraint annotations, because AFAICS it looks good. > > There are possibly some documentation errors around Constraints, as > the docs may talk about Constraints are not throwing exceptions, but > that was changed not too long ago, to always throw a localizable > exception instead, to simplify the setup. > > Unless Rickard can spot something when he wakes up, I suggest you post > this on http://issues.ops4j.org/jira/browse/QI and upload the test > files. > Done. http://issues.ops4j.org/jira/browse/QI-59 Thanks, Rich > > Cheers > Niclas > > > On Wed, May 7, 2008 at 3:37 AM, Richard Wallace > <[EMAIL PROTECTED]> wrote: > >> Hello again, >> >> So I've been experimenting more with Qi4j. Loving it so far. One of >> the things that I wanted to do was to create Nameable entities. I saw >> it done in some of the sample code and wanted to give it a go on my own >> to get a feel for how constraints fit. So here's my Nameable type >> >> public interface Nameable { >> >> @NonEmptyString Property<String> name(); >> } >> >> >> and a test for it, to make sure that the name can't be set to something >> other than something valid >> >> public class NameableTest extends AbstractQi4jTest { >> >> @Test >> public void assertNameCannotBeSetToNull() throws >> ConcurrentEntityModificationException, UnitOfWorkCompletionException { >> UnitOfWork uow = unitOfWorkFactory.newUnitOfWork(); >> Nameable nameable = uow.newEntity(Nameable.class); >> nameable.name().set(null); >> uow.complete(); >> } >> >> @Test >> public void assertNameCannotBeSetToEmptyString() throws >> ConcurrentEntityModificationException, UnitOfWorkCompletionException { >> UnitOfWork uow = unitOfWorkFactory.newUnitOfWork(); >> Nameable nameable = uow.newEntity(Nameable.class); >> nameable.name().set(""); >> uow.complete(); >> } >> >> @Test >> public void assertNameCannotBeSetToStringWithOnlyWhitespace() throws >> ConcurrentEntityModificationException, UnitOfWorkCompletionException { >> UnitOfWork uow = unitOfWorkFactory.newUnitOfWork(); >> Nameable nameable = uow.newEntity(Nameable.class); >> nameable.name().set(" \t \n"); >> uow.complete(); >> } >> >> @Test >> public void assertNameCannotBeLeftUnset() throws >> ConcurrentEntityModificationException, UnitOfWorkCompletionException { >> UnitOfWork uow = unitOfWorkFactory.newUnitOfWork(); >> uow.newEntity(Nameable.class); >> uow.complete(); >> } >> >> @SuppressWarnings("unchecked") >> public void assemble(ModuleAssembly module) throws AssemblyException { >> module.addComposites(NameableEntity.class); >> module.addServices(UuidIdentityGeneratorService.class, >> MemoryEntityStoreService.class); >> } >> >> @Constraints( { NotNullConstraint.class, >> MinLengthConstraint.class, >> InstanceOfConstraint.class } ) >> static interface NameableEntity extends Nameable, EntityComposite, >> ValidatableAbstractComposite {} >> } >> >> And to my surprise, all the tests pass, even though they shouldn't. I >> should be getting some kind of constraint violation exception but I'm >> not. What am I doing wrong? >> >> Thanks, >> Rich >> >> _______________________________________________ >> qi4j-dev mailing list >> [email protected] >> http://lists.ops4j.org/mailman/listinfo/qi4j-dev >> >> > > _______________________________________________ > qi4j-dev mailing list > [email protected] > http://lists.ops4j.org/mailman/listinfo/qi4j-dev > _______________________________________________ qi4j-dev mailing list [email protected] http://lists.ops4j.org/mailman/listinfo/qi4j-dev

