*/
public class CamelRoutingEngineTest {
@Test
public void testCreateRemoveConnection() throws Exception {
CamelRoutingEngine routingEngine = new CamelRoutingEngine();
try {
routingEngine.start();
Connector connector = mock(Connector.class);
// create a connector service
ConnectorService cs1 = routingEngine.addConnection("test1", connector).withPriority(2000);
cs1.start();
// check that the connector service was created successfully
Assert.assertNotNull(cs1);
Assert.assertEquals(Service.State.STARTED, cs1.getState());
// check that there is only one connector
List<ConnectorService> connectorServices = routingEngine.getConnections();
Assert.assertEquals(1, connectorServices.size());
// create a second and third connector
ConnectorService cs2 = routingEngine.addConnection("test2", connector).withPriority(0);
cs2.start();
ConnectorService cs3 = routingEngine.addConnection("test3", connector).withPriority(1000);
cs3.start();
connectorServices = routingEngine.getConnections();
Assert.assertEquals(3, connectorServices.size());
// check that the connector are in order
ConnectorService psTest = connectorServices.get(0);
Assert.assertEquals(cs2, psTest); // the one with 0 priority
psTest = connectorServices.get(1);
Assert.assertEquals(cs3, psTest); // the one with 1000 priority
psTest = connectorServices.get(2);
Assert.assertEquals(cs1, psTest); // the one with 2000 priority
// remove the connector test3
routingEngine.removeConnection("test3");
// check that there are only 2 connector services
connectorServices = routingEngine.getConnections();
Assert.assertEquals(2, connectorServices.size());
psTest = connectorServices.get(0);
Assert.assertEquals(cs2, psTest); // the one with 0 priority
psTest = connectorServices.get(1);
Assert.assertEquals(cs1, psTest); // the one with 2000 priority
} finally {
routingEngine.shutdown();
}
}