001: package org.netbeans.modules.e2e.wsdl.wsdl2java;
002:
003: import java.io.File;
004: import java.util.HashMap;
005: import java.util.HashSet;
006: import java.util.List;
007: import junit.framework.*;
008: import java.util.Set;
009: import javax.lang.model.element.ExecutableElement;
010: import javax.lang.model.element.TypeElement;
011: import javax.lang.model.type.TypeMirror;
012: import org.netbeans.modules.e2e.api.wsdl.wsdl2java.WSDL2Java;
013: import org.openide.filesystems.FileUtil;
014:
015: /**
016: *
017: * @author Lukas Waldmann
018: */
019: public class WSDL2JavaImplTest extends TestCase {
020: final String outputDir = "C:\\WSDL";
021: final String wsdlFile = "C:\\WSDL\\QuizService.wsdl";
022: final String pack = "test";
023:
024: Set<String> generatedFiles;
025: HashMap<String, Object> report = new HashMap<String, Object>();
026:
027: public WSDL2JavaImplTest(String testName) {
028: super (testName);
029: }
030:
031: protected void setUp() throws Exception {
032: WSDL2Java.Configuration conf = new WSDL2Java.Configuration();
033: conf.setOutputDirectory(outputDir);
034: conf.setWSDLFileName(wsdlFile);
035: conf.setPackageName(pack);
036: org.netbeans.modules.e2e.wsdl.wsdl2java.WSDL2JavaImpl instance = new WSDL2JavaImpl(
037: conf);
038:
039: boolean result = instance.generate();
040: }
041:
042: protected void tearDown() throws Exception {
043: }
044:
045: /**
046: * Test of generate method, of class org.netbeans.modules.e2e.wsdl.wsdl2java.WSDL2JavaImpl.
047: */
048: public void testGenerate() {
049: System.out.println("generate");
050:
051: for (String fName : generatedFiles) {
052: HashMap<String, Object> expectedClasses = (HashMap<String, Object>) report
053: .remove(fName);
054: assertNotNull("File " + fName
055: + " was not expected to be generated",
056: expectedClasses);
057:
058: File file = new File(outputDir + File.separator + fName);
059: ClassExplorer explorer = new ClassExplorer(FileUtil
060: .toFileObject(file));
061: List<TypeElement> generatedTypes = explorer.getClasses();
062: assertTrue("Generated classes for file " + fName
063: + " doesn't match expected", explorer
064: .compareClasses(expectedClasses.keySet(),
065: generatedTypes));
066: for (TypeElement type : generatedTypes) {
067: HashMap<String, Object> expectedMethods = (HashMap<String, Object>) expectedClasses
068: .remove(type.toString());
069: Set<String> methods = new HashSet<String>();
070: HashMap<String, String> retTypes = new HashMap<String, String>();
071: for (String metret : expectedMethods.keySet()) {
072: int pos = metret.indexOf('|');
073: String method = metret.substring(0, pos - 1);
074: methods.add(method);
075: retTypes.put(method, metret.substring(pos + 1));
076: }
077: List<ExecutableElement> generatedMethods = explorer
078: .getMethods(type);
079: assertTrue("Generated methods for class "
080: + type.toString() + " doesn't match expected",
081: explorer.compareMethods(methods,
082: generatedMethods));
083: for (ExecutableElement method : generatedMethods) {
084: //Check return type
085: assertEquals("Return type of method "
086: + method.toString()
087: + " doesn't match expected", retTypes
088: .get(method.toString()), explorer
089: .getReturnType(method));
090:
091: Set<String> expectedParameters = (Set<String>) expectedMethods
092: .remove(method.toString() + '|'
093: + retTypes.get(method.toString()));
094: assertNotNull("Method " + method.toString()
095: + " was not expected to be generated",
096: expectedParameters);
097:
098: List<TypeMirror> generatedParameters = explorer
099: .getParameters(method);
100: assertTrue("Generated classes for file " + fName
101: + " doesn't match expected", explorer
102: .compareParameters(expectedParameters,
103: generatedParameters));
104: }
105: if (!expectedMethods.isEmpty()) {
106: fail("Following methods "
107: + expectedMethods.keySet() + " of class "
108: + type.toString()
109: + " were not generated for file " + fName);
110: }
111: }
112: if (!expectedClasses.isEmpty()) {
113: fail("Following classes " + expectedClasses.keySet()
114: + " were not generated for file " + fName);
115: }
116: }
117: if (!report.isEmpty()) {
118: fail("Following files were not generated: "
119: + report.keySet());
120: }
121: }
122: }
|