assertEquals(null,findFirstString( "cascade={}", new File(getOutputDir(), "org/hibernate/tool/hbm2x/Article.java") ));
}
public void testAnnotationBuilder() {
AnnotationBuilder builder = AnnotationBuilder.createAnnotation("SingleCleared").resetAnnotation( "Single" );
assertEquals("@Single", builder.getResult());
builder = AnnotationBuilder.createAnnotation("javax.persistence.OneToMany")
.addAttribute("willbecleared", (String)null)
.resetAnnotation("javax.persistence.OneToMany")
.addAttribute("cascade", new String[] { "val1", "val2"})
.addAttribute("fetch", "singleValue");
assertEquals("@javax.persistence.OneToMany(cascade={val1, val2}, fetch=singleValue)", builder.getResult());
builder = AnnotationBuilder.createAnnotation("javax.persistence.OneToMany");
builder.addAttribute("cascade", (String[])null);
builder.addAttribute("fetch", (String)null);
assertEquals("@javax.persistence.OneToMany", builder.getResult());
builder = AnnotationBuilder.createAnnotation("abc");
ArrayList list = new ArrayList();
list.add(new Integer(42));
list.add( new String("xxx") );
builder.addQuotedAttributes( "it", list.iterator() );
assertEquals("@abc(it={\"42\", \"xxx\"})", builder.getResult());
List columns = new ArrayList();
columns.add("first");
columns.add("second");
AnnotationBuilder constraint = AnnotationBuilder.createAnnotation( "UniqueConstraint" );
constraint.addQuotedAttributes( "columnNames", new IteratorTransformer(columns.iterator()) {
public Object transform(Object object) {
return object.toString();
}
});
constraint.addAttribute( "single", "value" );
String attribute = constraint.getAttributeAsString("columnNames");
assertEquals("{\"first\", \"second\"}", attribute);
assertEquals("value", constraint.getAttributeAsString( "single" ));
}