Author: alessio.soldano(a)jboss.com
Date: 2009-01-15 05:11:14 -0500 (Thu, 15 Jan 2009)
New Revision: 9042
Modified:
framework/branches/jaxws21/testsuite/test/java/org/jboss/test/ws/jaxws/samples/xop/doclit/MTOMFeatureTestCase.java
Log:
[JBWS-2448] Improving test
Modified:
framework/branches/jaxws21/testsuite/test/java/org/jboss/test/ws/jaxws/samples/xop/doclit/MTOMFeatureTestCase.java
===================================================================
---
framework/branches/jaxws21/testsuite/test/java/org/jboss/test/ws/jaxws/samples/xop/doclit/MTOMFeatureTestCase.java 2009-01-15
09:59:07 UTC (rev 9041)
+++
framework/branches/jaxws21/testsuite/test/java/org/jboss/test/ws/jaxws/samples/xop/doclit/MTOMFeatureTestCase.java 2009-01-15
10:11:14 UTC (rev 9042)
@@ -44,85 +44,91 @@
/**
* [JBWS-2448] This test verify the MTOMFeature correctly enable MTOM on client side.
- *
+ *
* @author alessio.soldano(a)jboss.com
* @since 14-Jan-2009
*/
-public class MTOMFeatureTestCase extends JBossWSTest
-{
+public class MTOMFeatureTestCase extends JBossWSTest {
- public final String TARGET_ENDPOINT_ADDRESS = "http://" + getServerHost() +
":8080/jaxws-samples-xop-doclit/bare";
+ public final String TARGET_ENDPOINT_ADDRESS = "http://" + getServerHost() +
":8080/jaxws-samples-xop-doclit/bare";
- protected MTOMEndpoint port;
+ protected MTOMEndpoint port;
- public static Test suite()
- {
- return new JBossWSTestSetup(MTOMFeatureTestCase.class,
"jaxws-samples-xop-doclit.war");
- }
+ public static Test suite() {
+ return new JBossWSTestSetup(MTOMFeatureTestCase.class,
"jaxws-samples-xop-doclit.war");
+ }
- @SuppressWarnings("unchecked")
- private MTOMEndpoint getPort(boolean mtomEnabled) throws Exception
- {
- QName serviceName = new
QName("http://doclit.xop.samples.jaxws.ws.test.jboss.org/",
"MTOMService");
- URL wsdlURL = new URL(TARGET_ENDPOINT_ADDRESS + "?wsdl");
+ private MTOMEndpoint getPort(boolean mtomEnabled) throws Exception {
+ QName serviceName = new
QName("http://doclit.xop.samples.jaxws.ws.test.jboss.org/",
"MTOMService");
+ URL wsdlURL = new URL(TARGET_ENDPOINT_ADDRESS + "?wsdl");
- Service service = Service.create(wsdlURL, serviceName);
- MTOMEndpoint port = service.getPort(MTOMEndpoint.class, new
MTOMFeature(mtomEnabled));
- SOAPBinding binding = (SOAPBinding)((BindingProvider)port).getBinding();
+ Service service = Service.create(wsdlURL, serviceName);
+ return service.getPort(MTOMEndpoint.class, new MTOMFeature(mtomEnabled));
+ }
- if (mtomEnabled)
- {
- List<Handler> handlerChain = new ArrayList<Handler>();
- handlerChain.addAll(binding.getHandlerChain());
- handlerChain.add(new MTOMCheckClientHandler());
- binding.setHandlerChain(handlerChain);
- }
- return port;
- }
+ @SuppressWarnings("unchecked")
+ private static void addMTOMCheckHandler(MTOMEndpoint port) {
+ SOAPBinding binding = (SOAPBinding) ((BindingProvider) port).getBinding();
+ List<Handler> handlerChain = new ArrayList<Handler>();
+ handlerChain.addAll(binding.getHandlerChain());
+ handlerChain.add(new MTOMCheckClientHandler());
+ binding.setHandlerChain(handlerChain);
+ }
- public void testWithMTOMRequest() throws Exception
- {
- DataHandler dh = new DataHandler("DataHandlerRoundtrip",
"text/plain");
- DHResponse response = getPort(true).echoDataHandler(new DHRequest(dh));
- assertNotNull(response);
+ public void testWithMTOMRequest() throws Exception {
+ DataHandler dh = new DataHandler("DataHandlerRoundtrip",
"text/plain");
+ MTOMEndpoint port = getPort(true);
+ addMTOMCheckHandler(port);
+ DHResponse response = port.echoDataHandler(new DHRequest(dh));
+ assertNotNull(response);
- Object content = getContent(response.getDataHandler());
- String contentType = response.getDataHandler().getContentType();
+ Object content = getContent(response.getDataHandler());
+ String contentType = response.getDataHandler().getContentType();
- assertEquals("Server data", content);
- assertEquals("text/plain", contentType);
- }
+ assertEquals("Server data", content);
+ assertEquals("text/plain", contentType);
+ }
- public void testWithoutMTOMRequest() throws Exception
- {
- DataHandler dh = new DataHandler("DataHandlerResponseOptimzed",
"text/plain");
- DHResponse response = getPort(false).echoDataHandler(new DHRequest(dh));
- assertNotNull(response);
+ public void testWithoutMTOMRequest() throws Exception {
+ DataHandler dh = new DataHandler("DataHandlerResponseOptimzed",
"text/plain");
+ DHResponse response = getPort(false).echoDataHandler(new DHRequest(dh));
+ assertNotNull(response);
- Object content = getContent(response.getDataHandler());
- String contentType = response.getDataHandler().getContentType();
+ Object content = getContent(response.getDataHandler());
+ String contentType = response.getDataHandler().getContentType();
- assertEquals("Server data", content);
- assertEquals("text/plain", contentType);
- }
+ assertEquals("Server data", content);
+ assertEquals("text/plain", contentType);
+ }
+
+ public void testErrorWithoutMTOMRequest() throws Exception {
+ DataHandler dh = new DataHandler("DataHandlerResponseOptimzed",
"text/plain");
+ MTOMEndpoint port = getPort(false);
+ addMTOMCheckHandler(port);
+ try
+ {
+ port.echoDataHandler(new DHRequest(dh));
+ fail("Exception expected");
+ }
+ catch (Exception e)
+ {
+ //OK
+ }
+ }
- protected Object getContent(DataHandler dh) throws IOException
- {
- Object content = dh.getContent();
+ protected Object getContent(DataHandler dh) throws IOException {
+ Object content = dh.getContent();
- // Metro returns an ByteArrayInputStream
- if (content instanceof InputStream)
- {
- try
- {
- BufferedReader br = new BufferedReader(new
InputStreamReader((InputStream)content));
- return br.readLine();
- }
- finally
- {
- ((InputStream)content).close();
- }
- }
- return content;
- }
+ // Metro returns an ByteArrayInputStream
+ if (content instanceof InputStream) {
+ try {
+ BufferedReader br = new BufferedReader(new InputStreamReader(
+ (InputStream) content));
+ return br.readLine();
+ } finally {
+ ((InputStream) content).close();
+ }
+ }
+ return content;
+ }
}