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

Reply via email to