/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.reflection.inspect;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import net.ranides.assira.collection.SetUtils;
import net.ranides.assira.generic.Serializer;
import net.ranides.assira.reflection.inspect.WebServiceInspector.WSMethod;
import net.ranides.assira.reflection.mock.ForWSInspector.Service1;
import net.ranides.assira.text.StrBuilder;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class WebServiceInspectorTest {
    
    public WebServiceInspectorTest() {
    }

    @Test
    public void testWSInspector() {
        WebServiceInspector wsi = new WebServiceInspector(Service1.class);
        
        assertEquals("name1", wsi.name());
        assertEquals("service1", wsi.service());
        assertEquals("ns1", wsi.namespace());
        assertEquals("999", wsi.port());
        assertEquals("/info.wsdl", wsi.location());
        
        assertEquals(2, wsi.methods().size());
        
        Set<String> expected = SetUtils.asHashSet(
            "opTime time [String iuser, List<Number> inumbers] {user=String, numbers=List<Number>} ret",
            "opHello hello [String iuser, List<Number> inumbers] {iuser=String, inumbers=List<Number>} int"
        );
        Set<String> found = new HashSet<>();
        for(WSMethod method : wsi.methods()) {
            String line = new StrBuilder()
                .append(method.name())
                .append(" ")
                .append(method.action())
                .append(" ")
                .append(method.params())
                .append(" ")    
                .append(method.webparams())
                .append(" ")    
                .append(method.resultname())
                .toString();
            found.add(line);
        }
        assertEquals(expected, found);
    }
	
	@Test
	public void testSerialization() throws IOException {
		WebServiceInspector wsi = new WebServiceInspector(Service1.class);
		WSMethod<?> m = Serializer.copy( wsi.methods().get(0) );
		assertNotNull(m);
	}
    
}
