// Path: src/test/java/com/tzavellas/circuitbreaker/AbstractJmxTest.java
// public abstract class AbstractJmxTest {
// 	
// 	protected ITimeService time;
// 	
// 	protected abstract void disableJmx();
// 	
// 	protected CircuitBreakerMBean mbean() throws JMException {
// 		return JmxUtils.getCircuitBreaker(time);
// 	}
// 	
// 	protected void readStatsAndOpenCircuitViaJmx() throws Exception {
// 		time.networkTime();
// 		
// 		CircuitBreakerMBean mbean = mbean();
// 		assertTrue(mbean.getCalls() >= 1);
// 		assertEquals(0, mbean.getCurrentFailures());
// 		assertEquals(0, mbean.getFailures());
// 		assertEquals(0, mbean.getTimesOpened());
// 		assertTrue(mbean.isClosed());
// 		assertFalse(mbean.isHalfOpen());
// 		assertFalse(mbean.isOpen());
// 		
// 		mbean.open();
// 		assertTrue(mbean.isOpen());
// 		time.networkTime();
// 	}
// }
// 
// Path: src/main/java/com/tzavellas/circuitbreaker/OpenCircuitException.java
// public class OpenCircuitException extends RuntimeException {
// 	
// 	private static final long serialVersionUID = 1L;
// 	private final transient CircuitInfo circuit;
// 	
// 	/**
// 	 * Create an OpenCircuitException.
// 	 * 
// 	 * @param c the {@code CircuitInfo} that caused this exception.
// 	 */
// 	public OpenCircuitException(CircuitInfo c) {
// 		circuit = c;
// 	}
// 	
// 	/**
// 	 * Get the {@code CircuitInfo} that is open and caused this
// 	 * exception to be thrown.
// 	 * 
// 	 * @return the {@code CircuitInfo} that caused this exception.
// 	 */
// 	public CircuitInfo getCircuit() {
// 		return circuit;
// 	}
// 
// 	/**
// 	 * Overridden to return null to avoid the cost of creating the stack
// 	 * trace.
// 	 * 
// 	 * <p>This can be done because this exception is used as a control
// 	 * structure and not to report any error.</p>
// 	 */
// 	@Override
// 	public synchronized Throwable fillInStackTrace() {
// 		return null;
// 	}
// }
// 
// Path: src/test/java/com/tzavellas/test/aj/TimeService.java
// @IntegrationPoint
// public class TimeService implements ITimeService {
// 
// 	public Date networkTime() {
// 		return EXPECTED;
// 	}
// 	
// 	public Date faultyNetworkTime() {
// 		throw new IllegalStateException();
// 	}
// }


