public void testConsumerSingletonism() throws Exception { // given Endpoint endpoint = context.getEndpoint("smslib://asdf"); Processor mockProcessor = mock(Processor.class); endpoint.createConsumer(mockProcessor); Processor anotherMockProcessor = mock(Processor.class); // when then try { endpoint.createConsumer(anotherMockProcessor); fail("Should only be able to create a single consumer."); } catch (Exception e) { // expected } }
private Consumer createConsumerFor(String path) throws Exception { Endpoint endpoint = context.getEndpoint("cmis://" + path); return endpoint.createConsumer( new Processor() { public void process(Exchange exchange) throws Exception { template.send("mock:result", exchange); } }); }
/** * Factory method to lazily create the complete list of services required for this route such as * adding the processor or consumer */ @Override protected void addServices(List<Service> services) throws Exception { Endpoint endpoint = getEndpoint(); consumer = endpoint.createConsumer(processor); if (consumer != null) { services.add(consumer); if (consumer instanceof RouteAware) { ((RouteAware) consumer).setRoute(this); } } Processor processor = getProcessor(); if (processor instanceof Service) { services.add((Service) processor); } }