Hi, i'm having problems with testing a Jpaconsumer route, i'm trying to
replace the jpa endpoint with direct: using replacefromwith but i'm getting:
No consumers available on endpoint.What am i doing wrong?Thank you.*Test
def*public class RutaArchivarItemsTest extends CamelTestSupport {
@Produce(uri = "direct:producer") protected ProducerTemplate template;
@EndpointInject(uri = "direct:lala") protected DirectEndpoint
directEndpoint; @EndpointInject(uri = "mock:borrarEventoPieza")
protected MockEndpoint borrarEventoPieza; @EndpointInject(uri =
"mock:archivoArchivoPieza") protected MockEndpoint archivoArchivoPieza;
private String id_prefix = RutaArchivarItems.class.getSimpleName();
@Override protected RouteBuilder createRouteBuilder() throws Exception {
return new RutaArchivarItems(); } @Override public boolean
isUseAdviceWith() { return true; } public void adviceRoutes()
throws Exception {
context.getRouteDefinitions().get(0).adviceWith(context, new
AdviceWithRouteBuilder() { @Override public void
configure() throws Exception {
replaceFromWith(directEndpoint); weaveById(id_prefix +
"guardarArchivo").replace().to(archivoArchivoPieza);
weaveById(id_prefix + "buscarEventoPieza").remove();
weaveById(id_prefix + "borrarEventoPieza").replace().to(borrarEventoPieza);
weaveById(id_prefix + "buscarConfiguracion").replace().process(new
Processor() { @Override public void
process(Exchange exchange) throws Exception {
exchange.getIn().setHeader((String) exchange.getIn().getHeader("key"), "3");
} }); } }); } @Test public void
testEventoSeArchiva() throws Exception { adviceRoutes();
context.start(); Date fechaPieza =
DateTime.now().plusHours(-4).toDate(); EventoPieza eventoPieza = new
EventoPieza(); eventoPieza.setIntentos(3);
eventoPieza.setUltimaFechaEnvio(fechaPieza);
template.sendBody(directEndpoint,eventoPieza); assertEquals(1,
borrarEventoPieza.getReceivedCounter()); assertEquals(1,
archivoArchivoPieza.getReceivedCounter()); context.stop();
}}*Route def:*public class RutaArchivarItems extends RutaBase { protected
int offset_hours; protected boolean habilitado; JpaEndpoint
jpaEventoPieza = new JpaEndpoint(); JpaEndpoint jpaArchivo = new
JpaEndpoint(); @PostConstruct public void intialize() { String
delay = cf.find(Configuracion.class,
Configuracion.GENERAL_CONSUMER_DELAY).getValue(); int
backoff_multiplier = Integer.valueOf(cf.find(Configuracion.class,
Configuracion.GENERAL_CONSUMER_BACKOFF_MULTIPLIER).getValue()); int
backoff_threshold = Integer.valueOf(cf.find(Configuracion.class,
Configuracion.GENERAL_CONSUMER_BACKOFF_THRESHOLD).getValue());
//EventoPieza jpaEventoPieza.setCamelContext(getContext());
jpaEventoPieza.setEntityType(EventoPieza.class);
jpaEventoPieza.setEntityManagerFactory(entityManagerFactory);
jpaEventoPieza.setTransactionManager(transactionManager);
jpaEventoPieza.setEndpointUriIfNotSpecified("jpa://archivoEventoPieza");
//Consumer jpaEventoPieza.setConsumeDelete(false); Map<String,
Object> prop = new HashMap<>(); prop.put("delay", delay);
prop.put("namedQuery", "pieza.paraArchivar");
jpaEventoPieza.setConsumerProperties(prop);
jpaEventoPieza.setBackoffMultiplier(backoff_multiplier);
jpaEventoPieza.setBackoffIdleThreshold(backoff_threshold);
jpaEventoPieza.setMaximumResults(1000); //Producer
jpaArchivo.setCamelContext(getContext());
jpaArchivo.setEntityType(ArchivoEventos.class);
jpaArchivo.setEntityManagerFactory(entityManagerFactory);
jpaArchivo.setTransactionManager(transactionManager);
jpaArchivo.setFlushOnSend(true);
jpaArchivo.setEndpointUriIfNotSpecified("jpa://archivoArchivoPieza");
offset_hours = Integer.valueOf(cf.find(Configuracion.class,
Configuracion.GENERAL_ARCHIVO_OFFSET).getValue()); habilitado =
Boolean.valueOf(cf.find(Configuracion.class,
Configuracion.GENERAL_ARCHIVO_ENABLED).getValue()); } @Override
public void configure() throws Exception {
from(jpaEventoPieza).routeId("A_" + id_prefix).autoStartup(isHabilitado())
.setHeader("key", constant(Configuracion.GENERAL_ARCHIVO_OFFSET))
.to("buscarConfiguracion").id(id_prefix + "buscarConfiguracion")
.filter().method(BDUtils.class, "piezaListaParaArchivar")
.process(new Processor() { @Override
public void process(Exchange exchange) throws Exception {
Message in = exchange.getIn(); EventoPieza item =
(EventoPieza) in.getBody(); ArchivoEventos
archivoEventos = new ArchivoEventos(item);
in.setBody(archivoEventos); in.setHeader("itemId",
item.getItemId()); in.setHeader("event",
item.getEvent()); in.setHeader("version",
item.getVersion()); } })
.to(jpaArchivo).id(id_prefix + "guardarArchivo")
.log(LoggingLevel.INFO, "Archivar: " + body().toString())
.to("buscarEventoPieza").id(id_prefix + "buscarEventoPieza")
.to("borrarEventoPieza").id(id_prefix + "borrarEventoPieza")
.log(LoggingLevel.INFO, "Borrar: " + body().toString()); } public
boolean isHabilitado() { return habilitado; }}
--
View this message in context:
http://camel.465427.n5.nabble.com/Testing-Jpa-Consumer-Route-tp5797310.html
Sent from the Camel - Users mailing list archive at Nabble.com.