Search in sources :

Example 1 with IDLToWSDLProcessor

use of org.apache.cxf.tools.corba.processors.idl.IDLToWSDLProcessor in project cxf by apache.

the class IDLToWSDLGenerationTest method testWSDLGeneration.

public void testWSDLGeneration(String sourceIdlFilename, String expectedWsdlFilename) throws Exception {
    URL idl = getClass().getResource(sourceIdlFilename);
    ProcessorEnvironment env = new ProcessorEnvironment();
    Map<String, Object> cfg = new HashMap<>();
    cfg.put(ToolCorbaConstants.CFG_IDLFILE, new File(idl.toURI()).getAbsolutePath());
    env.setParameters(cfg);
    IDLToWSDLProcessor processor = new IDLToWSDLProcessor();
    processor.setEnvironment(env);
    java.io.CharArrayWriter out = new java.io.CharArrayWriter();
    processor.setOutputWriter(out);
    processor.process();
    URL orig = getClass().getResource(expectedWsdlFilename);
    InputStream actualStream = new ByteArrayInputStream(out.toString().getBytes());
    System.out.println(out.toString());
    assertWsdlEquals(orig.openStream(), actualStream, DEFAULT_IGNORE_ATTR, DEFAULT_IGNORE_TAG);
}
Also used : HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) URL(java.net.URL) IDLToWSDLProcessor(org.apache.cxf.tools.corba.processors.idl.IDLToWSDLProcessor) ByteArrayInputStream(java.io.ByteArrayInputStream) ProcessorEnvironment(org.apache.cxf.tools.corba.common.ProcessorEnvironment) File(java.io.File)

Example 2 with IDLToWSDLProcessor

use of org.apache.cxf.tools.corba.processors.idl.IDLToWSDLProcessor in project cxf by apache.

the class IDLToWSDLGenerationTest method testLogicalPhysicalSchemaGeneration.

public void testLogicalPhysicalSchemaGeneration(String idlFilename, String logicalName, String physicalName, String schemaFilename, String defaultFilename, String importName, String defaultImportName) throws Exception {
    URL idl = getClass().getResource(idlFilename);
    ProcessorEnvironment env = new ProcessorEnvironment();
    Map<String, Object> cfg = new HashMap<>();
    cfg.put(ToolCorbaConstants.CFG_IDLFILE, new File(idl.toURI()).getAbsolutePath());
    if (logicalName != null) {
        cfg.put(ToolCorbaConstants.CFG_LOGICAL, logicalName);
    }
    if (physicalName != null) {
        cfg.put(ToolCorbaConstants.CFG_PHYSICAL, physicalName);
    }
    if (schemaFilename != null) {
        cfg.put(ToolCorbaConstants.CFG_SCHEMA, schemaFilename);
    }
    env.setParameters(cfg);
    IDLToWSDLProcessor processor = new IDLToWSDLProcessor();
    processor.setEnvironment(env);
    java.io.CharArrayWriter outD = new java.io.CharArrayWriter();
    processor.setOutputWriter(outD);
    java.io.CharArrayWriter outL = new java.io.CharArrayWriter();
    java.io.CharArrayWriter outP = new java.io.CharArrayWriter();
    java.io.CharArrayWriter outS = new java.io.CharArrayWriter();
    if (logicalName != null) {
        processor.setLogicalOutputWriter(outL);
    }
    if (physicalName != null) {
        processor.setPhysicalOutputWriter(outP);
    }
    if (schemaFilename != null) {
        processor.setSchemaOutputWriter(outS);
    }
    processor.process();
    String userdir = System.getProperty("user.dir");
    String sep = System.getProperty("file.separator");
    File file = new File(userdir + sep + importName);
    String location = file.toURI().toString();
    File schemaFile = new File(userdir + sep + schemaFilename);
    String schemaLocation = schemaFile.toURI().toString();
    File defaultFile = new File(userdir + sep + defaultImportName);
    String defaultLocation = defaultFile.toURI().toString();
    if (logicalName != null) {
        testCompare(logicalName, outL, schemaLocation);
    }
    if (physicalName != null) {
        testCompare(physicalName, outP, location);
    }
    if (schemaFilename != null) {
        InputStream origSchemaStream = getClass().getResourceAsStream("/idl/" + schemaFilename);
        InputStream actualSchemaStream = new ByteArrayInputStream(outS.toString().getBytes());
        assertWsdlEquals(origSchemaStream, actualSchemaStream, SCHEMA_IGNORE_ATTR, DEFAULT_IGNORE_TAG);
    }
    if (defaultFilename != null) {
        testCompare(defaultFilename, outD, defaultLocation);
    }
}
Also used : HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) URL(java.net.URL) IDLToWSDLProcessor(org.apache.cxf.tools.corba.processors.idl.IDLToWSDLProcessor) ByteArrayInputStream(java.io.ByteArrayInputStream) ProcessorEnvironment(org.apache.cxf.tools.corba.common.ProcessorEnvironment) File(java.io.File)

