annotations.add(new AnnotationMetadataBuilder(TEST));
final String entityName = annotationValues.getEntity()
.getSimpleTypeName();
final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.appendFormalLine(entityName
+ " obj = dod."
+ dataOnDemandMetadata.getRandomPersistentEntityMethod()
.getMethodName().getSymbolName() + "();");
bodyBuilder
.appendFormalLine("Assert.assertNotNull(\"Data on demand for '"
+ entityName
+ "' failed to initialize correctly\", obj);");
bodyBuilder.appendFormalLine(identifierAccessorMethod.getReturnType()
.getSimpleTypeName()
+ " id = obj."
+ identifierAccessorMethod.getMethodName().getSymbolName()
+ "();");
bodyBuilder
.appendFormalLine("Assert.assertNotNull(\"Data on demand for '"
+ entityName
+ "' failed to provide an identifier\", id);");
bodyBuilder.appendFormalLine("obj = " + findMethod.getMethodCall()
+ ";");
bodyBuilder.appendFormalLine("boolean modified = dod."
+ dataOnDemandMetadata.getModifyMethod().getMethodName()
.getSymbolName() + "(obj);");
bodyBuilder
.appendFormalLine(versionAccessorMethod.getReturnType()
.getSimpleTypeName()
+ " currentVersion = obj."
+ versionAccessorMethod.getMethodName().getSymbolName()
+ "();");
final String castStr = entityHasSuperclass ? "(" + entityName + ")"
: "";
bodyBuilder.appendFormalLine(entityName + " merged = " + castStr
+ mergeMethod.getMethodCall() + ";");
if (flushMethod != null) {
bodyBuilder.appendFormalLine(flushMethod.getMethodCall() + ";");
flushMethod.copyAdditionsTo(builder, governorTypeDetails);
}
bodyBuilder
.appendFormalLine("Assert.assertEquals(\"Identifier of merged object not the same as identifier of original object\", merged."
+ identifierAccessorMethod.getMethodName()
.getSymbolName() + "(), id);");
if (JdkJavaType.isDateField(versionType)) {
bodyBuilder
.appendFormalLine("Assert.assertTrue(\"Version for '"
+ entityName
+ "' failed to increment on merge and flush directive\", (currentVersion != null && obj."
+ versionAccessorMethod.getMethodName()
.getSymbolName()
+ "().after(currentVersion)) || !modified);");
}
else if (JavaType.STRING.equals(versionType)) {
bodyBuilder
.appendFormalLine("Assert.assertTrue(\"Version for '"
+ entityName
+ "' failed to increment on flush directive\", (currentVersion != null && !currentVersion.equals(obj."
+ versionAccessorMethod.getMethodName()
.getSymbolName() + "())) || !modified);");
}
else {
bodyBuilder
.appendFormalLine("Assert.assertTrue(\"Version for '"
+ entityName
+ "' failed to increment on merge and flush directive\", (currentVersion != null && obj."
+ versionAccessorMethod.getMethodName()
.getSymbolName()