/** 単純なテスト。 */ @Test public void simple() { TableModelDescription a = new TableModelBuilder("A") .add(null, "id", PropertyTypeKind.LONG) .add(null, "hoge", new StringType(255)) .toDescription(); TableModelDescription b = new TableModelBuilder("B") .add(null, "id", PropertyTypeKind.LONG) .add(null, "foo", new StringType(255)) .toDescription(); JoinedModelBuilder target = new JoinedModelBuilder("J", a, "a", b, "b"); target.on("a.id", "b.id"); target.add("id", "a.id"); target.add("hoge", "a.hoge"); target.add("bar", "b.foo"); JoinedModelDescription desc = target.toDescription(); assertThat(desc.getFromModel().getSimpleName(), is("A")); assertThat(desc.getJoinModel().getSimpleName(), is("B")); assertThat(desc.getFromCondition(), is(sources(a, "id"))); assertThat(desc.getJoinCondition(), is(sources(b, "id"))); List<ModelProperty> props = desc.getProperties(); assertThat(props.size(), is(3)); ModelProperty id = props.get(0); assertThat(id.getName(), is("id")); assertThat(id.getType().getKind(), is(PropertyTypeKind.LONG)); assertThat(id.getFrom(), is(source(a, "id"))); assertThat(id.getJoined(), is(source(b, "id"))); ModelProperty hoge = props.get(1); assertThat(hoge.getName(), is("hoge")); assertThat(hoge.getType().getKind(), is(PropertyTypeKind.STRING)); assertThat(hoge.getFrom(), is(source(a, "hoge"))); assertThat(hoge.getJoined(), is(nullValue())); ModelProperty bar = props.get(2); assertThat(bar.getName(), is("bar")); assertThat(bar.getType().getKind(), is(PropertyTypeKind.STRING)); assertThat(bar.getFrom(), is(nullValue())); assertThat(bar.getJoined(), is(source(b, "foo"))); }
private AstRecord generateTerm() { List<AstPropertyDefinition> properties = Lists.create(); for (ModelProperty property : model.getProperties()) { properties.add( new AstPropertyDefinition( null, AstBuilder.getDesciption("{0}", property.getName()), Arrays.asList( new AstAttribute[] { AstBuilder.getOriginalName(property.getName()), }), AstBuilder.toName(property), AstBuilder.toType(property.getType()))); } return new AstRecordDefinition(null, properties); }