Search in sources :

Example 26 with ToolContext

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

the class JAXRSContainerTest method testCodeGenNoIds.

@Test
public void testCodeGenNoIds() {
    try {
        JAXRSContainer container = new JAXRSContainer(null);
        ToolContext context = new ToolContext();
        context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
        context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/singleResource.xml"));
        context.put(WadlToolConstants.CFG_RESOURCENAME, "CustomResource");
        context.put(WadlToolConstants.CFG_GENERATE_ENUMS, "true");
        context.put(WadlToolConstants.CFG_COMPILE, "true");
        container.setContext(context);
        container.execute();
        assertNotNull(output.list());
        List<File> javaFiles = FileUtils.getFilesRecurse(output, ".+\\." + "java" + "$");
        assertEquals(2, javaFiles.size());
        assertTrue(checkContains(javaFiles, "application.CustomResource.java"));
        assertTrue(checkContains(javaFiles, "application.Theid.java"));
        List<File> classFiles = FileUtils.getFilesRecurse(output, ".+\\." + "class" + "$");
        assertEquals(2, classFiles.size());
        assertTrue(checkContains(classFiles, "application.CustomResource.class"));
        assertTrue(checkContains(classFiles, "application.Theid.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 27 with ToolContext

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

the class JAXRSContainerTest method testCodeGenNoIds2.

@Test
public void testCodeGenNoIds2() {
    try {
        JAXRSContainer container = new JAXRSContainer(null);
        ToolContext context = new ToolContext();
        context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
        context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/multipleResources.xml"));
        context.put(WadlToolConstants.CFG_COMPILE, "true");
        container.setContext(context);
        container.execute();
        assertNotNull(output.list());
        List<File> javaFiles = FileUtils.getFilesRecurse(output, ".+\\." + "java" + "$");
        assertEquals(2, javaFiles.size());
        assertTrue(checkContains(javaFiles, "application.BookstoreResource.java"));
        assertTrue(checkContains(javaFiles, "application.BooksResource.java"));
        List<File> classFiles = FileUtils.getFilesRecurse(output, ".+\\." + "class" + "$");
        assertEquals(2, classFiles.size());
        assertTrue(checkContains(classFiles, "application.BookstoreResource.class"));
        assertTrue(checkContains(classFiles, "application.BooksResource.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 28 with ToolContext

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

the class JAXRSContainerTest method testCodeGenInterfacesCustomPackageForResourcesAndSchemas.

@Test
public void testCodeGenInterfacesCustomPackageForResourcesAndSchemas() {
    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_PACKAGENAME, "custom.books.service");
        context.put(WadlToolConstants.CFG_SCHEMA_PACKAGENAME, "http://superbooks=custom.books.schema");
        context.put(WadlToolConstants.CFG_COMPILE, "true");
        container.setContext(context);
        container.execute();
        assertNotNull(output.list());
        verifyFiles("java", true, false, "custom.books.schema", "custom.books.service", 11, true);
        verifyFiles("class", true, false, "custom.books.schema", "custom.books.service", 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 29 with ToolContext

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

the class ValidateWadlTest method testInvalidParameterStyle.

@Test
public void testInvalidParameterStyle() throws Exception {
    try {
        JAXRSContainer container = new JAXRSContainer(null);
        ToolContext context = new ToolContext();
        context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/invalidParamStyle.xml"));
        container.setContext(context);
        container.execute();
        fail();
    } catch (ValidationException e) {
        String message = e.getMessage();
        assertTrue(message.startsWith("Unsupported parameter style: plain"));
    }
}
Also used : ToolContext(org.apache.cxf.tools.common.ToolContext) Test(org.junit.Test)

Example 30 with ToolContext

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

the class WADLToJavaTest method testGenerateJAXBToStringAndEqualsAndHashCode.

@Test
public void testGenerateJAXBToStringAndEqualsAndHashCode() throws Exception {
    try {
        String[] args = new String[] { "-d", output.getCanonicalPath(), "-p", "custom.service", "-async getName,delete", "-compile", "-xjc-XtoString", "-xjc-Xequals", "-xjc-XhashCode", getLocation("/wadl/bookstore.xml") };
        WADLToJava tool = new WADLToJava(args);
        tool.run(new ToolContext());
        assertNotNull(output.list());
        verifyFiles("java", true, false, "superbooks", "custom.service");
        verifyFiles("class", true, false, "superbooks", "custom.service");
        List<Class<?>> schemaClassFiles = getSchemaClassFiles();
        assertEquals(4, schemaClassFiles.size());
        for (Class<?> c : schemaClassFiles) {
            c.getMethod("toString");
            c.getMethod("hashCode");
            c.getMethod("equals", Object.class);
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : WADLToJava(org.apache.cxf.tools.wadlto.WADLToJava) 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