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();
}
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);
}
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);
}
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);
}
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));
}
}
Aggregations