package com.github.jaceko.circuitbreaker.it.util.mock;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import java.io.IOException;

import javax.ws.rs.core.Response;

import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

import com.github.jaceko.circuitbreaker.it.util.xml.XmlParser;

public class WebserviceMockControler {

	private MockService mockServiceProxy;

	public WebserviceMockControler(String mockServiceRootAddress) {
		JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
		bean.setAddress(mockServiceRootAddress);
		bean.setResourceClass(MockService.class);
		mockServiceProxy = bean.create(MockService.class);

	}

	public MockServiceOperation soapOperation(WebserviceOperation mockedOperation) {
		return new MockServiceOperation("SOAP", mockServiceProxy, mockedOperation);
	}

	public static class MockServiceOperation {
		MockService mockServiceProxy;
		String serviceType;
		WebserviceOperation mockedOperation;

		public MockServiceOperation(String serviceType, MockService mockServiceProxy, WebserviceOperation mockedOperation) {
			super();
			this.serviceType = serviceType;
			this.mockServiceProxy = mockServiceProxy;
			this.mockedOperation = mockedOperation;
		}

		public void setUp(MockResponseBuilder mockResponse) {
			mockServiceProxy.setupResponse(serviceType, mockedOperation.getServiceName(), mockedOperation.getOperationId(),
					mockResponse.responseDelay(), mockResponse.build());
		}

		public void init() {
			mockServiceProxy.init(serviceType, mockedOperation.getServiceName(), mockedOperation.getOperationId());
		}

		public Document recordedRequests() throws SAXException, IOException {
			String recordedRequests = mockServiceProxy.getRecordedRequests(serviceType, mockedOperation.getServiceName(),
					mockedOperation.getOperationId());
			return XmlParser.parse(recordedRequests);
		}
	}

}

@@ -60,150 +60,27 @@
 ort 
-static org.hamcrest.CoreMatchers.is;%0Aimport static org.junit.Assert.assertThat;%0A%0Aimport java.io.IOException;%0A%0Aimport javax.ws.rs.core.Response
+java.io.IOException
 ;%0A%0Ai

remove unused imports