use of java.util.Set in project camel by apache.
the class BacklogDebuggerTest method testBacklogDebugger.
@SuppressWarnings("unchecked")
public void testBacklogDebugger() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MBeanServer mbeanServer = getMBeanServer();
ObjectName on = new ObjectName("org.apache.camel:context=camel-1,type=tracer,name=BacklogDebugger");
assertNotNull(on);
mbeanServer.isRegistered(on);
Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
assertEquals("Should not be enabled", Boolean.FALSE, enabled);
// enable debugger
mbeanServer.invoke(on, "enableDebugger", null, null);
enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
assertEquals("Should be enabled", Boolean.TRUE, enabled);
// add breakpoint at bar
mbeanServer.invoke(on, "addBreakpoint", new Object[] { "bar" }, new String[] { "java.lang.String" });
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(0);
mock.setSleepForEmptyTest(1000);
template.sendBody("seda:start", "Hello World");
assertMockEndpointsSatisfied();
// add breakpoint at bar
Set<String> nodes = (Set<String>) mbeanServer.invoke(on, "getSuspendedBreakpointNodeIds", null, null);
assertNotNull(nodes);
assertEquals(1, nodes.size());
assertEquals("bar", nodes.iterator().next());
// the message should be ours
String xml = (String) mbeanServer.invoke(on, "dumpTracedMessagesAsXml", new Object[] { "bar" }, new String[] { "java.lang.String" });
assertNotNull(xml);
log.info(xml);
assertTrue("Should contain our body", xml.contains("Hello World"));
assertTrue("Should contain bar node", xml.contains("<toNode>bar</toNode>"));
resetMocks();
mock.expectedMessageCount(1);
// resume breakpoint
mbeanServer.invoke(on, "resumeBreakpoint", new Object[] { "bar" }, new String[] { "java.lang.String" });
assertMockEndpointsSatisfied();
// and no suspended anymore
nodes = (Set<String>) mbeanServer.invoke(on, "getSuspendedBreakpointNodeIds", null, null);
assertNotNull(nodes);
assertEquals(0, nodes.size());
}
use of java.util.Set in project camel by apache.
the class BindyAbstractDataFormat method tryToGetFactoryRegistry.
private FactoryRegistry tryToGetFactoryRegistry() {
Function<CamelContext, Registry> f = CamelContext::getRegistry;
Function<Registry, Set<FactoryRegistry>> g = r -> r.findByType(FactoryRegistry.class);
Function<Set<FactoryRegistry>, FactoryRegistry> h = factoryRegistries -> {
if (factoryRegistries.size() > 1) {
LOGGER.warn("Number of registered {}: {}", FactoryRegistry.class.getCanonicalName(), factoryRegistries.size());
}
if (factoryRegistries.iterator().hasNext()) {
return factoryRegistries.iterator().next();
} else {
return new DefaultFactoryRegistry();
}
};
return Optional.ofNullable(camelContext).map(f).map(g).map(h).orElse(new DefaultFactoryRegistry());
}
use of java.util.Set in project camel by apache.
the class BeanValidatorRouteTest method validateShouldFailWithOrderedChecksGroup.
@Test
public void validateShouldFailWithOrderedChecksGroup() throws Exception {
if (isPlatform("aix")) {
// cannot run on aix
return;
}
final String url = "bean-validator://x?group=org.apache.camel.component.bean.validator.OrderedChecks";
final Car car = createCar(null, "D-A");
try {
template.requestBody(url, car);
fail("should throw exception");
} catch (CamelExecutionException e) {
assertIsInstanceOf(BeanValidationException.class, e.getCause());
BeanValidationException exception = (BeanValidationException) e.getCause();
Set<ConstraintViolation<Object>> constraintViolations = exception.getConstraintViolations();
assertEquals(1, constraintViolations.size());
ConstraintViolation<Object> constraintViolation = constraintViolations.iterator().next();
assertEquals("manufacturer", constraintViolation.getPropertyPath().toString());
assertEquals(null, constraintViolation.getInvalidValue());
assertEquals("may not be null", constraintViolation.getMessage());
}
car.setManufacturer("BMW");
try {
template.requestBody(url, car);
fail("should throw exception");
} catch (CamelExecutionException e) {
assertIsInstanceOf(BeanValidationException.class, e.getCause());
BeanValidationException exception = (BeanValidationException) e.getCause();
Set<ConstraintViolation<Object>> constraintViolations = exception.getConstraintViolations();
assertEquals(1, constraintViolations.size());
ConstraintViolation<Object> constraintViolation = constraintViolations.iterator().next();
assertEquals("licensePlate", constraintViolation.getPropertyPath().toString());
assertEquals("D-A", constraintViolation.getInvalidValue());
assertEquals("size must be between 5 and 14", constraintViolation.getMessage());
}
car.setLicensePlate("DD-AB-123");
Exchange exchange = template.request(url, new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(car);
}
});
assertNotNull(exchange);
}
use of java.util.Set in project camel by apache.
the class BeanValidatorRouteTest method validateShouldFailWithExpliciteDefaultGroup.
@Test
public void validateShouldFailWithExpliciteDefaultGroup() throws Exception {
if (isPlatform("aix")) {
// cannot run on aix
return;
}
final String url = "bean-validator://x?group=javax.validation.groups.Default";
final Car car = createCar("BMW", null);
try {
template.requestBody(url, car);
fail("should throw exception");
} catch (CamelExecutionException e) {
assertIsInstanceOf(BeanValidationException.class, e.getCause());
BeanValidationException exception = (BeanValidationException) e.getCause();
Set<ConstraintViolation<Object>> constraintViolations = exception.getConstraintViolations();
assertEquals(1, constraintViolations.size());
ConstraintViolation<Object> constraintViolation = constraintViolations.iterator().next();
assertEquals("licensePlate", constraintViolation.getPropertyPath().toString());
assertEquals(null, constraintViolation.getInvalidValue());
assertEquals("may not be null", constraintViolation.getMessage());
}
car.setLicensePlate("D-A");
Exchange exchange = template.request(url, new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(car);
}
});
assertNotNull(exchange);
}
use of java.util.Set in project camel by apache.
the class BeanValidatorRouteTest method validateShouldFailWithOptionalChecksGroup.
@Test
public void validateShouldFailWithOptionalChecksGroup() throws Exception {
if (isPlatform("aix")) {
// cannot run on aix
return;
}
final String url = "bean-validator://x?group=org.apache.camel.component.bean.validator.OptionalChecks";
final Car car = createCar("BMW", "D-A");
try {
template.requestBody(url, car);
fail("should throw exception");
} catch (CamelExecutionException e) {
assertIsInstanceOf(BeanValidationException.class, e.getCause());
BeanValidationException exception = (BeanValidationException) e.getCause();
Set<ConstraintViolation<Object>> constraintViolations = exception.getConstraintViolations();
assertEquals(1, constraintViolations.size());
ConstraintViolation<Object> constraintViolation = constraintViolations.iterator().next();
assertEquals("licensePlate", constraintViolation.getPropertyPath().toString());
assertEquals("D-A", constraintViolation.getInvalidValue());
assertEquals("size must be between 5 and 14", constraintViolation.getMessage());
}
car.setLicensePlate("DD-AB-123");
Exchange exchange = template.request(url, new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(car);
}
});
assertNotNull(exchange);
}
Aggregations