@Test
public void testMetadataNoUpdate() throws Exception {
Record record = repository.newRecord();
record.setRecordType(recordType1.getName());
record.setField(fieldType2.getName(), new Integer(1));
record.setMetadata(fieldType2.getName(), new MetadataBuilder().value("field1", "value1").build());
record = repository.create(record);
assertEquals(1, record.getVersion().longValue());
assertEquals(1, record.getMetadata(fieldType2.getName()).getMap().size());
// resubmit the same record object, this should not cause an update
record = repository.update(record);
assertEquals(1, record.getVersion().longValue());
// Delete a non-existing field from the metadata, this should also not cause an update
record.setMetadata(fieldType2.getName(), new MetadataBuilder().delete("field2").build());
record = repository.update(record);
assertEquals(1, record.getVersion().longValue());
// Once more with an empty metadata object
record.setMetadata(fieldType2.getName(), new MetadataBuilder().build());
record = repository.update(record);
assertEquals(1, record.getVersion().longValue());
// But if we do a real update, we should get a new version
record.setMetadata(fieldType2.getName(), new MetadataBuilder().value("field1", "value1a").build());
record = repository.update(record);
assertEquals(2, record.getVersion().longValue());
}