/**
 * Copyright 2009-2010 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.javacrumbs.calc;

import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.rmi.RemoteException;

import net.javacrumbs.smock.axis2.client.AbstractSmockClientTest;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class CalcSimpleTest extends AbstractSmockClientTest {

    private CalcClient calc = new CalcClient("https://localhost:8443/axis2-server-test/services/CalculatorService.CalculatorServiceHttpSoap12Endpoint/");
    
    @Before
    public void setUp()
    {
    	createServer();
    }
   
    @After
    public void verify()
    {
    	super.verify();
    }

	@Test
	public void testSimple() throws RemoteException
	{
		expect(anything()).andRespond(withMessage("response1.xml"));

		long result = calc.plus(1, 2);
		assertEquals(3, result);
	}
	
	@Test
	public void testVerifyRequest() throws RemoteException
	{
		expect(message("request1.xml")).andRespond(withMessage("response1.xml"));
		
		long result = calc.plus(1, 2);
		assertEquals(3, result);
	}
	@Test
	public void testSchema() throws IOException
	{
		expect(validPayload(resource("xsd/calc.xsd"))).andExpect(message("request1.xml")).andRespond(withMessage("response1.xml"));
		
		long result = calc.plus(1, 2);
		assertEquals(3, result);
	}
	@Test
	public void testIgnore() throws IOException
	{
		expect(validPayload(resource("xsd/calc.xsd"))).andExpect(message("request-ignore.xml")).andRespond(withMessage("response2.xml"));
		
		long result = calc.plus(2, 3);
		assertEquals(5, result);
	}
	@Test
	public void testMultiple() throws IOException
	{
		expect(validPayload(resource("xsd/calc.xsd"))).andExpect(message("request-ignore.xml")).andRespond(withMessage("response2.xml"));
		expect(validPayload(resource("xsd/calc.xsd"))).andExpect(message("request-ignore.xml")).andRespond(withMessage("response3.xml"));
		
		
		assertEquals(5, calc.plus(2, 3));
		assertEquals(8, calc.plus(3, 5));
	}
	@Test
	public void testStrange() throws RemoteException
	{
		expect(message("request-ignore.xml")).andRespond(withMessage("response1.xml"));
		expect(message("request-ignore.xml")).andRespond(withMessage("response2.xml"));
		expect(message("request-ignore.xml")).andRespond(withMessage("response1.xml"));
				
		assertEquals(3, calc.plus(1, 2));
		assertEquals(5, calc.plus(2, 3));
		assertEquals(3, calc.plus(1, 2));
	}
	@Test
	public void testTemplate() throws IOException
	{
		expect(validPayload(resource("xsd/calc.xsd"))).andExpect(message("request-ignore.xml")).andRespond(withMessage("response-template.xml"));
		
		long result = calc.plus(2, 3);
		assertEquals(5, result);
	}
	
	@Test
	public void testMultipleTemplate() throws IOException
	{
		expect(validPayload(resource("xsd/calc.xsd"))).andExpect(message("request-ignore.xml")).andRespond(withMessage("response-template.xml"));
		expect(validPayload(resource("xsd/calc.xsd"))).andExpect(message("request-ignore.xml")).andRespond(withMessage("response-template.xml"));
		
		assertEquals(5, calc.plus(2, 3));
		assertEquals(8, calc.plus(3, 5));
	}

	@Test
	public void testContext() throws IOException
	{
		expect(validPayload(resource("xsd/calc.xsd")))
			.andExpect(message("request-context-xslt.xml").withParameter("a",1).withParameter("b", 4))
			.andRespond(withMessage("response-template.xml"));
		
		long result = calc.plus(1, 4);
		assertEquals(5, result);
	}
	
	@Test(expected=RemoteException.class)
	public void testException() throws IOException
	{
		expect(validPayload(resource("xsd/calc.xsd"))).andExpect(message("request-ignore.xml")).andRespond(withMessage("fault.xml"));
		calc.plus(2, 3);
	}
}

@@ -848,33 +848,8 @@
 er;%0A
-import org.junit.Before;%0A
 impo
@@ -1094,77 +1094,8 @@
    %0A
-    @Before%0A    public void setUp()%0A    %7B%0A    %09createServer();%0A    %7D%0A
    %0A

Test simplified