Search in sources :

Example 46 with ToolContext

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

the class JAXRSContainerTest method testNoTargetNamespace.

@Test
public void testNoTargetNamespace() {
    try {
        JAXRSContainer container = new JAXRSContainer(null);
        ToolContext context = new ToolContext();
        context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
        context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/resourceSchemaNoTargetNamespace.xml"));
        context.put(WadlToolConstants.CFG_SCHEMA_PACKAGENAME, "=custom");
        context.put(WadlToolConstants.CFG_COMPILE, "true");
        container.setContext(context);
        container.execute();
        assertNotNull(output.list());
        List<File> files = FileUtils.getFilesRecurse(output, ".+\\.class" + "$");
        assertEquals(3, files.size());
        assertTrue(checkContains(files, "application" + ".Resource.class"));
        assertTrue(checkContains(files, "custom" + ".TestCompositeObject.class"));
        assertTrue(checkContains(files, "custom" + ".ObjectFactory.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 47 with ToolContext

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

the class JAXRSContainerTest method testResourceWithEPRNoSchemaGen.

@Test
public void testResourceWithEPRNoSchemaGen() {
    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/2005/08/addressing}EndpointReferenceType=" + "javax.xml.ws.wsaddressing.W3CEndpointReference");
        context.put(WadlToolConstants.CFG_NO_ADDRESS_BINDING, "true");
        context.put(WadlToolConstants.CFG_NO_TYPES, "true");
        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" + ".BookstoreResource.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 48 with ToolContext

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

the class JAXRSContainerTest method testCodeGenWithImportedSchema.

@Test
public void testCodeGenWithImportedSchema() {
    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_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)

Example 49 with ToolContext

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

the class JAXRSContainerTest method testCodeGenInterfaceAndImpl.

@Test
public void testCodeGenInterfaceAndImpl() {
    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_INTERFACE, "true");
        context.put(WadlToolConstants.CFG_IMPL, "true");
        context.put(WadlToolConstants.CFG_COMPILE, "true");
        container.setContext(context);
        container.execute();
        assertNotNull(output.list());
        verifyFiles("java", true, true, "superbooks", "org.apache.cxf.jaxrs.model.wadl", 14, true);
        verifyFiles("class", true, true, "superbooks", "org.apache.cxf.jaxrs.model.wadl", 14, 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 50 with ToolContext

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

the class JAXRSContainerTest method testCodeGenInterfacesWithJaxbClassNameSuffix.

@Test
public void testCodeGenInterfacesWithJaxbClassNameSuffix() {
    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_JAXB_CLASS_NAME_SUFFIX, "DTO");
        context.put(WadlToolConstants.CFG_BINDING, getLocation("/wadl/jaxbSchemaBindings.xml"));
        context.put(WadlToolConstants.CFG_COMPILE, "true");
        container.setContext(context);
        container.execute();
        assertNotNull(output.list());
        List<File> schemafiles = FileUtils.getFilesRecurse(output, ".+\\." + "java" + "$");
        assertEquals(10, schemafiles.size());
        doVerifyTypesWithSuffix(schemafiles, "superbooks", "java");
        List<File> classfiles = FileUtils.getFilesRecurse(output, ".+\\." + "class" + "$");
        assertEquals(10, classfiles.size());
        doVerifyTypesWithSuffix(classfiles, "superbooks", "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)

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