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)

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

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.


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

Reply via email to