This repository has been archived by the owner on May 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add integration test for complex schemas
- Loading branch information
amckenzie
committed
Aug 15, 2017
1 parent
7e46f84
commit 20e12a6
Showing
19 changed files
with
672 additions
and
60 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
...n-test/src/test/java/uk/gov/justice/generation/pojo/integration/test/ComplexSchemaIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package uk.gov.justice.generation.pojo.integration.test; | ||
|
||
import static java.util.stream.Collectors.toList; | ||
|
||
import uk.gov.justice.generation.pojo.core.DefinitionBuilderVisitor; | ||
import uk.gov.justice.generation.pojo.core.GenerationContext; | ||
import uk.gov.justice.generation.pojo.core.JsonSchemaWrapper; | ||
import uk.gov.justice.generation.pojo.core.RootFieldNameGenerator; | ||
import uk.gov.justice.generation.pojo.generators.ClassGeneratable; | ||
import uk.gov.justice.generation.pojo.generators.JavaGeneratorFactory; | ||
import uk.gov.justice.generation.pojo.integration.utils.ClassCompiler; | ||
import uk.gov.justice.generation.pojo.integration.utils.JsonSchemaLoader; | ||
import uk.gov.justice.generation.pojo.write.SourceWriter; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
import org.everit.json.schema.ObjectSchema; | ||
import org.junit.Test; | ||
|
||
public class ComplexSchemaIT { | ||
|
||
private final SourceWriter sourceWriter = new SourceWriter(); | ||
private final ClassCompiler classCompiler = new ClassCompiler(); | ||
private final JavaGeneratorFactory javaGeneratorFactory = new JavaGeneratorFactory(); | ||
private final RootFieldNameGenerator rootFieldNameGenerator = new RootFieldNameGenerator(); | ||
|
||
@Test | ||
public void shouldParseAVeryComplexSchemaDocument() throws Exception { | ||
|
||
final File jsonSchemaFile = new File("src/test/resources/schemas/context.command.complex-data.json"); | ||
final ObjectSchema schema = JsonSchemaLoader.loadSchema(jsonSchemaFile, ObjectSchema.class); | ||
final String fieldName = rootFieldNameGenerator.generateNameFrom(jsonSchemaFile); | ||
|
||
final DefinitionBuilderVisitor definitionBuilderVisitor = new DefinitionBuilderVisitor("uk.gov.justice.pojo"); | ||
final JsonSchemaWrapper jsonSchemaWrapper = new JsonSchemaWrapper(schema); | ||
|
||
jsonSchemaWrapper.accept(fieldName, definitionBuilderVisitor); | ||
|
||
final List<ClassGeneratable> classGeneratables = definitionBuilderVisitor.getDefinitions() | ||
.stream() | ||
.map(javaGeneratorFactory::createClassGeneratorFor) | ||
.collect(toList()); | ||
|
||
|
||
final File sourceOutputDirectory = new File("./target/test-generation"); | ||
final File classesOutputDirectory = new File("./target/test-classes"); | ||
|
||
sourceOutputDirectory.delete(); | ||
|
||
final GenerationContext generationContext = new GenerationContext(sourceOutputDirectory); | ||
|
||
classGeneratables.forEach(classGeneratable -> { | ||
sourceWriter.write(classGeneratable, generationContext); | ||
classCompiler.compile(classGeneratable, sourceOutputDirectory, classesOutputDirectory); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.