Search in sources :

Example 61 with ConjureDefinition

use of com.palantir.conjure.spec.ConjureDefinition in project conjure-java by palantir.

the class ObjectGeneratorTests method testConjureImports.

@Test
public void testConjureImports() throws IOException {
    ConjureDefinition conjure = Conjure.parse(ImmutableList.of(new File("src/test/resources/example-conjure-imports.yml"), new File("src/test/resources/example-types.yml"), new File("src/test/resources/example-service.yml")));
    File src = Files.createDirectory(tempDir.toPath().resolve("src")).toFile();
    new GenerationCoordinator(MoreExecutors.directExecutor(), ImmutableSet.of(new ObjectGenerator(Options.builder().useImmutableBytes(true).excludeEmptyOptionals(true).build()))).emit(conjure, src);
    // Generated files contain imports
    assertThat(compiledFileContent(src, "test/api/with/imports/ComplexObjectWithImports.java")).contains("import com.palantir.product.StringExample;");
    // Imported files are not generated.
    assertThat(new File(src, "com/palantir/foundry/catalog/api/datasets/BackingFileSystem.java")).doesNotExist();
    assertThat(new File(src, "test/api/StringExample.java")).doesNotExist();
}
Also used : GenerationCoordinator(com.palantir.conjure.java.GenerationCoordinator) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 62 with ConjureDefinition

use of com.palantir.conjure.spec.ConjureDefinition in project conjure-java by palantir.

the class ObjectGeneratorTests method testObjectGenerator_excludeEmptyCollections.

@Test
public void testObjectGenerator_excludeEmptyCollections() throws IOException {
    ConjureDefinition def = Conjure.parse(ImmutableList.of(new File("src/test/resources/exclude-empty-collections.yml")));
    List<Path> files = new GenerationCoordinator(MoreExecutors.directExecutor(), ImmutableSet.of(new ObjectGenerator(Options.builder().excludeEmptyCollections(true).build()))).emit(def, tempDir);
    assertThatFilesAreTheSame(files, REFERENCE_FILES_FOLDER);
}
Also used : Path(java.nio.file.Path) GenerationCoordinator(com.palantir.conjure.java.GenerationCoordinator) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 63 with ConjureDefinition

use of com.palantir.conjure.spec.ConjureDefinition in project conjure-java by palantir.

the class ObjectGeneratorTests method testObjectGenerator_stagedBuilder.

@Test
public void testObjectGenerator_stagedBuilder() throws IOException {
    ConjureDefinition def = Conjure.parse(ImmutableList.of(new File("src/test/resources/example-staged-types.yml")));
    List<Path> files = new GenerationCoordinator(MoreExecutors.directExecutor(), ImmutableSet.of(new ObjectGenerator(Options.builder().useStagedBuilders(true).excludeEmptyOptionals(true).build()))).emit(def, tempDir);
    assertThatFilesAreTheSame(files, REFERENCE_FILES_FOLDER);
}
Also used : Path(java.nio.file.Path) GenerationCoordinator(com.palantir.conjure.java.GenerationCoordinator) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 64 with ConjureDefinition

use of com.palantir.conjure.spec.ConjureDefinition in project conjure-java by palantir.

the class ObjectGeneratorTests method testStrictFalse.

@Test
public void testStrictFalse() throws IOException {
    ConjureDefinition def = Conjure.parse(ImmutableList.of(new File("src/test/resources/example-types-strict-objects.yml")));
    List<Path> files = new GenerationCoordinator(MoreExecutors.directExecutor(), ImmutableSet.of(new ObjectGenerator(Options.builder().useImmutableBytes(true).strictObjects(false).build()))).emit(def, tempDir);
    assertThatFilesAreTheSame(files, REFERENCE_FILES_FOLDER);
}
Also used : Path(java.nio.file.Path) GenerationCoordinator(com.palantir.conjure.java.GenerationCoordinator) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 65 with ConjureDefinition

use of com.palantir.conjure.spec.ConjureDefinition in project conjure-postman by palantir.

the class ConjurePostmanGeneratorTest method maybeResetExpectedDirectory.

private void maybeResetExpectedDirectory(Path expected, ConjureDefinition definition) throws IOException {
    if (Boolean.valueOf(System.getProperty("recreate", "false")) || !expected.toFile().isDirectory()) {
        Files.createDirectories(expected);
        try (Stream<Path> walk = Files.walk(expected)) {
            walk.filter(path -> path.toFile().isFile()).forEach(path -> path.toFile().delete());
        }
        try (Stream<Path> walk = Files.walk(expected)) {
            walk.forEach(path -> path.toFile().delete());
        }
        Files.createDirectories(expected);
        PostmanCollectionFileWriter defaultWriter = new DefaultPostmanCollectionFileWriter(expected);
        defaultWriter.write(generator.generate(definition));
    }
}
Also used : Path(java.nio.file.Path) Files(java.nio.file.Files) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Set(java.util.Set) Conjure(com.palantir.conjure.defs.Conjure) IOException(java.io.IOException) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) Collectors(java.util.stream.Collectors) File(java.io.File) DefaultPostmanCollectionFileWriter(com.palantir.conjure.postman.writer.DefaultPostmanCollectionFileWriter) List(java.util.List) Stream(java.util.stream.Stream) PostmanCollectionFileWriter(com.palantir.conjure.postman.writer.PostmanCollectionFileWriter) Strings(org.assertj.core.util.Strings) Path(java.nio.file.Path) DefaultPostmanCollectionFileWriter(com.palantir.conjure.postman.writer.DefaultPostmanCollectionFileWriter) PostmanCollectionFileWriter(com.palantir.conjure.postman.writer.PostmanCollectionFileWriter) DefaultPostmanCollectionFileWriter(com.palantir.conjure.postman.writer.DefaultPostmanCollectionFileWriter)

Aggregations

ConjureDefinition (com.palantir.conjure.spec.ConjureDefinition)65 Test (org.junit.jupiter.api.Test)49 File (java.io.File)40 Path (java.nio.file.Path)30 ConjureIllegalStateException (com.palantir.conjure.exceptions.ConjureIllegalStateException)13 JerseyServiceGenerator (com.palantir.conjure.java.services.JerseyServiceGenerator)9 UndertowServiceGenerator (com.palantir.conjure.java.services.UndertowServiceGenerator)9 GenerationCoordinator (com.palantir.conjure.java.GenerationCoordinator)8 Retrofit2ServiceGenerator (com.palantir.conjure.java.services.Retrofit2ServiceGenerator)4 DialogueServiceGenerator (com.palantir.conjure.java.services.dialogue.DialogueServiceGenerator)4 AnnotatedConjureSourceFile (com.palantir.conjure.parser.AnnotatedConjureSourceFile)4 TypeDefinition (com.palantir.conjure.spec.TypeDefinition)4 BeforeAll (org.junit.jupiter.api.BeforeAll)4 TypeName (com.palantir.conjure.spec.TypeName)3 ImmutableList (com.google.common.collect.ImmutableList)2 ReferenceTypeResolver (com.palantir.conjure.defs.ConjureTypeParserVisitor.ReferenceTypeResolver)2 ConjureRuntimeException (com.palantir.conjure.exceptions.ConjureRuntimeException)2 ConjureSourceFile (com.palantir.conjure.parser.ConjureSourceFile)2 DefaultPostmanCollectionFileWriter (com.palantir.conjure.postman.writer.DefaultPostmanCollectionFileWriter)2 PostmanCollectionFileWriter (com.palantir.conjure.postman.writer.PostmanCollectionFileWriter)2