@Test public void nestedSelfRefsInStringContentWithoutParentFile() throws NoSuchMethodException, ClassNotFoundException, IOException { String schemaContents = IOUtils.toString( CodeGenerationHelper.class.getResource("/schema/ref/nestedSelfRefsReadAsString.json")); JCodeModel codeModel = new JCodeModel(); new SchemaMapper().generate(codeModel, "NestedSelfRefsInString", "com.example", schemaContents); codeModel.build(schemaRule.getGenerateDir()); ClassLoader classLoader = schemaRule.compile(); Class<?> nestedSelfRefs = classLoader.loadClass("com.example.NestedSelfRefsInString"); assertThat( nestedSelfRefs.getMethod("getThings").getReturnType().getSimpleName(), equalTo("List")); Class<?> listEntryType = (Class<?>) ((ParameterizedType) nestedSelfRefs.getMethod("getThings").getGenericReturnType()) .getActualTypeArguments()[0]; assertThat(listEntryType.getName(), equalTo("com.example.Thing")); Class<?> thingClass = classLoader.loadClass("com.example.Thing"); assertThat( thingClass.getMethod("getNamespace").getReturnType().getSimpleName(), equalTo("String")); assertThat(thingClass.getMethod("getName").getReturnType().getSimpleName(), equalTo("String")); assertThat( thingClass.getMethod("getVersion").getReturnType().getSimpleName(), equalTo("String")); }
@BeforeClass public static void generateAndCompileEnum() throws ClassNotFoundException { ClassLoader selfRefsClassLoader = classSchemaRule.generateAndCompile("/schema/ref/selfRefs.json", "com.example"); selfRefsClass = selfRefsClassLoader.loadClass("com.example.SelfRefs"); }