/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.yoko.tools.processors;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import junit.framework.TestCase;
import org.apache.yoko.tools.common.ProcessorEnvironment;
import org.apache.yoko.tools.common.ToolCorbaConstants;
import org.apache.yoko.tools.processors.idl.IDLToWSDLProcessor;
public class IDLToWSDLGenerationTest extends TestCase {
public static final String START_COMMENT = "<!--";
public static final String END_COMMENT = "-->";
public IDLToWSDLGenerationTest(String name) {
super(name);
}
protected void setUp() {
}
protected void tearDown() {
}
public static void main(String args[]) {
junit.textui.TestRunner.run(IDLToWSDLGenerationTest.class);
}
public void testWSDLGeneration(String sourceIdlFilename,
String expectedWsdlFilename)
throws Exception {
URL idl = getClass().getResource(sourceIdlFilename);
ProcessorEnvironment env = new ProcessorEnvironment();
Map<String, Object> cfg = new HashMap<String, Object>();
cfg.put(ToolCorbaConstants.CFG_IDLFILE, idl.getFile());
env.setParameters(cfg);
IDLToWSDLProcessor processor = new IDLToWSDLProcessor();
processor.setEnvironment(env);
java.io.CharArrayWriter out = new java.io.CharArrayWriter();
processor.setOutputWriter(out);
processor.process();
InputStream origstream = getClass().getResourceAsStream(expectedWsdlFilename);
byte orig[] = inputStreamToBytes(origstream);
checkWSDLStrings(orig, out.toString().getBytes());
}
private void checkWSDLStrings(byte orig[], byte generated[]) throws Exception {
BufferedReader origReader =
new BufferedReader(new InputStreamReader(new java.io.ByteArrayInputStream(orig)));
BufferedReader genReader =
new BufferedReader(new InputStreamReader(new java.io.ByteArrayInputStream(generated)));
String sorig = origReader.readLine();
String sgen = genReader.readLine();
boolean origComment = false;
boolean genComment = false;
while (sorig != null && sgen != null) {
if (sorig.trim().startsWith(START_COMMENT)) {
origComment = true;
}
if (sgen.trim().startsWith(START_COMMENT)) {
genComment = true;
}
if ((!origComment) && (!genComment)) {
assertEquals(sorig, sgen);
sgen = genReader.readLine();
sorig = origReader.readLine();
}
if (sorig != null && sgen != null) {
if (sorig.trim().endsWith(END_COMMENT)) {
origComment = false;
sorig = origReader.readLine();
}
if (sgen.trim().endsWith(END_COMMENT)) {
genComment = false;
sgen = genReader.readLine();
}
if (genComment) {
sgen = genReader.readLine();
}
if (origComment) {
sorig = origReader.readLine();
}
}
}
}
public byte[] inputStreamToBytes(InputStream in) throws Exception {
java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream(1024);
byte[] buffer = new byte[1024];
int len;
while ((len = in.read(buffer)) >= 0) {
out.write(buffer, 0, len);
}
in.close();
out.close();
return out.toByteArray();
}
public void testHelloWorldWSDLGeneration() throws Exception {
testWSDLGeneration("/idl/HelloWorld.idl", "/idl/expected_HelloWorld.wsdl");
}
public void testPrimitivesGeneration() throws Exception {
testWSDLGeneration("/idl/primitives.idl", "/idl/expected_Primitives.wsdl");
}
public void testExceptionGeneration() throws Exception {
testWSDLGeneration("/idl/Exception.idl", "/idl/expected_Exception.wsdl");
}
public void testStructGeneration() throws Exception {
testWSDLGeneration("/idl/Struct.idl", "/idl/expected_Struct.wsdl");
}
public void testOnewayGeneration() throws Exception {
testWSDLGeneration("/idl/Oneway.idl", "/idl/expected_Oneway.wsdl");
}
public void testConstGeneration() throws Exception {
testWSDLGeneration("/idl/Const.idl", "/idl/expected_Const.wsdl");
}
public void testEnumGeneration() throws Exception {
testWSDLGeneration("/idl/Enum.idl", "/idl/expected_Enum.wsdl");
}
public void testUnionGeneration() throws Exception {
testWSDLGeneration("/idl/Union.idl", "/idl/expected_Union.wsdl");
}
public void testFixedGeneration() throws Exception {
testWSDLGeneration("/idl/Fixed.idl", "/idl/expected_Fixed.wsdl");
}
public void testTypedefGeneration() throws Exception {
testWSDLGeneration("/idl/Typedef.idl", "/idl/expected_Typedef.wsdl");
}
public void testStringGeneration() throws Exception {
testWSDLGeneration("/idl/String.idl", "/idl/expected_String.wsdl");
}
public void testAttributesGeneration() throws Exception {
testWSDLGeneration("/idl/Attributes.idl", "/idl/expected_Attributes.wsdl");
}
public void testSequenceGeneration() throws Exception {
testWSDLGeneration("/idl/Sequence.idl", "/idl/expected_Sequence.wsdl");
}
public void testArrayGeneration() throws Exception {
testWSDLGeneration("/idl/Array.idl", "/idl/expected_Array.wsdl");
}
public void testAnonarrayGeneration() throws Exception {
testWSDLGeneration("/idl/Anonarray.idl", "/idl/expected_Anonarray.wsdl");
}
public void testAnonsequenceGeneration() throws Exception {
testWSDLGeneration("/idl/Anonsequence.idl", "/idl/expected_Anonsequence.wsdl");
}
public void testAnonboundedsequenceGeneration() throws Exception {
testWSDLGeneration("/idl/Anonboundedsequence.idl", "/idl/expected_Anonboundedsequence.wsdl");
}
public void testAnonstringGeneration() throws Exception {
testWSDLGeneration("/idl/Anonstring.idl", "/idl/expected_Anonstring.wsdl");
}
public void testMultipleDeclaratorsGeneration() throws Exception {
testWSDLGeneration("/idl/Declarators.idl", "/idl/expected_Declarators.wsdl");
}
}