package org.codehaus.xfire.client;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import org.codehaus.xfire.aegis.AbstractXFireAegisTest;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.invoker.BeanInvoker;
import org.codehaus.xfire.transport.local.LocalTransport;

public class ConcatClientTest
    extends AbstractXFireAegisTest
{
    public void testDynamicClient() throws Exception
    {
        Service s = getServiceFactory().create(ConcatService.class);
        s.setInvoker(new BeanInvoker(new ConcatService()
        {
            public String concat(String s1, String s2)
            {
                return s1 + s2;
            }

            public String concat(String s1, String s2, String s3)
            {
                return s1 + s2 + s3;
            }
            
        }));

        getServiceRegistry().register(s);

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        s.getWSDLWriter().write(bos);
        Client client = new Client(new ByteArrayInputStream(bos.toByteArray()), null);
        client.setXFire(getXFire());
        client.setUrl("xfire.local://ConcatService");
        client.setTransport(getTransportManager().getTransport(LocalTransport.BINDING_ID));

        Object[] res = client.invoke("concat", new Object[]{"1", "2"});
        
        assertEquals("12", res[0]);
        
        res = client.invoke("concat1", new Object[]{"1", "2", "3"});
        
        assertEquals("123", res[0]);
    }

    public static interface ConcatService
    {
        String concat(String s1, String s2);
        
        String concat(String s1, String s2, String s3);
    }
}

@@ -854,16 +854,18 @@
      %7D%0D%0A
+%0D%0A
         
@@ -860,32 +860,118 @@
 %0D%0A%0D%0A            
+public void noconcat(String s1, String s2)%0D%0A            %7B%0D%0A            %0D%0A            %7D
 %0D%0A        %7D));%0D%0A
@@ -1642,24 +1642,139 @@
 , res%5B0%5D);%0D%0A
+        %0D%0A        res = client.invoke(%22noconcat%22, new Object%5B%5D %7B%22a%22, %22b%22%7D);%0D%0A        assertEquals(0, res.length);%0D%0A
     %7D%0D%0A%0D%0A   
@@ -1929,22 +1929,78 @@
 tring s3);%0D%0A
+        %0D%0A        void noconcat(String s1, String s2);%0D%0A
     %7D%0D%0A%7D%0D%0A

add test for returning void