}
@Test
public void testUpdateMutableFieldWithNewRecordType() throws Exception {
// Create default record
Record record = createDefaultRecord();
// Update the record, creates a second version
Record updateRecord = record.cloneRecord();
updateRecord.setField(fieldType1.getName(), "value2");
updateRecord.setField(fieldType2.getName(), 789);
updateRecord.setField(fieldType3.getName(), false);
repository.update(updateRecord, false, false);
// Read the first version of the record
Record readRecord = repository.read(record.getId(), Long.valueOf(1));
assertEquals(recordType1.getName(), readRecord.getRecordTypeName());
assertEquals(recordType1.getVersion(), readRecord.getRecordTypeVersion());
assertEquals(recordType1.getName(), readRecord.getRecordTypeName(Scope.NON_VERSIONED));
assertEquals(recordType1.getVersion(), readRecord.getRecordTypeVersion(Scope.NON_VERSIONED));
assertEquals(recordType1.getName(), readRecord.getRecordTypeName(Scope.VERSIONED));
assertEquals(recordType1.getVersion(), readRecord.getRecordTypeVersion(Scope.VERSIONED));
assertEquals(recordType1.getName(), readRecord.getRecordTypeName(Scope.VERSIONED_MUTABLE));
assertEquals(recordType1.getVersion(), readRecord.getRecordTypeVersion(Scope.VERSIONED_MUTABLE));
// Do a mutable update of the first version of the record, change the record type
Record updateMutableRecord = repository.newRecord(record.getId());
updateMutableRecord.setVersion(Long.valueOf(1));
updateMutableRecord.setRecordType(recordType2.getName(), recordType2.getVersion());
updateMutableRecord.setField(fieldType4.getName(), 888);
updateMutableRecord.setField(fieldType5.getName(), false);
updateMutableRecord.setField(fieldType6.getName(), "value3");
Record updatedMutableRecord = repository.update(updateMutableRecord, true, false);
assertEquals(Long.valueOf(1), updatedMutableRecord.getVersion());
// Read the first version of the record again
readRecord = repository.read(record.getId(), Long.valueOf(1));
assertEquals(Long.valueOf(1), readRecord.getVersion());
assertEquals("value2", readRecord.getField(fieldType1.getName()));