Author: mmao
Date: Wed Jun 6 06:23:54 2007
New Revision: 544835
URL: http://svn.apache.org/viewvc?view=rev&rev=544835
Log:
* Update tools doc builder to support more xerces impl
* Fix the tests, if there is xerces impl which version is lower than 2.7.1 in
the classpath, will get the differenet usage output
* Upgrade tools common unit test to junit 4
Modified:
incubator/cxf/trunk/tools/common/pom.xml
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/dom/ExtendedDocumentBuilder.java
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/dom/Messages.properties
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/dom/SchemaValidatingSAXParser.java
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/ToolSpec.java
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/ProcessorEnvironmentTest.java
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/WSDLVersionTest.java
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/dom/DocumentTest.java
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/dom/ExtendedDocumentBuilderTest.java
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/dom/SchemaValidatingSAXParserTest.java
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaClassTest.java
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaInterfaceTest.java
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaParameterTest.java
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaTypeTest.java
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/AbstractToolContainerTest.java
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/ToolExceptionTest.java
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/ToolSpecTest.java
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/ToolSupportTest.java
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java
Modified: incubator/cxf/trunk/tools/common/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/pom.xml?view=diff&rev=544835&r1=544834&r2=544835
==============================================================================
--- incubator/cxf/trunk/tools/common/pom.xml (original)
+++ incubator/cxf/trunk/tools/common/pom.xml Wed Jun 6 06:23:54 2007
@@ -82,7 +82,7 @@
<artifactId>cxf-common-utilities</artifactId>
<version>${project.version}</version>
</dependency>
-
+
</dependencies>
Modified:
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/dom/ExtendedDocumentBuilder.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/dom/ExtendedDocumentBuilder.java?view=diff&rev=544835&r1=544834&r2=544835
==============================================================================
---
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/dom/ExtendedDocumentBuilder.java
(original)
+++
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/dom/ExtendedDocumentBuilder.java
Wed Jun 6 06:23:54 2007
@@ -68,7 +68,11 @@
} catch (org.xml.sax.SAXException e) {
LOG.log(Level.SEVERE, "SCHEMA_FACTORY_EXCEPTION_MSG");
}
- this.parserFactory.setSchema(this.schema);
+ try {
+ this.parserFactory.setSchema(this.schema);
+ } catch (UnsupportedOperationException e) {
+ LOG.log(Level.WARNING, "DOC_PARSER_NOT_SUPPORTED", e);
+ }
}
}
Modified:
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/dom/Messages.properties
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/dom/Messages.properties?view=diff&rev=544835&r1=544834&r2=544835
==============================================================================
---
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/dom/Messages.properties
(original)
+++
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/dom/Messages.properties
Wed Jun 6 06:23:54 2007
@@ -26,3 +26,5 @@
FAIL_SET_SAX_PARSER_MSG=Failed to set Xerces SAX parser property: {0}
+DOC_PARSER_NOT_SUPPORTED = This DocumentBuilderFactory parser does not support
the setSchema {0}
+SAX_PARSER_NOT_SUPPORTED = This SAXParserFactory parser does not support the
setSchema {0}
\ No newline at end of file
Modified:
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/dom/SchemaValidatingSAXParser.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/dom/SchemaValidatingSAXParser.java?view=diff&rev=544835&r1=544834&r2=544835
==============================================================================
---
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/dom/SchemaValidatingSAXParser.java
(original)
+++
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/dom/SchemaValidatingSAXParser.java
Wed Jun 6 06:23:54 2007
@@ -70,7 +70,11 @@
} catch (org.xml.sax.SAXException e) {
LOG.log(Level.SEVERE, "SCHEMA_FACTORY_EXCEPTION_MSG");
}
- this.parserFactory.setSchema(this.schema);
+ try {
+ this.parserFactory.setSchema(this.schema);
+ } catch (UnsupportedOperationException e) {
+ LOG.log(Level.WARNING, "SAX_PARSER_NOT_SUPPORTED", e);
+ }
}
}
Modified:
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/ToolSpec.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/ToolSpec.java?view=diff&rev=544835&r1=544834&r2=544835
==============================================================================
---
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/ToolSpec.java
(original)
+++
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/ToolSpec.java
Wed Jun 6 06:23:54 2007
@@ -23,16 +23,17 @@
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
-
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
+import javax.xml.xpath.XPathConstants;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -41,6 +42,7 @@
import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.XPathUtils;
import org.apache.cxf.tools.common.ToolException;
import org.apache.cxf.tools.common.dom.ExtendedDocumentBuilder;
@@ -101,7 +103,19 @@
}
public Element getElementById(String id) {
- return doc.getElementById(id);
+ Element ele = doc.getElementById(id);
+ if (ele != null) {
+ return ele;
+ }
+
+ XPathUtils xpather = new XPathUtils(new HashMap<String, String>());
+ NodeList nl = (NodeList) xpather.getValue("//[EMAIL PROTECTED]'" + id
+ "']",
+ doc,
+ XPathConstants.NODESET);
+ if (nl != null && nl.getLength() > 0) {
+ return (Element)nl.item(0);
+ }
+ return null;
}
public boolean hasHandler() {
Modified:
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java?view=diff&rev=544835&r1=544834&r2=544835
==============================================================================
---
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java
(original)
+++
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java
Wed Jun 6 06:23:54 2007
@@ -27,7 +27,6 @@
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
-
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
@@ -43,7 +42,6 @@
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.tools.common.toolspec.Tool;
import org.apache.cxf.tools.common.toolspec.ToolSpec;
-
public class CommandLineParser {
Modified:
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/ProcessorEnvironmentTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/ProcessorEnvironmentTest.java?view=diff&rev=544835&r1=544834&r2=544835
==============================================================================
---
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/ProcessorEnvironmentTest.java
(original)
+++
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/ProcessorEnvironmentTest.java
Wed Jun 6 06:23:54 2007
@@ -19,11 +19,14 @@
package org.apache.cxf.tools.common;
-import java.util.*;
+import java.util.HashMap;
+import java.util.Map;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
-public class ProcessorEnvironmentTest extends TestCase {
+public class ProcessorEnvironmentTest extends Assert {
+ @Test
public void testGet() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("k1", "v1");
@@ -33,6 +36,7 @@
assertEquals("v1", value);
}
+ @Test
public void testPut() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("k1", "v1");
@@ -43,6 +47,7 @@
assertEquals("v2", value);
}
+ @Test
public void testRemove() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("k1", "v1");
@@ -55,6 +60,7 @@
assertNull(env.get("k1"));
}
+ @Test
public void testContainsKey() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("k1", "v1");
@@ -63,6 +69,7 @@
assertTrue(env.containsKey("k1"));
}
+ @Test
public void testGetDefaultValue() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("k1", "v1");
@@ -75,6 +82,7 @@
assertEquals("v2", k2);
}
+ @Test
public void testOptionSet() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("k1", "true");
@@ -85,6 +93,7 @@
assertFalse(env.optionSet("k2"));
}
+ @Test
public void testGetBooleanValue() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("k1", "true");
Modified:
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/WSDLVersionTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/WSDLVersionTest.java?view=diff&rev=544835&r1=544834&r2=544835
==============================================================================
---
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/WSDLVersionTest.java
(original)
+++
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/WSDLVersionTest.java
Wed Jun 6 06:23:54 2007
@@ -19,12 +19,13 @@
package org.apache.cxf.tools.common;
-import junit.framework.TestCase;
-
import org.apache.cxf.wsdl.WSDLConstants;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class WSDLVersionTest extends Assert {
-public class WSDLVersionTest extends TestCase {
-
+ @Test
public void testWSDLVersion() {
assertEquals(WSDLConstants.WSDLVersion.WSDL11,
WSDLConstants.getVersion("1.1"));
assertEquals(WSDLConstants.WSDLVersion.WSDL20,
WSDLConstants.getVersion("2.0"));
Modified:
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/dom/DocumentTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/dom/DocumentTest.java?view=diff&rev=544835&r1=544834&r2=544835
==============================================================================
---
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/dom/DocumentTest.java
(original)
+++
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/dom/DocumentTest.java
Wed Jun 6 06:23:54 2007
@@ -19,10 +19,14 @@
package org.apache.cxf.tools.common.dom;
-import junit.framework.*;
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
-public class DocumentTest extends TestCase {
+public class DocumentTest extends Assert {
+ @Test
+ @Ignore
public void testDocument() {
// fail("There are no tests in xutil.dom, put some in!!");
}
Modified:
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/dom/ExtendedDocumentBuilderTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/dom/ExtendedDocumentBuilderTest.java?view=diff&rev=544835&r1=544834&r2=544835
==============================================================================
---
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/dom/ExtendedDocumentBuilderTest.java
(original)
+++
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/dom/ExtendedDocumentBuilderTest.java
Wed Jun 6 06:23:54 2007
@@ -21,9 +21,11 @@
import org.w3c.dom.Document;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
-public class ExtendedDocumentBuilderTest extends TestCase {
+public class ExtendedDocumentBuilderTest extends Assert {
+ @Test
public void testMassMethod() throws Exception {
ExtendedDocumentBuilder builder = new ExtendedDocumentBuilder();
builder.setValidating(false);
@@ -31,6 +33,7 @@
assertTrue(builder.parse(getClass().getResourceAsStream(tsSource)) !=
null);
}
+ @Test
public void testParse() throws Exception {
ExtendedDocumentBuilder builder = new ExtendedDocumentBuilder();
String tsSource =
"/org/apache/cxf/tools/common/toolspec/parser/resources/testtool1.xml";
Modified:
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/dom/SchemaValidatingSAXParserTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/dom/SchemaValidatingSAXParserTest.java?view=diff&rev=544835&r1=544834&r2=544835
==============================================================================
---
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/dom/SchemaValidatingSAXParserTest.java
(original)
+++
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/dom/SchemaValidatingSAXParserTest.java
Wed Jun 6 06:23:54 2007
@@ -19,9 +19,11 @@
package org.apache.cxf.tools.common.dom;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
-public class SchemaValidatingSAXParserTest extends TestCase {
+public class SchemaValidatingSAXParserTest extends Assert {
+ @Test
public void testMassMethod() {
SchemaValidatingSAXParser parser = new SchemaValidatingSAXParser();
parser.setValidating(true);
Modified:
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaClassTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaClassTest.java?view=diff&rev=544835&r1=544834&r2=544835
==============================================================================
---
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaClassTest.java
(original)
+++
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaClassTest.java
Wed Jun 6 06:23:54 2007
@@ -19,10 +19,10 @@
package org.apache.cxf.tools.common.model;
-import junit.framework.TestCase;
+import org.junit.Assert;
import org.junit.Test;
-public class JavaClassTest extends TestCase {
+public class JavaClassTest extends Assert {
@Test
public void testGetterSetter() throws Exception {
JavaField field = new JavaField("arg0",
Modified:
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaInterfaceTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaInterfaceTest.java?view=diff&rev=544835&r1=544834&r2=544835
==============================================================================
---
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaInterfaceTest.java
(original)
+++
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaInterfaceTest.java
Wed Jun 6 06:23:54 2007
@@ -19,10 +19,10 @@
package org.apache.cxf.tools.common.model;
-import junit.framework.TestCase;
+import org.junit.Assert;
import org.junit.Test;
-public class JavaInterfaceTest extends TestCase {
+public class JavaInterfaceTest extends Assert {
@Test
public void testSetFullClassName() throws Exception {
String fullName = "org.apache.cxf.tools.common.model.JavaInterface";
Modified:
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaParameterTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaParameterTest.java?view=diff&rev=544835&r1=544834&r2=544835
==============================================================================
---
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaParameterTest.java
(original)
+++
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaParameterTest.java
Wed Jun 6 06:23:54 2007
@@ -19,10 +19,12 @@
package org.apache.cxf.tools.common.model;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
-public class JavaParameterTest extends TestCase {
-
+public class JavaParameterTest extends Assert {
+
+ @Test
public void testGetHolderDefaultTypeValue() throws Exception {
JavaParameter holderParameter = new JavaParameter("i",
"java.lang.String", null);
holderParameter.setHolder(true);
@@ -35,4 +37,4 @@
assertEquals("new
javax.xml.ws.Holder<org.apache.cxf.tools.common.model.JavaParamter>()",
holderParameter.getDefaultTypeValue());
}
-}
\ No newline at end of file
+}
Modified:
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaTypeTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaTypeTest.java?view=diff&rev=544835&r1=544834&r2=544835
==============================================================================
---
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaTypeTest.java
(original)
+++
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaTypeTest.java
Wed Jun 6 06:23:54 2007
@@ -19,9 +19,11 @@
package org.apache.cxf.tools.common.model;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
-public class JavaTypeTest extends TestCase {
+public class JavaTypeTest extends Assert {
+ @Test
public void testGetPredefinedDefaultTypeValue() throws Exception {
assertEquals("0", new JavaType("i", int.class.getName(),
null).getDefaultTypeValue());
assertEquals("false", new JavaType("i", boolean.class.getName(),
null).getDefaultTypeValue());
@@ -30,11 +32,13 @@
javax.xml.namespace.QName.class.getName(),
null).getDefaultTypeValue());
}
+ @Test
public void testGetArrayDefaultTypeValue() throws Exception {
assertEquals("new int[0]", new JavaType("i", "int[]",
null).getDefaultTypeValue());
assertEquals("new String[0]", new JavaType("i", "String[]",
null).getDefaultTypeValue());
}
+ @Test
public void testGetClassDefaultTypeValue() throws Exception {
assertEquals("new org.apache.cxf.tools.common.model.JavaType()",
new JavaType("i",
"org.apache.cxf.tools.common.model.JavaType", null)
Modified:
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/AbstractToolContainerTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/AbstractToolContainerTest.java?view=diff&rev=544835&r1=544834&r2=544835
==============================================================================
---
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/AbstractToolContainerTest.java
(original)
+++
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/AbstractToolContainerTest.java
Wed Jun 6 06:23:54 2007
@@ -19,21 +19,22 @@
package org.apache.cxf.tools.common.toolspec;
-import junit.framework.TestCase;
import org.apache.cxf.tools.common.ToolException;
-public class AbstractToolContainerTest extends TestCase {
- private DummyToolContainer dummyTool;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
- public AbstractToolContainerTest(String name) {
- super(name);
- }
+public class AbstractToolContainerTest extends Assert {
+ private DummyToolContainer dummyTool;
+ @Before
public void setUp() throws Exception {
String tsSource =
"/org/apache/cxf/tools/common/toolspec/parser/resources/testtool.xml";
ToolSpec toolspec = new
ToolSpec(getClass().getResourceAsStream(tsSource), false);
dummyTool = new DummyToolContainer(toolspec);
}
+ @Test
public void testQuietMode() {
// catch all exception in here.
try {
@@ -46,6 +47,7 @@
assertNotNull("Fail to redirect output:",
dummyTool.getOutOutputStream());
}
+ @Test
public void testInit() {
try {
dummyTool.init();
@@ -56,6 +58,7 @@
assertTrue(true);
}
+ @Test
public void testToolRunner() throws Exception {
String tsSource =
"/org/apache/cxf/tools/common/toolspec/parser/resources/testtool.xml";
String[] args = {"-r", "wsdlurl=dfd"};
Modified:
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/ToolExceptionTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/ToolExceptionTest.java?view=diff&rev=544835&r1=544834&r2=544835
==============================================================================
---
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/ToolExceptionTest.java
(original)
+++
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/ToolExceptionTest.java
Wed Jun 6 06:23:54 2007
@@ -19,9 +19,12 @@
package org.apache.cxf.tools.common.toolspec;
-import junit.framework.TestCase;
import org.apache.cxf.tools.common.ToolException;
-public class ToolExceptionTest extends TestCase {
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ToolExceptionTest extends Assert {
+ @Test
public void testMassMethod() {
ToolException e = new ToolException("e");
assertTrue(e.getCause() == null);
Modified:
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/ToolSpecTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/ToolSpecTest.java?view=diff&rev=544835&r1=544834&r2=544835
==============================================================================
---
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/ToolSpecTest.java
(original)
+++
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/ToolSpecTest.java
Wed Jun 6 06:23:54 2007
@@ -19,18 +19,21 @@
package org.apache.cxf.tools.common.toolspec;
-import junit.framework.TestCase;
import org.apache.cxf.tools.common.ToolException;
-public class ToolSpecTest extends TestCase {
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ToolSpecTest extends Assert {
ToolSpec toolSpec;
+ @Test
public void testConstruct() {
toolSpec = null;
toolSpec = new ToolSpec();
assertTrue(toolSpec != null);
-
}
-
+
+ @Test
public void testConstructFromInputStream() {
String tsSource = "parser/resources/testtool.xml";
try {
@@ -41,6 +44,7 @@
assertTrue(toolSpec.getAnnotation() == null);
}
+ @Test
public void testGetParameterDefault() throws Exception {
String tsSource = "parser/resources/testtool.xml";
@@ -50,17 +54,22 @@
assertTrue(toolSpec.getParameterDefault("namespace") == null);
assertTrue(toolSpec.getParameterDefault("wsdlurl") == null);
}
+
+ @Test
public void testGetStreamRefName1() throws Exception {
String tsSource = "parser/resources/testtool1.xml";
toolSpec = new ToolSpec(getClass().getResourceAsStream(tsSource),
false);
assertEquals("test getStreamRefName failed",
toolSpec.getStreamRefName("streamref"), "namespace");
}
+
+ @Test
public void testGetStreamRefName2() throws Exception {
String tsSource = "parser/resources/testtool2.xml";
toolSpec = new ToolSpec(getClass().getResourceAsStream(tsSource),
false);
assertEquals("test getStreamRefName2 failed",
toolSpec.getStreamRefName("streamref"), "wsdlurl");
}
+ @Test
public void testIsValidInputStream() throws Exception {
String tsSource = "parser/resources/testtool1.xml";
toolSpec = new ToolSpec(getClass().getResourceAsStream(tsSource),
false);
@@ -69,6 +78,7 @@
assertTrue(toolSpec.getInstreamIds().size() == 1);
}
+ @Test
public void testGetHandler() throws Exception {
String tsSource = "parser/resources/testtool1.xml";
toolSpec = new ToolSpec(getClass().getResourceAsStream(tsSource),
false);
@@ -76,6 +86,7 @@
assertNotNull(toolSpec.getHandler(this.getClass().getClassLoader()));
}
+ @Test
public void testGetOutstreamIds() throws Exception {
String tsSource = "parser/resources/testtool2.xml";
toolSpec = new ToolSpec(getClass().getResourceAsStream(tsSource),
false);
Modified:
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/ToolSupportTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/ToolSupportTest.java?view=diff&rev=544835&r1=544834&r2=544835
==============================================================================
---
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/ToolSupportTest.java
(original)
+++
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/ToolSupportTest.java
Wed Jun 6 06:23:54 2007
@@ -19,11 +19,13 @@
package org.apache.cxf.tools.common.toolspec;
-import junit.framework.TestCase;
import org.apache.cxf.tools.common.ToolException;
-public class ToolSupportTest extends TestCase {
+import org.junit.Assert;
+import org.junit.Test;
-
+public class ToolSupportTest extends Assert {
+
+ @Test
public void testProtect() throws ToolException {
ToolSupport toolSupport = new ToolSupport();
Modified:
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java?view=diff&rev=544835&r1=544834&r2=544835
==============================================================================
---
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java
(original)
+++
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java
Wed Jun 6 06:23:54 2007
@@ -19,28 +19,26 @@
package org.apache.cxf.tools.common.toolspec.parser;
-import junit.framework.TestCase;
+import java.util.StringTokenizer;
+import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.tools.common.toolspec.ToolSpec;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
-public class CommandLineParserTest extends TestCase {
+public class CommandLineParserTest extends Assert {
private CommandLineParser parser;
- public CommandLineParserTest(String name) {
- super(name);
- }
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run(CommandLineParserTest.class);
- }
-
+ @Before
public void setUp() throws Exception {
String tsSource =
"/org/apache/cxf/tools/common/toolspec/parser/resources/testtool.xml";
ToolSpec toolspec = new
ToolSpec(getClass().getResourceAsStream(tsSource), true);
parser = new CommandLineParser(toolspec);
}
-
+
+ @Test
public void testValidArguments() throws Exception {
String[] args = new String[] {"-r", "-n", "test", "arg1"};
CommandDocument result = parser.parseArguments(args);
@@ -48,6 +46,7 @@
assertEquals("testValidArguments Failed", "test",
result.getParameter("namespace"));
}
+ @Test
public void testInvalidArgumentValue() throws Exception {
try {
String[] args = new String[] {"-n", "test@", "arg1"};
@@ -64,12 +63,14 @@
}
}
+ @Test
public void testValidArgumentEnumValue() throws Exception {
String[] args = new String[] {"-r", "-e", "true", "arg1"};
CommandDocument result = parser.parseArguments(args);
assertEquals("testValidArguments Failed", "true",
result.getParameter("enum"));
}
+ @Test
public void testInvalidArgumentEnumValue() throws Exception {
try {
String[] args = new String[] {"-e", "wrongvalue"};
@@ -87,6 +88,7 @@
}
}
+ @Test
public void testValidMixedArguments() throws Exception {
String[] args = new String[] {"-v", "-r", "-n", "test", "arg1"};
CommandDocument result = parser.parseArguments(args);
@@ -94,6 +96,7 @@
assertEquals("testValidMissedArguments Failed", "test",
result.getParameter("namespace"));
}
+ @Test
public void testInvalidOption() {
try {
String[] args = new String[] {"-n", "-r", "arg1"};
@@ -115,6 +118,7 @@
}
}
+ @Test
public void testMissingOption() {
try {
String[] args = new String[] {"-n", "test", "arg1"};
@@ -133,6 +137,7 @@
}
}
+ @Test
public void testMissingArgument() {
try {
String[] args = new String[] {"-n", "test", "-r"};
@@ -151,6 +156,7 @@
}
}
+ @Test
public void testDuplicateArgument() {
try {
String[] args = new String[] {"-n", "test", "-r", "arg1", "arg2"};
@@ -164,6 +170,7 @@
}
}
+ @Test
public void testUnexpectedOption() {
try {
String[] args = new String[] {"-n", "test", "-r", "-unknown"};
@@ -182,7 +189,8 @@
}
}
-
+
+ @Test
public void testInvalidPackageName() {
try {
@@ -203,6 +211,7 @@
}
+ @Test
public void testvalidPackageName() throws Exception {
String[] args = new String[]{
@@ -215,41 +224,72 @@
}
-
+
+ @Test
public void testUsage() throws Exception {
String usage =
"[ -n <C++ Namespace> ] [ -impl ] [ -e <Enum Value> ] -r "
+ "[ -p <[wsdl namespace =]Package Name> ]* [ -? ] [ -v ]
<wsdlurl> ";
String pUsage = parser.getUsage();
- assertEquals("testUsage failed", usage, pUsage);
+
+ if (isQuolifiedVersion()) {
+ assertEquals("This test failed in the xerces version above 2.7.1
or the version with JDK ",
+ usage, pUsage);
+ } else {
+ usage = "[ -n <C++ Namespace> ] [ -impl ] [ -e <Enum Value> ] -r "
+ + "-p <[wsdl namespace =]Package Name>* [ -? ] [ -v ]
<wsdlurl>";
+ assertEquals("This test failed in the xerces version below 2.7.1",
usage.trim(), pUsage.trim());
+ }
}
+ private boolean isQuolifiedVersion() {
+ try {
+ Class c = Class.forName("org.apache.xerces.impl.Version");
+ Object o = c.newInstance();
+ String v = (String) c.getMethod("getVersion").invoke(o);
+ float vn = Float.parseFloat(StringUtils.getFirstFound(v,
"(\\d+.\\d+)"));
+ return vn >= 2.7;
+ } catch (Exception e) {
+ // ignore
+ }
+ return true;
+ }
+
+ @Test
public void testDetailedUsage() throws Exception {
+ String specialItem = "[ -p <[wsdl namespace =]Package Name> ]*";
+ if (!isQuolifiedVersion()) {
+ specialItem = "-p <[wsdl namespace =]Package Name>*";
+ }
+
+ String[] expected = new String[]{"[ -n <C++ Namespace> ]",
+ "Namespace",
+ "[ -impl ]",
+ "impl",
+ "[ -e <Enum Value> ]",
+ "enum",
+ "-r",
+ "required",
+ specialItem,
+ "The java package name to use for the
generated code."
+ + "Also, optionally specify the wsdl
namespace mapping to "
+ + "a particular java packagename.",
+ "[ -? ]",
+ "help",
+ "[ -v ]",
+ "version",
+ "<wsdlurl>",
+ "WSDL/SCHEMA URL"};
+
+ int index = 0;
String lineSeparator = System.getProperty("line.separator");
- String usage = "[ -n <C++ Namespace> ]" + lineSeparator;
- usage += "Namespace" + lineSeparator + lineSeparator;
- usage += "[ -impl ]" + lineSeparator;
- usage += "impl" + lineSeparator + lineSeparator;
- usage += "[ -e <Enum Value> ]" + lineSeparator;
- usage += "enum" + lineSeparator + lineSeparator;
- usage += "-r" + lineSeparator;
- usage += "required" + lineSeparator + lineSeparator;
- usage += "[ -p <[wsdl namespace =]Package Name> ]*" + lineSeparator;
- usage += "The java package name to use for the generated code."
- + "Also, optionally specify the wsdl namespace mapping to a
particular java packagename."
- + lineSeparator + lineSeparator;
- usage += "[ -? ]" + lineSeparator;
- usage += "help" + lineSeparator + lineSeparator;
- usage += "[ -v ]" + lineSeparator;
- usage += "version" + lineSeparator + lineSeparator;
- usage += "<wsdlurl>" + lineSeparator;
- usage += "WSDL/SCHEMA URL" + lineSeparator + lineSeparator;
- assertEquals("testUsage failed",
- usage.replaceAll(lineSeparator, "").replace(" ", ""),
- parser.getDetailedUsage().replaceAll(lineSeparator, "")
- .replaceAll(" ", "").replaceAll("\\\t", ""));
+ StringTokenizer st1 = new StringTokenizer(parser.getDetailedUsage(),
lineSeparator);
+ while (st1.hasMoreTokens()) {
+ assertEquals("Failed at line " + index, expected[index++],
st1.nextToken().toString().trim());
+ }
}
+ @Test
public void testOtherMethods() throws Exception {
String tsSource =
"/org/apache/cxf/tools/common/toolspec/parser/resources/testtool.xml";
ToolSpec toolspec = new
ToolSpec(getClass().getResourceAsStream(tsSource), false);
@@ -259,6 +299,7 @@
assertTrue(commandDocument != null);
}
+ @Test
public void testGetDetailedUsage() {
assertTrue("Namespace".equals(parser.getDetailedUsage("namespace")));
}