final JavaType dodGovernor) {
// Add an @RunWith(SpringJunit4ClassRunner) annotation to the type, if
// the user did not define it on the governor directly
if (MemberFindingUtils.getAnnotationOfType(
governorTypeDetails.getAnnotations(), RUN_WITH) == null) {
final AnnotationMetadataBuilder runWithBuilder = new AnnotationMetadataBuilder(
RUN_WITH);
runWithBuilder
.addClassAttribute("value",
"org.springframework.test.context.junit4.SpringJUnit4ClassRunner");
builder.addAnnotation(runWithBuilder);
}
// Add an @ContextConfiguration("classpath:/applicationContext.xml")
// annotation to the type, if the user did not define it on the governor
// directly
if (MemberFindingUtils.getAnnotationOfType(
governorTypeDetails.getAnnotations(), CONTEXT_CONFIGURATION) == null) {
final AnnotationMetadataBuilder contextConfigurationBuilder = new AnnotationMetadataBuilder(
CONTEXT_CONFIGURATION);
contextConfigurationBuilder.addStringAttribute("locations",
"classpath*:/META-INF/spring/applicationContext*.xml");
builder.addAnnotation(contextConfigurationBuilder);
}
// Add an @Transactional, if the user did not define it on the governor
// directly
if (annotationValues.isTransactional()
&& MemberFindingUtils.getAnnotationOfType(
governorTypeDetails.getAnnotations(), TRANSACTIONAL) == null) {
final AnnotationMetadataBuilder transactionalBuilder = new AnnotationMetadataBuilder(
TRANSACTIONAL);
if (StringUtils.isNotBlank(transactionManager)
&& !"transactionManager".equals(transactionManager)) {
transactionalBuilder.addStringAttribute("value",
transactionManager);
}
builder.addAnnotation(transactionalBuilder);
}
// Add the data on demand field if the user did not define it on the
// governor directly
final FieldMetadata field = governorTypeDetails
.getField(new JavaSymbolName("dod"));
if (field != null) {
Validate.isTrue(field.getFieldType().equals(dodGovernor),
"Field 'dod' on '%s' must be of type '%s'",
destination.getFullyQualifiedTypeName(),
dodGovernor.getFullyQualifiedTypeName());
Validate.notNull(
MemberFindingUtils.getAnnotationOfType(
field.getAnnotations(), AUTOWIRED),
"Field 'dod' on '%s' must be annotated with @Autowired",
destination.getFullyQualifiedTypeName());
}
else {
// Add the field via the ITD
final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
annotations.add(new AnnotationMetadataBuilder(AUTOWIRED));
final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(
getId(), 0, annotations, new JavaSymbolName("dod"),
dodGovernor);
builder.addField(fieldBuilder);
}