Search in sources :

Example 21 with ToolContext

use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.

the class JAXRSContainerTest method testCodeGenImpl.

@Test
public void testCodeGenImpl() {
    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_IMPL, "true");
        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) {
        fail();
        e.printStackTrace();
    }
}
Also used : ToolContext(org.apache.cxf.tools.common.ToolContext) URISyntaxException(java.net.URISyntaxException) Test(org.junit.Test)

Example 22 with ToolContext

use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.

the class JAXRSContainerTest method testCodeGenTypesOnly.

@Test
public void testCodeGenTypesOnly() {
    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_TYPES, "true");
        container.setContext(context);
        container.execute();
        assertNotNull(output.list());
        verifyTypes("superbooks", "java", true);
    } catch (Exception e) {
        fail();
        e.printStackTrace();
    }
}
Also used : ToolContext(org.apache.cxf.tools.common.ToolContext) URISyntaxException(java.net.URISyntaxException) Test(org.junit.Test)

Example 23 with ToolContext

use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.

the class JAXRSContainerTest method testResourceWithEPR.

@Test
public void testResourceWithEPR() {
    try {
        JAXRSContainer container = new JAXRSContainer(null);
        ToolContext context = new ToolContext();
        context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
        context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/resourceWithEPR.xml"));
        context.put(WadlToolConstants.CFG_SCHEMA_TYPE_MAP, "{http://www.w3.org/2001/XMLSchema}date=javax.xml.datatype.XMLGregorianCalendar");
        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" + ".BookstoreResource.class"));
        assertTrue(checkContains(files, "superbooks" + ".Book.class"));
        assertTrue(checkContains(files, "superbooks" + ".ObjectFactory.class"));
        assertTrue(checkContains(files, "superbooks" + ".package-info.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 24 with ToolContext

use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.

the class JAXRSContainerTest method testCodeGenInterfaces.

@Test
public void testCodeGenInterfaces() {
    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_MEDIA_TYPE_MAP, "application/xml=javax.xml.transform.Source");
        context.put(WadlToolConstants.CFG_MEDIA_TYPE_MAP, "multipart/form-data=org.apache.cxf.jaxrs.ext.multipart.MultipartBody");
        context.put(WadlToolConstants.CFG_NO_VOID_FOR_EMPTY_RESPONSES, "true");
        context.put(WadlToolConstants.CFG_GENERATE_RESPONSE_IF_HEADERS_SET, "true");
        context.put(WadlToolConstants.CFG_GENERATE_RESPONSE_FOR_METHODS, "getName");
        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)

Example 25 with ToolContext

use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.

the class JAXRSContainerTest method testCodeGenWithImportedSchemaAndBinding.

@Test
public void testCodeGenWithImportedSchemaAndBinding() {
    try {
        JAXRSContainer container = new JAXRSContainer(null);
        ToolContext context = new ToolContext();
        context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
        context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/bookstoreImport.xml"));
        context.put(WadlToolConstants.CFG_BINDING, getLocation("/wadl/jaxbBindingWithSchemaLoc.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();
    }
}
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