import org.junit.After;
import org.junit.Test;
import com.tzavellas.circuitbreaker.AbstractJmxTest;
import com.tzavellas.circuitbreaker.OpenCircuitException;
import com.tzavellas.test.aj.TimeService;
	@Test(expected=OpenCircuitException.class)
	public void enable_jmx_via_configurator_bean() throws Exception {
		time = new TimeService();
		CircuitConfiguratorBean conf = new CircuitConfiguratorBean();
		conf.setAspectClass(IntegrationPointBreaker.class);
		conf.setTarget(time);
		conf.setEnableJmx(true);
		conf.configure();
		readStatsAndOpenCircuitViaJmx();
	}
	
	@Test(expected=OpenCircuitException.class)
	public void setEnableJmx_registers_once() throws Exception {
		time = new TimeService();
		IntegrationPointBreaker.aspectOf(time).setEnableJmx(true);
		IntegrationPointBreaker.aspectOf(time).setEnableJmx(true);
		readStatsAndOpenCircuitViaJmx();
	}
	
	@Test
	public void setEnableJmx_unregisters_once() throws Exception {
		time = new TimeService();
		IntegrationPointBreaker.aspectOf(time).setEnableJmx(true);
		IntegrationPointBreaker.aspectOf(time).setEnableJmx(false);
		IntegrationPointBreaker.aspectOf(time).setEnableJmx(false);
	}
	
	@Test
	public void prevent_jmx_name_collision_for_two_objects_of_the_same_type() throws Exception {
		CircuitBreakerConfigurator.aspectOf().setEnableJmx(true);
// Path: src/test/java/com/tzavellas/circuitbreaker/AbstractJmxTest.java
// public abstract class AbstractJmxTest {
// 	
// 	protected ITimeService time;
// 	
// 	protected abstract void disableJmx();
// 	
// 	protected CircuitBreakerMBean mbean() throws JMException {
// 		return JmxUtils.getCircuitBreaker(time);
// 	}
// 	
// 	protected void readStatsAndOpenCircuitViaJmx() throws Exception {
// 		time.networkTime();
// 		
// 		CircuitBreakerMBean mbean = mbean();
// 		assertTrue(mbean.getCalls() >= 1);
// 		assertEquals(0, mbean.getCurrentFailures());
// 		assertEquals(0, mbean.getFailures());
// 		assertEquals(0, mbean.getTimesOpened());
// 		assertTrue(mbean.isClosed());
// 		assertFalse(mbean.isHalfOpen());
// 		assertFalse(mbean.isOpen());
// 		
// 		mbean.open();
// 		assertTrue(mbean.isOpen());
// 		time.networkTime();
// 	}
// }
// 
// Path: src/main/java/com/tzavellas/circuitbreaker/OpenCircuitException.java
// public class OpenCircuitException extends RuntimeException {
// 	
// 	private static final long serialVersionUID = 1L;
// 	private final transient CircuitInfo circuit;
// 	
// 	/**
// 	 * Create an OpenCircuitException.
// 	 * 
// 	 * @param c the {@code CircuitInfo} that caused this exception.
// 	 */
// 	public OpenCircuitException(CircuitInfo c) {
// 		circuit = c;
// 	}
// 	
// 	/**
// 	 * Get the {@code CircuitInfo} that is open and caused this
// 	 * exception to be thrown.
// 	 * 
// 	 * @return the {@code CircuitInfo} that caused this exception.
// 	 */
// 	public CircuitInfo getCircuit() {
// 		return circuit;
// 	}
// 
// 	/**
// 	 * Overridden to return null to avoid the cost of creating the stack
// 	 * trace.
// 	 * 
// 	 * <p>This can be done because this exception is used as a control
// 	 * structure and not to report any error.</p>
// 	 */
// 	@Override
// 	public synchronized Throwable fillInStackTrace() {
// 		return null;
// 	}
// }
// 
// Path: src/test/java/com/tzavellas/test/aj/TimeService.java
// @IntegrationPoint
// public class TimeService implements ITimeService {
// 
// 	public Date networkTime() {
// 		return EXPECTED;
// 	}
// 	
// 	public Date faultyNetworkTime() {
// 		throw new IllegalStateException();
// 	}
// }


// Path: src/test/java/com/tzavellas/circuitbreaker/aspectj/JmxTest.java
import org.junit.After;
import org.junit.Test;
import com.tzavellas.circuitbreaker.AbstractJmxTest;
import com.tzavellas.circuitbreaker.OpenCircuitException;
import com.tzavellas.test.aj.TimeService;

	@Test(expected=OpenCircuitException.class)
	public void enable_jmx_via_configurator_bean() throws Exception {
		time = new TimeService();
		CircuitConfiguratorBean conf = new CircuitConfiguratorBean();
		conf.setAspectClass(IntegrationPointBreaker.class);
		conf.setTarget(time);
		conf.setEnableJmx(true);
		conf.configure();
		readStatsAndOpenCircuitViaJmx();
	}
	
	@Test(expected=OpenCircuitException.class)
	public void setEnableJmx_registers_once() throws Exception {
		time = new TimeService();
		IntegrationPointBreaker.aspectOf(time).setEnableJmx(true);
		IntegrationPointBreaker.aspectOf(time).setEnableJmx(true);
		readStatsAndOpenCircuitViaJmx();
	}
	
	@Test
	public void setEnableJmx_unregisters_once() throws Exception {
		time = new TimeService();
		IntegrationPointBreaker.aspectOf(time).setEnableJmx(true);
		IntegrationPointBreaker.aspectOf(time).setEnableJmx(false);
		IntegrationPointBreaker.aspectOf(time).setEnableJmx(false);
	}
	
	@Test
	public void prevent_jmx_name_collision_for_two_objects_of_the_same_type() throws Exception {
		CircuitBreakerConfigurator.aspectOf().setEnableJmx(true);
		time = new TimeService();