Schema { public Collection<UserType> getUserTypes() { Collection<UserType> uts = new ArrayList<UserType>(); for (Type t : typeMap.values()) { if (t.isUserType()) { uts.add((UserType) t); } } return uts; }  static Schema build(String path); void save(OutputStream os); Collection<Type> getTypes(); Collection<UserType> getUserTypes(); Type findType(String idOrName); SchemaVersion getVersion(); Collection<Type> getDerivedTypes(String baseTypeId,
			boolean directOnly); Collection<Type> getDerivedTypes(Type baseType,
			boolean directOnly); static final String TYPE_ID_TOKENIZER_PATTERN; }
@Test public void schemaFieldTest() throws URISyntaxException, TeslaSchemaException, NoSuchAlgorithmException, SAXException, IOException, ParserConfigurationException { Schema schema = parseSchema("src/test/resources/field.tml"); Collection<UserType> types = schema.getUserTypes(); String[] expectedFieldNameList = new String[] { "Byte", "Int16", "UInt16", "Int32", "UInt32", "Int64", "UInt64", "Boolean", "Double", "Binary", "String" }; Type[] expectedTypeList = new Type[] { Primitive.BYTE, Primitive.INT16, Primitive.UINT16, Primitive.INT32, Primitive.UINT32, Primitive.INT64, Primitive.UINT64, Primitive.BOOLEAN, Primitive.DOUBLE, Primitive.BINARY, Primitive.STRING }; assert (expectedFieldNameList.length == expectedTypeList.length); assertTrue(types.iterator().next().isClass()); Class class1 = (Class) types.iterator().next(); for (int i = 0; i < expectedFieldNameList.length; i++) { String fieldName = expectedFieldNameList[i] + "Field"; Field field = class1.findField(fieldName); assertNotNull(field); assertEquals(fieldName, field.getName()); assertEquals(expectedTypeList[i], field.getType()); } }
@Test public void schemaFieldDisplayNameTest() throws URISyntaxException, TeslaSchemaException, NoSuchAlgorithmException, SAXException, IOException, ParserConfigurationException { Schema schema = parseSchema("src/test/resources/fielddisplayname.tml"); Collection<UserType> types = schema.getUserTypes(); assertTrue(types.iterator().next().isClass()); Class class1 = (Class) types.iterator().next(); List<Field> fields = class1.getAllFields(); assertEquals("FieldDisplayName", fields.get(0).getDisplayName()); }
@Test public void schemaNullableFieldTest() throws URISyntaxException, TeslaSchemaException, NoSuchAlgorithmException, SAXException, IOException, ParserConfigurationException { Schema schema = parseSchema("src/test/resources/nullablefield.tml"); Collection<UserType> types = schema.getUserTypes(); Iterator<UserType> itr = types.iterator(); assertTrue(itr.next().isClass()); Class class1 = (Class) itr.next(); assertTrue(class1.getName().contains("TeslaClass")); for (Field field : class1.getAllFields()) { assertTrue(((Field) field).getIsOptional()); } }
@Test public void schemaFieldRankTest() throws URISyntaxException, TeslaSchemaException, NoSuchAlgorithmException, SAXException, IOException, ParserConfigurationException { Schema schema = parseSchema("src/test/resources/fieldrank.tml"); Collection<UserType> types = schema.getUserTypes(); assertTrue(types.iterator().next().isClass()); Class class1 = (Class) types.iterator().next(); assertTrue(class1.getName().contains("TeslaClass")); for (Field field : class1.getAllFields()) { assertTrue(((Field) field).getIsArray()); assertEquals(2, ((Field) field).getRank()); } }
@Test public void schemaEnumTest() throws Exception { Schema schema = parseSchema("src/test/resources/enum.tml"); assertNotNull(schema); Collection<UserType> types = schema.getUserTypes(); assertTrue(types.iterator().next().isEnum()); Enum enumType = (Enum) types.iterator().next(); assertNotNull(enumType); Collection<EnumEntry> enumEntries = enumType.getEntries(); assertEquals(3, enumEntries.size()); int i = 0; for (EnumEntry enumEntry : enumEntries) { assertEquals(i-1, enumEntry.getValue()); i++; } }
@Test public void schemaNamespaceTest() throws URISyntaxException, TeslaSchemaException, NoSuchAlgorithmException, SAXException, IOException, ParserConfigurationException { Schema schema = parseSchema("src/test/resources/namespace.tml"); assertNotNull(schema); assertEquals("My", schema.getUserTypes().iterator().next() .getNameSpace()); }