package de.timeroes.axmlrpc;

import java.net.URL;

import org.junit.Test;

import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static org.junit.Assert.*;

import org.junit.Rule;

import com.github.tomakehurst.wiremock.junit.WireMockRule;

import de.timroes.axmlrpc.XMLRPCClient;

public class TestResponseParser {
	private final int port = 8080;
	private final String endPoint = "/dummyEndPoint";

	@Rule
	public WireMockRule wireMockRule = new WireMockRule(port);

	@Test
	public void canParseString() throws Exception {
		setMockWithXmlRpcContent("<value><string>toto</string></value>");
		assertEquals("toto", makeDummyCall());
	}

	@Test
	public void canParseInt() throws Exception {
		setMockWithXmlRpcContent("<value><i4>32</i4></value>");
		assertEquals(32, makeDummyCall());

		setMockWithXmlRpcContent("<value><int>33</int></value>");
		assertEquals(33, makeDummyCall());
	}

	@Test
	public void canParseBoolean() throws Exception {
		setMockWithXmlRpcContent("<value><boolean>1</boolean></value>");
		assertEquals(true, makeDummyCall());

		setMockWithXmlRpcContent("<value><boolean>0</boolean></value>");
		assertEquals(false, makeDummyCall());
	}

	private void setMockWithXmlRpcContent(String content){
		stubFor(post(urlEqualTo(endPoint))
				.willReturn(aResponse()
						.withStatus(200)
						.withBody("<methodResponse><params><param>" + content + "</param></params></methodResponse>")
						));
	}

	private Object makeDummyCall() throws Exception {
		return new XMLRPCClient(new URL("http://localhost:" + port + endPoint)).call("dummy_method");
	}
}

@@ -641,32 +641,255 @@
 mmyCall());%0A%09%7D%0A%0A
+%09@Test%0A%09public void canParseAsStringWhenTypeIsntExplicitelyProvided() throws Exception %7B%0A%09%09setMockWithXmlRpcContent(%22%3Cvalue%3Etoto%3C/value%3E%22);%0A%09%09assertEquals(%22toto%22, makeDummyCall(XMLRPCClient.FLAGS_DEFAULT_TYPE_STRING));%0A%09%7D%0A%0A
 %09@Test%0A%09public v
@@ -1706,16 +1706,129 @@
 ption %7B%0A
+%09%09return makeDummyCall(XMLRPCClient.FLAGS_NONE);%0A%09%7D%0A%0A%09private Object makeDummyCall(int flags) throws Exception %7B%0A
 %09%09return
@@ -1891,16 +1891,23 @@
 ndPoint)
+, flags
 ).call(%22

Add test for case where type String is implicit