package org.codehaus.xfire.transport.http;

import org.codehaus.xfire.service.OperationInfo;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
import org.codehaus.xfire.soap.SoapConstants;
import org.codehaus.xfire.test.AbstractServletTest;

import com.meterware.httpunit.HttpUnitOptions;
import com.meterware.httpunit.PostMethodWebRequest;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;

/**
 * XFireServletTest
 *
 * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
 */
public class SoapActionTest
        extends AbstractServletTest
{
    public void setUp()
            throws Exception
    {
        super.setUp();

        ObjectServiceFactory osf = new ObjectServiceFactory(getTransportManager()) {
            protected String getAction(OperationInfo op)
            {
                return op.getName();
            }
        };
        osf.setStyle(SoapConstants.STYLE_DOCUMENT);
        
        Service service = osf.create(SoapActionService.class);
        getServiceRegistry().register(service);
    }

    public void testSoapAction()
            throws Exception
    {
        HttpUnitOptions.setLoggingHttpHeaders(true);

        WebRequest req = new PostMethodWebRequest("http://localhost/services/SoapActionService",
                                                  getResourceAsStream("empty.xml"),
                                                  "text/xml");
        req.setHeaderField("SOAPAction", "one");

        WebResponse response = newClient().getResponse(req);
        assertTrue(response.getText().indexOf("oneout") != -1);
       
        req = new PostMethodWebRequest("http://localhost/services/SoapActionService",
                                       getResourceAsStream("empty.xml"),
                                       "text/xml");
        req.setHeaderField("SOAPAction", "two");
        
        response = newClient().getResponse(req);
        assertTrue(response.getText().indexOf("twoout") != -1);

    }
}

@@ -2051,20 +2051,978 @@
 %22) != -1);%0A%0A
+    %7D%0A    %0A%0A    public void testQuotedSoapAction()%0A            throws Exception%0A    %7B%0A        HttpUnitOptions.setLoggingHttpHeaders(true);%0A%0A        WebRequest req = new PostMethodWebRequest(%22http://localhost/services/SoapActionService%22,%0A                                                  getResourceAsStream(%22empty.xml%22),%0A                                                  %22text/xml%22);%0A        req.setHeaderField(%22SOAPAction%22, %22%5C%22one%5C%22%22);%0A%0A        WebResponse response = newClient().getResponse(req);%0A        assertTrue(response.getText().indexOf(%22oneout%22) != -1);%0A       %0A        req = new PostMethodWebRequest(%22http://localhost/services/SoapActionService%22,%0A                                       getResourceAsStream(%22empty.xml%22),%0A                                       %22text/xml%22);%0A        req.setHeaderField(%22SOAPAction%22, %22%5C%22two%5C%22%22);%0A        %0A        response = newClient().getResponse(req);%0A        assertTrue(response.getText().indexOf(%22twoout%22) != -1);%0A%0A
     %7D%0A%7D%0A

Add better quoted soap action test