use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class JAXRSContainerTest method testCodeGenNoIds.
@Test
public void testCodeGenNoIds() {
try {
JAXRSContainer container = new JAXRSContainer(null);
ToolContext context = new ToolContext();
context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/singleResource.xml"));
context.put(WadlToolConstants.CFG_RESOURCENAME, "CustomResource");
context.put(WadlToolConstants.CFG_GENERATE_ENUMS, "true");
context.put(WadlToolConstants.CFG_COMPILE, "true");
container.setContext(context);
container.execute();
assertNotNull(output.list());
List<File> javaFiles = FileUtils.getFilesRecurse(output, ".+\\." + "java" + "$");
assertEquals(2, javaFiles.size());
assertTrue(checkContains(javaFiles, "application.CustomResource.java"));
assertTrue(checkContains(javaFiles, "application.Theid.java"));
List<File> classFiles = FileUtils.getFilesRecurse(output, ".+\\." + "class" + "$");
assertEquals(2, classFiles.size());
assertTrue(checkContains(classFiles, "application.CustomResource.class"));
assertTrue(checkContains(classFiles, "application.Theid.class"));
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class JAXRSContainerTest method testCodeGenNoIds2.
@Test
public void testCodeGenNoIds2() {
try {
JAXRSContainer container = new JAXRSContainer(null);
ToolContext context = new ToolContext();
context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/multipleResources.xml"));
context.put(WadlToolConstants.CFG_COMPILE, "true");
container.setContext(context);
container.execute();
assertNotNull(output.list());
List<File> javaFiles = FileUtils.getFilesRecurse(output, ".+\\." + "java" + "$");
assertEquals(2, javaFiles.size());
assertTrue(checkContains(javaFiles, "application.BookstoreResource.java"));
assertTrue(checkContains(javaFiles, "application.BooksResource.java"));
List<File> classFiles = FileUtils.getFilesRecurse(output, ".+\\." + "class" + "$");
assertEquals(2, classFiles.size());
assertTrue(checkContains(classFiles, "application.BookstoreResource.class"));
assertTrue(checkContains(classFiles, "application.BooksResource.class"));
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class JAXRSContainerTest method testCodeGenInterfacesCustomPackageForResourcesAndSchemas.
@Test
public void testCodeGenInterfacesCustomPackageForResourcesAndSchemas() {
try {
JAXRSContainer container = new JAXRSContainer(null);
ToolContext context = new ToolContext();
context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/bookstore.xml"));
context.put(WadlToolConstants.CFG_PACKAGENAME, "custom.books.service");
context.put(WadlToolConstants.CFG_SCHEMA_PACKAGENAME, "http://superbooks=custom.books.schema");
context.put(WadlToolConstants.CFG_COMPILE, "true");
container.setContext(context);
container.execute();
assertNotNull(output.list());
verifyFiles("java", true, false, "custom.books.schema", "custom.books.service", 11, true);
verifyFiles("class", true, false, "custom.books.schema", "custom.books.service", 11, true);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class ValidateWadlTest method testInvalidParameterStyle.
@Test
public void testInvalidParameterStyle() throws Exception {
try {
JAXRSContainer container = new JAXRSContainer(null);
ToolContext context = new ToolContext();
context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/invalidParamStyle.xml"));
container.setContext(context);
container.execute();
fail();
} catch (ValidationException e) {
String message = e.getMessage();
assertTrue(message.startsWith("Unsupported parameter style: plain"));
}
}
use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class WADLToJavaTest method testGenerateJAXBToStringAndEqualsAndHashCode.
@Test
public void testGenerateJAXBToStringAndEqualsAndHashCode() throws Exception {
try {
String[] args = new String[] { "-d", output.getCanonicalPath(), "-p", "custom.service", "-async getName,delete", "-compile", "-xjc-XtoString", "-xjc-Xequals", "-xjc-XhashCode", getLocation("/wadl/bookstore.xml") };
WADLToJava tool = new WADLToJava(args);
tool.run(new ToolContext());
assertNotNull(output.list());
verifyFiles("java", true, false, "superbooks", "custom.service");
verifyFiles("class", true, false, "superbooks", "custom.service");
List<Class<?>> schemaClassFiles = getSchemaClassFiles();
assertEquals(4, schemaClassFiles.size());
for (Class<?> c : schemaClassFiles) {
c.getMethod("toString");
c.getMethod("hashCode");
c.getMethod("equals", Object.class);
}
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
Aggregations