String NS = "testRecordTypeBuilderFieldsAndSupertypes";
//
// Create some field types
//
FieldType field1 = typeManager.createFieldType("STRING", new QName(NS, "field1"), VERSIONED);
FieldType field2 = typeManager.createFieldType("STRING", new QName(NS, "field2"), VERSIONED);
FieldType field3 = typeManager.createFieldType("STRING", new QName(NS, "field3"), VERSIONED);
FieldType field4 = typeManager.createFieldType("STRING", new QName(NS, "field4"), VERSIONED);
FieldType field5 = typeManager.createFieldType("STRING", new QName(NS, "field5"), VERSIONED);
//
// Create some supertypes
//
FieldType field21 = typeManager.createFieldType("STRING", new QName(NS, "field21"), VERSIONED);
FieldType field22 = typeManager.createFieldType("STRING", new QName(NS, "field22"), VERSIONED);
FieldType field23 = typeManager.createFieldType("STRING", new QName(NS, "field23"), VERSIONED);
FieldType field24 = typeManager.createFieldType("STRING", new QName(NS, "field24"), VERSIONED);
FieldType field25 = typeManager.createFieldType("STRING", new QName(NS, "field25"), VERSIONED);
FieldType field26 = typeManager.createFieldType("STRING", new QName(NS, "field26"), VERSIONED);
FieldType field27 = typeManager.createFieldType("STRING", new QName(NS, "field27"), VERSIONED);
FieldType field28 = typeManager.createFieldType("STRING", new QName(NS, "field28"), VERSIONED);
FieldType field29 = typeManager.createFieldType("STRING", new QName(NS, "field29"), VERSIONED);
RecordType supertype1 = typeManager.recordTypeBuilder().name(NS, "supertype1").fieldEntry().use(field21).add().create();
RecordType supertype2 = typeManager.recordTypeBuilder().name(NS, "supertype2").fieldEntry().use(field22).add().create();
RecordType supertype3 = typeManager.recordTypeBuilder().name(NS, "supertype3").fieldEntry().use(field23).add().create();
RecordType supertype4 = typeManager.recordTypeBuilder().name(NS, "supertype4").fieldEntry().use(field24).add().create();
RecordType supertype5 = typeManager.recordTypeBuilder().name(NS, "supertype5").fieldEntry().use(field25).add().create();
RecordType supertype6 = typeManager.recordTypeBuilder().name(NS, "supertype6").fieldEntry().use(field26).add().create();
RecordType supertype7 = typeManager.recordTypeBuilder().name(NS, "supertype7").fieldEntry().use(field27).add().create();
// give supertype7 two more versions
supertype7.addFieldTypeEntry(field28.getId(), false);
supertype7 = typeManager.updateRecordType(supertype7);
supertype7.addFieldTypeEntry(field29.getId(), false);
supertype7 = typeManager.updateRecordType(supertype7);
RecordType recordType = typeManager
.recordTypeBuilder()
.defaultNamespace(NS)
.name("recordType1")
/* Adding previously defined fields */
/* By ID */
.fieldEntry().id(field1.getId()).add()
/* By object + test mandatory flag */
.fieldEntry().use(field2).mandatory().add()
/* By non-qualified name */
.fieldEntry().name("field3").add()
/* By qualified name */
.fieldEntry().name(new QName(NS, "field4")).add()
/* By indirect qualified name*/
.fieldEntry().name(NS, "field5").add()
/* Adding newly created fields */
/* Using default default scope */
.fieldEntry().defineField().name("field10").type("LIST<STRING>").create().add()
/* Using default type (STRING) */
.fieldEntry().defineField().name("field11").create().add()
/* Using QName */
.fieldEntry().defineField().name(new QName(NS, "field12")).create().add()
/* Using explicit scope */
.fieldEntry().defineField().name("field13").type("LONG").scope(VERSIONED).create().add()
/* Using different default scope */
.defaultScope(Scope.VERSIONED)
.fieldEntry().defineField().name("field14").create().add()
/* Using indirect qualified name*/
.fieldEntry().defineField().name(NS, "field15").create().add()
/* Adding supertypes */
.supertype().id(supertype1.getId()).add()
.supertype().name("supertype2").add()
.supertype().name(new QName(NS, "supertype3")).add()
.supertype().name(NS, "supertype4").add()
.supertype().use(supertype5).add()
.supertype().name(NS, "supertype7").version(2L).add()
.create();
//
// Global checks
//
assertEquals(new QName(NS, "recordType1"), recordType.getName());
//
// Verify fields
//
assertEquals(11, recordType.getFieldTypeEntries().size());
assertFalse(recordType.getFieldTypeEntry(field1.getId()).isMandatory());
assertTrue(recordType.getFieldTypeEntry(field2.getId()).isMandatory());
assertFalse(recordType.getFieldTypeEntry(field3.getId()).isMandatory());
// Verify the inline created fields
FieldType field10 = typeManager.getFieldTypeByName(new QName(NS, "field10"));
assertEquals("LIST<STRING>", field10.getValueType().getName());
assertEquals(Scope.NON_VERSIONED, field10.getScope());
assertNotNull(recordType.getFieldTypeEntry(field10.getId()));
FieldType field11 = typeManager.getFieldTypeByName(new QName(NS, "field11"));
assertEquals("STRING", field11.getValueType().getName());
assertEquals(Scope.NON_VERSIONED, field11.getScope());
assertNotNull(recordType.getFieldTypeEntry(field11.getId()));
FieldType field13 = typeManager.getFieldTypeByName(new QName(NS, "field13"));
assertEquals(Scope.VERSIONED, field13.getScope());
FieldType field14 = typeManager.getFieldTypeByName(new QName(NS, "field14"));
assertEquals(Scope.VERSIONED, field14.getScope());
//
// Verify supertypes
//
Map<SchemaId, Long> supertypes = recordType.getSupertypes();