ConjureParser { public static ConjureSourceFile parse(File file) { RecursiveParser parser = new RecursiveParser(); return parser.parse(file); } private  ConjureParser(); static ConjureSourceFile parse(File file); static AnnotatedConjureSourceFile parseAnnotated(File file); static List<AnnotatedConjureSourceFile> parseAnnotated(Collection<File> files);  }
@Test public void testConjureInlinedImports() throws IOException { ConjureSourceFile conjure = ConjureParser.parse(new File("src/test/resources/example-conjure-imports.yml")); assertThat(conjure.types().conjureImports()).containsKey(Namespace.of("imports")); }
@Test public void cyclicImportsAreNotAllowed() throws IOException { assertThatThrownBy(() -> ConjureParser.parse(new File("src/test/resources/example-recursive-imports.yml"))) .isInstanceOf(ConjureParser.CyclicImportException.class); }
@Test public void duplicate_keys_fail_to_parse() throws Exception { assertThatThrownBy(() -> ConjureParser.parse(new File("src/test/resources/duplicate-keys.yml"))) .hasMessageContaining("Duplicate field 'services'"); }
@Test public void testConjureExternalImports() { ConjureSourceFile conjure = ConjureParser.parse(new File("src/test/resources/example-external-types.yml")); assertThat(conjure.types() .imports() .get(TypeName.of("ExampleAnyImport")) .baseType()) .isEqualTo(PrimitiveType.fromString("any")); }
@Test public void testConjureFieldDeprecation() { ConjureSourceFile conjure = ConjureParser.parse(new File("src/test/resources/example-deprecation.yml")); ObjectTypeDefinition object = conjure.types() .definitions() .objects() .get(TypeName.of("BeanWithDeprecatedField")) .visit(new TypeDefinitionVisitor<ObjectTypeDefinition>() { @Override public ObjectTypeDefinition visit(AliasTypeDefinition _def) { throw new SafeIllegalArgumentException("Expected ObjectTypeDefinition"); } @Override public ObjectTypeDefinition visit(EnumTypeDefinition _def) { throw new SafeIllegalArgumentException("Expected ObjectTypeDefinition"); } @Override public ObjectTypeDefinition visit(ObjectTypeDefinition def) { return def; } @Override public ObjectTypeDefinition visit(UnionTypeDefinition _def) { throw new SafeIllegalArgumentException("Expected ObjectTypeDefinition"); } }); assertThat(object.fields().get(FieldName.of("old")).deprecated()).hasValue("Test deprecated."); }
@Test public void testConjureEnumValueDeprecation() { ConjureSourceFile conjure = ConjureParser.parse(new File("src/test/resources/example-deprecation.yml")); EnumTypeDefinition enumType = conjure.types() .definitions() .objects() .get(TypeName.of("EnumWithDeprecatedValues")) .visit(new TypeDefinitionVisitor<EnumTypeDefinition>() { @Override public EnumTypeDefinition visit(AliasTypeDefinition _def) { throw new SafeIllegalArgumentException("Expected EnumTypeDefinition"); } @Override public EnumTypeDefinition visit(EnumTypeDefinition def) { return def; } @Override public EnumTypeDefinition visit(ObjectTypeDefinition _def) { throw new SafeIllegalArgumentException("Expected EnumTypeDefinition"); } @Override public EnumTypeDefinition visit(UnionTypeDefinition _def) { throw new SafeIllegalArgumentException("Expected EnumTypeDefinition"); } }); EnumValueDefinition one = enumType.values().get(0); EnumValueDefinition two = enumType.values().get(1); assertThat(one.value()).isEqualTo("ONE"); assertThat(one.deprecated()).isNotPresent(); assertThat(two.value()).isEqualTo("TWO"); assertThat(two.deprecated()).hasValue("Prefer ONE."); }
@Test public void testConjureUnionTypeDeprecation() { ConjureSourceFile conjure = ConjureParser.parse(new File("src/test/resources/example-deprecation.yml")); UnionTypeDefinition union = conjure.types() .definitions() .objects() .get(TypeName.of("UnionWithDeprecatedTypes")) .visit(new TypeDefinitionVisitor<UnionTypeDefinition>() { @Override public UnionTypeDefinition visit(AliasTypeDefinition _def) { throw new SafeIllegalArgumentException("Expected EnumTypeDefinition"); } @Override public UnionTypeDefinition visit(EnumTypeDefinition _def) { throw new SafeIllegalArgumentException("Expected EnumTypeDefinition"); } @Override public UnionTypeDefinition visit(ObjectTypeDefinition _def) { throw new SafeIllegalArgumentException("Expected EnumTypeDefinition"); } @Override public UnionTypeDefinition visit(UnionTypeDefinition def) { return def; } }); assertThat(union.union().get(FieldName.of("first")).deprecated()).isNotPresent(); assertThat(union.union().get(FieldName.of("second")).deprecated()).hasValue("Use 'first'."); }
@Test public void testConjureRevisitedImports() throws IOException { List<String> inners = ImmutableList.of( "innerOne", "innerTwo", "innerThree", "innerFour", "innerFive", "innerSix", "innerSeven", "innerEight", "innerNine", "innerTen"); List<String> mid = ImmutableList.of("midOne", "midTwo", "midThree", "midFour", "midFive"); List<String> top = ImmutableList.of("topOne", "topTwo", "topThree", "topFour", "topFive", "topSix"); String root = "root"; generateFiles(inners, ImmutableList.of()); generateFiles(mid, inners); generateFiles(top, mid); generateFiles(ImmutableList.of(root), top); ConjureSourceFile result = ConjureParser.parse( temporaryFolder.getRoot().toPath().resolve(root + ".yml").toFile()); assertThat(result.types().conjureImports()).isNotEmpty(); }