Example 3 with IDLToWSDLProcessor

use of org.apache.cxf.tools.corba.processors.idl.IDLToWSDLProcessor in project cxf by apache.

the class IDLToWSDLGenerationTest method testEncodingGeneration.

@Test
public void testEncodingGeneration() throws Exception {
    try {
        String sourceIdlFilename = "/idl/Enum.idl";
        URL idl = getClass().getResource(sourceIdlFilename);
        ProcessorEnvironment env = new ProcessorEnvironment();
        Map<String, Object> cfg = new HashMap<>();
        cfg.put(ToolCorbaConstants.CFG_IDLFILE, new File(idl.toURI()).getAbsolutePath());
        cfg.put(ToolCorbaConstants.CFG_WSDL_ENCODING, "UTF-16");
        env.setParameters(cfg);
        IDLToWSDLProcessor processor = new IDLToWSDLProcessor();
        processor.setEnvironment(env);
        Writer out = processor.getOutputWriter("Enum.wsdl", ".");
        if (out instanceof OutputStreamWriter) {
            OutputStreamWriter writer = (OutputStreamWriter) out;
            assertEquals("Encoding should be UTF-16", writer.getEncoding(), "UTF-16");
        }
        out.close();
    } finally {
        new File("Enum.wsdl").deleteOnExit();
    }
}
Also used : HashMap(java.util.HashMap) ProcessorEnvironment(org.apache.cxf.tools.corba.common.ProcessorEnvironment) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) URL(java.net.URL) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) IDLToWSDLProcessor(org.apache.cxf.tools.corba.processors.idl.IDLToWSDLProcessor) Test(org.junit.Test)

Example 4 with IDLToWSDLProcessor

use of org.apache.cxf.tools.corba.processors.idl.IDLToWSDLProcessor in project cxf by apache.

the class IDLToWSDL method execute.

public void execute(boolean exitOnFinish) {
    IDLToWSDLProcessor idlProcessor = new IDLToWSDLProcessor();
    ProcessorEnvironment env = null;
    try {
        super.execute(exitOnFinish);
        if (!hasInfoOption()) {
            env = new ProcessorEnvironment();
            env.setParameters(getParametersMap(getArrayKeys()));
            if (isVerboseOn()) {
                env.put(ToolConstants.CFG_VERBOSE, Boolean.TRUE);
            }
            env.put(ToolConstants.CFG_CMD_ARG, args);
            initialise(env);
            validate(env);
            idlProcessor.setEnvironment(env);
            idlProcessor.process();
        }
    } catch (ToolException ex) {
        err.println("Error : " + ex.getMessage());
        if (ex.getCause() instanceof BadUsageException) {
            printUsageException(TOOL_NAME, (BadUsageException) ex.getCause());
        }
        err.println();
        if (isVerboseOn()) {
            ex.printStackTrace(err);
        }
        throw ex;
    } catch (Exception ex) {
        err.println("Error : " + ex.getMessage());
        err.println();
        if (isVerboseOn()) {
            ex.printStackTrace(err);
        }
        throw new ToolException(ex.getMessage(), ex.getCause());
    }
}
Also used : BadUsageException(org.apache.cxf.tools.common.toolspec.parser.BadUsageException) ProcessorEnvironment(org.apache.cxf.tools.corba.common.ProcessorEnvironment) ToolException(org.apache.cxf.tools.common.ToolException) ToolException(org.apache.cxf.tools.common.ToolException) BadUsageException(org.apache.cxf.tools.common.toolspec.parser.BadUsageException) IDLToWSDLProcessor(org.apache.cxf.tools.corba.processors.idl.IDLToWSDLProcessor)

Aggregations

ProcessorEnvironment (org.apache.cxf.tools.corba.common.ProcessorEnvironment)4 IDLToWSDLProcessor (org.apache.cxf.tools.corba.processors.idl.IDLToWSDLProcessor)4 File (java.io.File)3 URL (java.net.URL)3 HashMap (java.util.HashMap)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 BufferedWriter (java.io.BufferedWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 ToolException (org.apache.cxf.tools.common.ToolException)1 BadUsageException (org.apache.cxf.tools.common.toolspec.parser.BadUsageException)1 Test (org.junit.Test)1