I'm exploring further and wanted to test what I've been learning but
according to results of my test case, it looks like I haven't learnt
much yet. I'm unsure of how the fetching strategy works in qi4j (for
both entity and value associations).  I tried to test a value
association shown below and my assertion fails; I was expecting the
value association to return with a size of 1 but I'm getting zero.
Sorry to keep bugging you guys but I'm so used to the relational model
and need help getting out of the "box" :)

public class TestProperty extends AbstractQi4jTest {
    public void assemble(ModuleAssembly module) throws AssemblyException {
        module.addAssembler(new EntityTestAssembler());
        module.addAssembler( new RdfMemoryStoreAssembler() );
        module.addEntities(SimpleEntity.class);
        module.addValues(SimpleValue.class);
        module.addObjects(getClass());
    }

    @Test
    public void test() throws Exception {
        UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork();
        try {
            final EntityBuilder<SimpleEntity> builder =
unitOfWork.newEntityBuilder(SimpleEntity.class);

            final SimpleEntity proto = builder.prototypeFor(SimpleEntity.class);

            final ValueBuilder<SimpleValue> svBuilder =
valueBuilderFactory.newValueBuilder(SimpleValue.class);
            final SimpleValue svPrototype = svBuilder.prototype();
            svPrototype.value().set("Hello");
            final SimpleValue value = svBuilder.newInstance();

            final SimpleEntity simpleEntity = builder.newInstance();
            simpleEntity.values().add(value);

            unitOfWork.complete();

            unitOfWork = unitOfWorkFactory.newUnitOfWork();
            final SimpleEntity simpleEntity1 = unitOfWork.get(simpleEntity);

            assertThat(simpleEntity1.values().size(), equalTo(1));
        }
        finally {
            unitOfWork.discard();
        }
    }

    public interface Simple {
        String string();

        List<SimpleValue> values();
    }

    public interface SimpleState {
        @UseDefaults
        Property<String> string();

        @UseDefaults
        Property<List<SimpleValue>> values();
    }


    public interface SimpleValue extends ValueComposite {
        Property<String> value();
    }

    public static class SimpleMixin implements Simple {

        @This
        private SimpleState state;

        public String string() {
            return state.string().get();
        }

        public List<SimpleValue> values() {
            return state.values().get();
        }
    }

    @Mixins ({ SimpleMixin.class })
    public interface SimpleEntity extends Simple, EntityComposite {

    }
}

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to