Search in sources :

Example 51 with ToolContext

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

the class ValidateWadlTest method testInvalidWadl.

@Test
public void testInvalidWadl() throws Exception {
    try {
        JAXRSContainer container = new JAXRSContainer(null);
        ToolContext context = new ToolContext();
        context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/invalidWadl.xml"));
        context.put(WadlToolConstants.CFG_VALIDATE_WADL, "true");
        container.setContext(context);
        container.execute();
        fail("Validation exception expected");
    } catch (ValidationException e) {
    // expected
    }
}
Also used : ToolContext(org.apache.cxf.tools.common.ToolContext) Test(org.junit.Test)

Example 52 with ToolContext

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

the class WADLToJavaTest method testGenerateJAXBToString.

@Test
public void testGenerateJAXBToString() throws Exception {
    try {
        String[] args = new String[] { "-d", output.getCanonicalPath(), "-p", "custom.service", "-async getName,delete", "-compile", "-xjc-episode " + output.getAbsolutePath() + "/test.episode", "-xjc-XtoString", 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");
        assertTrue(new File(output.getAbsolutePath() + "/test.episode").exists());
        List<Class<?>> schemaClassFiles = getSchemaClassFiles();
        assertEquals(4, schemaClassFiles.size());
        for (Class<?> c : schemaClassFiles) {
            c.getMethod("toString");
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : WADLToJava(org.apache.cxf.tools.wadlto.WADLToJava) ToolContext(org.apache.cxf.tools.common.ToolContext) File(java.io.File) URISyntaxException(java.net.URISyntaxException) Test(org.junit.Test)

Example 53 with ToolContext

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

the class WADLToJavaTest method testCodeGenInterfaces.

@Test
public void testCodeGenInterfaces() {
    try {
        String[] args = new String[] { "-d", output.getCanonicalPath(), "-p", "custom.service", "-tMap", "{http://www.w3.org/2001/XMLSchema}date=java.util.List..String", "-async getName,delete", "-inheritResourceParams first", "-compile", 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");
    } 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)

Example 54 with ToolContext

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

the class WSDLToJavaContainerTest method testValidateorSuppressWarningsIsOn.

@Test
public void testValidateorSuppressWarningsIsOn() throws Exception {
    WSDLToJavaContainer container = new WSDLToJavaContainer("dummy", null);
    ToolContext context = new ToolContext();
    context.put(ToolConstants.CFG_WSDLURL, getLocation("hello_world.wsdl"));
    container.setContext(context);
    try {
        container.execute();
    } catch (ToolException te) {
        assertEquals(getLogMessage("FOUND_NO_FRONTEND"), te.getMessage());
    } catch (Exception e) {
        fail("Should not throw any exception but ToolException.");
    }
    assertTrue(context.optionSet(ToolConstants.CFG_SUPPRESS_WARNINGS));
}
Also used : ToolContext(org.apache.cxf.tools.common.ToolContext) ToolException(org.apache.cxf.tools.common.ToolException) ToolException(org.apache.cxf.tools.common.ToolException) URISyntaxException(java.net.URISyntaxException) Test(org.junit.Test)

Example 55 with ToolContext

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

the class WSDLToJavaContainerTest method testNoPlugin.

@Test
public void testNoPlugin() throws Exception {
    WSDLToJavaContainer container = new WSDLToJavaContainer("dummy", null);
    ToolContext context = new ToolContext();
    context.put(ToolConstants.CFG_WSDLURL, getLocation("hello_world.wsdl"));
    container.setContext(context);
    try {
        container.execute();
    } catch (ToolException te) {
        assertEquals(getLogMessage("FOUND_NO_FRONTEND"), te.getMessage());
    } catch (Exception e) {
        fail("Should not throw any exception but ToolException.");
    }
}
Also used : ToolContext(org.apache.cxf.tools.common.ToolContext) ToolException(org.apache.cxf.tools.common.ToolException) ToolException(org.apache.cxf.tools.common.ToolException) 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