use of cz.habarta.typescript.generator.parser.Jackson2Parser in project typescript-generator by vojtechhabarta.
the class ModelCompilerTest method testIntermediateInterfacesWithoutTypeParams.
@Test
public void testIntermediateInterfacesWithoutTypeParams() throws Exception {
final Settings settings = TestUtils.settings();
final Jackson2Parser jacksonParser = new Jackson2Parser(settings, new DefaultTypeProcessor());
final Model model = jacksonParser.parseModel(Implementation.class);
final ModelCompiler modelCompiler = new TypeScriptGenerator(settings).getModelCompiler();
final TsModel result = modelCompiler.javaToTypeScript(model);
Assert.assertThat(result.getBean(WithoutTypeParam.class).getProperties().get(0).tsType, CoreMatchers.instanceOf(TsType.UnionType.class));
}
use of cz.habarta.typescript.generator.parser.Jackson2Parser in project typescript-generator by vojtechhabarta.
the class EnumConstantsExtensionTest method basicTest.
@Test
public void basicTest() {
final List<String> lines = new ArrayList<>();
final EmitterExtension.Writer writer = new EmitterExtension.Writer() {
@Override
public void writeIndentedLine(String line) {
lines.add(line);
}
};
final Settings settings = new Settings();
settings.sortDeclarations = true;
final TypeProcessor typeProcessor = new DefaultTypeProcessor();
final Model model = new Jackson2Parser(settings, typeProcessor).parseModel(Direction.class);
final TsModel tsModel = new ModelCompiler(settings, typeProcessor).javaToTypeScript(model);
new EnumConstantsExtension().emitElements(writer, settings, false, tsModel);
String indent = settings.indentString;
Assert.assertEquals(7, lines.size());
Assert.assertEquals("", lines.get(0));
Assert.assertEquals("const Direction = {", lines.get(1));
Assert.assertEquals(indent + "North: <Direction>\"North\",", lines.get(2));
Assert.assertEquals(indent + "East: <Direction>\"East\",", lines.get(3));
Assert.assertEquals(indent + "South: <Direction>\"South\",", lines.get(4));
Assert.assertEquals(indent + "West: <Direction>\"West\",", lines.get(5));
Assert.assertEquals("}", lines.get(6));
}
use of cz.habarta.typescript.generator.parser.Jackson2Parser in project typescript-generator by vojtechhabarta.
the class ModelCompilerTest method testIntermediateInterfacesWithTypeParams.
@Test
public void testIntermediateInterfacesWithTypeParams() throws Exception {
final Settings settings = TestUtils.settings();
final Jackson2Parser jacksonParser = new Jackson2Parser(settings, new DefaultTypeProcessor());
final Model model = jacksonParser.parseModel(Implementation.class);
final ModelCompiler modelCompiler = new TypeScriptGenerator(settings).getModelCompiler();
final TsModel result = modelCompiler.javaToTypeScript(model);
Assert.assertThat(result.getBean(WithTypeParam.class).getProperties().get(0).tsType, CoreMatchers.instanceOf(TsType.UnionType.class));
}
use of cz.habarta.typescript.generator.parser.Jackson2Parser in project typescript-generator by vojtechhabarta.
the class BeanPropertyPathExtensionTest method basicTest.
@Test
public void basicTest() throws Exception {
final StringBuilder data = new StringBuilder();
final EmitterExtension.Writer writer = new EmitterExtension.Writer() {
@Override
public void writeIndentedLine(String line) {
data.append(line + "\n");
}
};
final Settings settings = new Settings();
settings.sortDeclarations = true;
final TypeProcessor typeProcessor = new DefaultTypeProcessor();
final Model model = new Jackson2Parser(settings, typeProcessor).parseModel(ClassA.class);
final TsModel tsModel = new ModelCompiler(settings, typeProcessor).javaToTypeScript(model);
new BeanPropertyPathExtension().emitElements(writer, settings, false, tsModel);
String dataStr = data.toString();
final String expected = Utils.readString(getClass().getResourceAsStream("/ext/expected.ts"), "\n");
Assert.assertEquals(expected.trim(), dataStr.trim());
}
Aggregations