Search in sources :

Example 41 with ToolContext

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();
    }
}
Also used : ToolContext(org.apache.cxf.tools.common.ToolContext) File(java.io.File) URISyntaxException(java.net.URISyntaxException) Test(org.junit.Test)

Example 42 with ToolContext

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();
    }
}
Also used : Path(javax.ws.rs.Path) ToolContext(org.apache.cxf.tools.common.ToolContext) Method(java.lang.reflect.Method) PUT(javax.ws.rs.PUT) URISyntaxException(java.net.URISyntaxException) Valid(javax.validation.Valid) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) PathParam(javax.ws.rs.PathParam) File(java.io.File) Test(org.junit.Test)

Example 43 with ToolContext

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();
    }
}
Also used : ToolContext(org.apache.cxf.tools.common.ToolContext) File(java.io.File) URISyntaxException(java.net.URISyntaxException) Test(org.junit.Test)

Example 44 with ToolContext

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();
    }
}
Also used : ToolContext(org.apache.cxf.tools.common.ToolContext) File(java.io.File) URISyntaxException(java.net.URISyntaxException) Test(org.junit.Test)

Example 45 with ToolContext

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();
    }
}
Also used : ToolContext(org.apache.cxf.tools.common.ToolContext) URISyntaxException(java.net.URISyntaxException) Test(org.junit.Test)

Aggregations

ToolContext (org.apache.cxf.tools.common.ToolContext)69 Test (org.junit.Test)45 URISyntaxException (java.net.URISyntaxException)35 File (java.io.File)23 ToolException (org.apache.cxf.tools.common.ToolException)13 BadUsageException (org.apache.cxf.tools.common.toolspec.parser.BadUsageException)7 WADLToJava (org.apache.cxf.tools.wadlto.WADLToJava)5 BufferedReader (java.io.BufferedReader)4 Method (java.lang.reflect.Method)4 URLClassLoader (java.net.URLClassLoader)4 QName (javax.xml.namespace.QName)4 Before (org.junit.Before)4 FileReader (java.io.FileReader)3 URI (java.net.URI)3 LinkedHashSet (java.util.LinkedHashSet)3 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)3 Artifact (org.apache.maven.artifact.Artifact)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 IOException (java.io.IOException)2 Writer (java.io.Writer)2