use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class JAXRSContainerTest method testInheritParameters.
@Test
public void testInheritParameters() {
try {
JAXRSContainer container = new JAXRSContainer(null);
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_SCHEMA_TYPE_MAP, "{http://www.w3.org/2001/XMLSchema}anyType=" + "java.io.InputStream");
context.put(WadlToolConstants.CFG_INHERIT_PARAMS, "last");
context.put(WadlToolConstants.CFG_CREATE_JAVA_DOCS, "true");
container.setContext(context);
container.execute();
assertNotNull(output.list());
List<File> files = FileUtils.getFilesRecurse(output, ".+\\." + "class" + "$");
assertEquals(1, files.size());
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class JAXRSContainerTest method testBeanValidation.
@Test
public void testBeanValidation() {
try {
JAXRSContainer container = new JAXRSContainer(null);
ToolContext context = new ToolContext();
context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/resourceSameTargetNsSchemas.xml"));
context.put(WadlToolConstants.CFG_BEAN_VALIDATION, "true");
context.put(WadlToolConstants.CFG_COMPILE, "true");
container.setContext(context);
container.execute();
assertNotNull(output.list());
List<File> files = FileUtils.getFilesRecurse(output, ".+\\." + "class" + "$");
assertEquals(4, 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(1, test1Methods.length);
Method m = test1Methods[0];
assertEquals(5, m.getAnnotations().length);
assertNotNull(m.getAnnotation(Valid.class));
assertNotNull(m.getAnnotation(Path.class));
assertNotNull(m.getAnnotation(Consumes.class));
assertNotNull(m.getAnnotation(Produces.class));
assertNotNull(m.getAnnotation(PUT.class));
Class<?>[] paramTypes = m.getParameterTypes();
assertEquals(2, paramTypes.length);
Annotation[][] paramAnns = m.getParameterAnnotations();
assertEquals(String.class, paramTypes[0]);
assertEquals(1, paramAnns[0].length);
PathParam methodPathParam1 = (PathParam) paramAnns[0][0];
assertEquals("id", methodPathParam1.value());
assertEquals(1, paramAnns[1].length);
assertTrue(paramAnns[1][0] instanceof Valid);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class JAXRSContainerTest method testCodeTwoSchemasSameTargetNs.
@Test
public void testCodeTwoSchemasSameTargetNs() {
try {
JAXRSContainer container = new JAXRSContainer(null);
ToolContext context = new ToolContext();
context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/resourceSameTargetNsSchemas.xml"));
context.put(WadlToolConstants.CFG_COMPILE, "true");
container.setContext(context);
container.execute();
List<File> javaFiles = FileUtils.getFilesRecurse(output, ".+\\." + "java" + "$");
assertEquals(4, javaFiles.size());
assertTrue(checkContains(javaFiles, "application.Resource.java"));
assertTrue(checkContains(javaFiles, "com.example.test.ObjectFactory.java"));
assertTrue(checkContains(javaFiles, "com.example.test.package-info.java"));
assertTrue(checkContains(javaFiles, "com.example.test.TestCompositeObject.java"));
List<File> classFiles = FileUtils.getFilesRecurse(output, ".+\\." + "class" + "$");
assertEquals(4, classFiles.size());
assertTrue(checkContains(classFiles, "application.Resource.class"));
assertTrue(checkContains(classFiles, "com.example.test.ObjectFactory.class"));
assertTrue(checkContains(classFiles, "com.example.test.package-info.class"));
assertTrue(checkContains(classFiles, "com.example.test.TestCompositeObject.class"));
assertNotNull(output.list());
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class JAXRSContainerTest method testCodeGenWithResourceSet.
@Test
public void testCodeGenWithResourceSet() {
try {
JAXRSContainer container = new JAXRSContainer(null);
ToolContext context = new ToolContext();
context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/singleResourceWithRefs.xml"));
context.put(WadlToolConstants.CFG_RESOURCENAME, "CustomResource");
context.put(WadlToolConstants.CFG_COMPILE, "true");
container.setContext(context);
container.execute();
assertNotNull(output.list());
List<File> javaFiles = FileUtils.getFilesRecurse(output, ".+\\." + "java" + "$");
assertEquals(1, javaFiles.size());
assertTrue(checkContains(javaFiles, "application.CustomResource.java"));
List<File> classFiles = FileUtils.getFilesRecurse(output, ".+\\." + "class" + "$");
assertEquals(1, classFiles.size());
assertTrue(checkContains(classFiles, "application.CustomResource.class"));
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class JAXRSContainerTest method testCodeGenInterfacesWithBinding.
@Test
public void testCodeGenInterfacesWithBinding() {
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_BINDING, getLocation("/wadl/jaxbBinding.xml"));
context.put(WadlToolConstants.CFG_COMPILE, "true");
container.setContext(context);
container.execute();
assertNotNull(output.list());
verifyFiles("java", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl", 11, true);
verifyFiles("class", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl", 11, true);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
Aggregations