use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class JAXRSContainerTest method testComplexPath.
@Test
public void testComplexPath() {
try {
JAXRSContainer container = new JAXRSContainer(null);
ToolContext context = new ToolContext();
context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/testComplexPath.xml"));
context.put(WadlToolConstants.CFG_COMPILE, "true");
container.setContext(context);
container.execute();
assertNotNull(output.list());
List<File> files = FileUtils.getFilesRecurse(output, ".+\\." + "class" + "$");
assertEquals(1, files.size());
assertTrue(checkContains(files, "application.Resource.class"));
@SuppressWarnings("resource") ClassLoader loader = new URLClassLoader(new URL[] { output.toURI().toURL() });
Class<?> test1 = loader.loadClass("application.Resource");
Method[] test1Methods = test1.getDeclaredMethods();
assertEquals(2, test1Methods.length);
assertEquals(2, test1Methods[0].getAnnotations().length);
if ("getGetaddmethod2".equals(test1Methods[0].getName())) {
Method tmp = test1Methods[0];
test1Methods[0] = test1Methods[1];
test1Methods[1] = tmp;
}
checkComplexPathMethod(test1Methods[0], "");
checkComplexPathMethod(test1Methods[1], "2");
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class JAXRSContainerTest method testOnewayMethod.
@Test
public void testOnewayMethod() throws Exception {
JAXRSContainer container = new JAXRSContainer(null);
final String onewayMethod = "deleteRepository";
ToolContext context = new ToolContext();
context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/test.xml"));
context.put(WadlToolConstants.CFG_COMPILE, "true");
context.put(WadlToolConstants.CFG_ONEWAY, onewayMethod);
container.setContext(context);
container.execute();
assertNotNull(output.list());
ClassCollector cc = context.get(ClassCollector.class);
assertEquals(1, cc.getServiceClassNames().size());
try (URLClassLoader loader = new URLClassLoader(new URL[] { output.toURI().toURL() })) {
final Class<?> generatedClass = loader.loadClass(cc.getServiceClassNames().values().iterator().next());
Method m = generatedClass.getMethod(onewayMethod, String.class);
assertNotNull(m.getAnnotation(Oneway.class));
}
}
use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class JAXRSContainerTest method testQueryMultipartParam.
@Test
public void testQueryMultipartParam() {
try {
JAXRSContainer container = new JAXRSContainer(null);
ToolContext context = new ToolContext();
context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/testQueryMultipartParam.wadl"));
context.put(WadlToolConstants.CFG_COMPILE, "true");
container.setContext(context);
container.execute();
assertNotNull(output.list());
List<File> files = FileUtils.getFilesRecurse(output, ".+\\." + "class" + "$");
assertEquals(2, files.size());
assertTrue(checkContains(files, "application.Test1.class"));
assertTrue(checkContains(files, "application.Test2.class"));
@SuppressWarnings("resource") ClassLoader loader = new URLClassLoader(new URL[] { output.toURI().toURL() });
Class<?> test1 = loader.loadClass("application.Test1");
Method[] test1Methods = test1.getDeclaredMethods();
assertEquals(1, test1Methods.length);
assertEquals(2, test1Methods[0].getAnnotations().length);
assertNotNull(test1Methods[0].getAnnotation(PUT.class));
Consumes consumes1 = test1Methods[0].getAnnotation(Consumes.class);
assertNotNull(consumes1);
assertEquals(1, consumes1.value().length);
assertEquals("multipart/mixed", consumes1.value()[0]);
assertEquals("put", test1Methods[0].getName());
Class<?>[] paramTypes = test1Methods[0].getParameterTypes();
assertEquals(3, paramTypes.length);
Annotation[][] paramAnns = test1Methods[0].getParameterAnnotations();
assertEquals(Boolean.class, paramTypes[0]);
assertEquals(1, paramAnns[0].length);
QueryParam test1QueryParam1 = (QueryParam) paramAnns[0][0];
assertEquals("standalone", test1QueryParam1.value());
assertEquals(String.class, paramTypes[1]);
assertEquals(1, paramAnns[1].length);
Multipart test1MultipartParam1 = (Multipart) paramAnns[1][0];
assertEquals("action", test1MultipartParam1.value());
assertTrue(test1MultipartParam1.required());
assertEquals(String.class, paramTypes[2]);
assertEquals(1, paramAnns[2].length);
Multipart test1MultipartParam2 = (Multipart) paramAnns[2][0];
assertEquals("sources", test1MultipartParam2.value());
assertFalse(test1MultipartParam2.required());
Class<?> test2 = loader.loadClass("application.Test2");
Method[] test2Methods = test2.getDeclaredMethods();
assertEquals(1, test2Methods.length);
assertEquals(2, test2Methods[0].getAnnotations().length);
assertNotNull(test2Methods[0].getAnnotation(PUT.class));
Consumes consumes2 = test2Methods[0].getAnnotation(Consumes.class);
assertNotNull(consumes2);
assertEquals(1, consumes2.value().length);
assertEquals("application/json", consumes2.value()[0]);
assertEquals("put", test2Methods[0].getName());
Class<?>[] paramTypes2 = test2Methods[0].getParameterTypes();
assertEquals(2, paramTypes2.length);
Annotation[][] paramAnns2 = test2Methods[0].getParameterAnnotations();
assertEquals(boolean.class, paramTypes2[0]);
assertEquals(1, paramAnns2[0].length);
QueryParam test2QueryParam1 = (QueryParam) paramAnns2[0][0];
assertEquals("snapshot", test2QueryParam1.value());
assertEquals(String.class, paramTypes2[1]);
assertEquals(0, paramAnns2[1].length);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class JAXRSContainerTest method testCodeGenWithImportedSchemaAndCatalog.
@Test
public void testCodeGenWithImportedSchemaAndCatalog() {
try {
JAXRSContainer container = new JAXRSContainer(null);
ToolContext context = new ToolContext();
context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/bookstoreImportCatalog.xml"));
context.put(WadlToolConstants.CFG_CATALOG, getLocation("/wadl/jax-rs-catalog.xml"));
context.put(WadlToolConstants.CFG_COMPILE, "true");
container.setContext(context);
container.execute();
assertNotNull(output.list());
verifyFiles("java", false, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl", 9);
verifyFiles("class", false, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl", 9);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class JAXRSContainerTest method doTestInlinedSchemasWithImport.
private void doTestInlinedSchemasWithImport(String loc) {
try {
JAXRSContainer container = new JAXRSContainer(null);
ToolContext context = new ToolContext();
context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
context.put(WadlToolConstants.CFG_WADLURL, getLocation(loc));
context.put(WadlToolConstants.CFG_COMPILE, "true");
container.setContext(context);
container.execute();
assertNotNull(output.list());
List<File> files = FileUtils.getFilesRecurse(output, ".+\\." + "class" + "$");
assertEquals(8, files.size());
assertTrue(checkContains(files, "org.apache.cxf.jaxrs.model.wadl" + ".BookStore.class"));
assertTrue(checkContains(files, "org.apache.cxf.jaxrs.model.wadl" + ".PATCH.class"));
assertTrue(checkContains(files, "superbooks" + ".Book.class"));
assertTrue(checkContains(files, "superbooks" + ".ObjectFactory.class"));
assertTrue(checkContains(files, "superbooks" + ".package-info.class"));
assertTrue(checkContains(files, "superchapters" + ".Chapter.class"));
assertTrue(checkContains(files, "superchapters" + ".ObjectFactory.class"));
assertTrue(checkContains(files, "superchapters" + ".package-info.class"));
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
Aggregations