Search in sources :

Example 6 with Set

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());
}
Also used : Set(java.util.Set) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 7 with Set

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());
}
Also used : CamelContext(org.apache.camel.CamelContext) CamelContext(org.apache.camel.CamelContext) CamelContextAware(org.apache.camel.CamelContextAware) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) Registry(org.apache.camel.spi.Registry) DefaultFactoryRegistry(org.apache.camel.dataformat.bindy.format.factories.DefaultFactoryRegistry) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) HashMap(java.util.HashMap) Field(java.lang.reflect.Field) Function(java.util.function.Function) ArrayList(java.util.ArrayList) FactoryRegistry(org.apache.camel.dataformat.bindy.format.factories.FactoryRegistry) DataFormatName(org.apache.camel.spi.DataFormatName) Link(org.apache.camel.dataformat.bindy.annotation.Link) DataFormat(org.apache.camel.spi.DataFormat) List(java.util.List) Map(java.util.Map) Optional(java.util.Optional) ServiceSupport(org.apache.camel.support.ServiceSupport) FormatFactoryInterface(org.apache.camel.dataformat.bindy.format.factories.FormatFactoryInterface) FormatFactories(org.apache.camel.dataformat.bindy.annotation.FormatFactories) Collections(java.util.Collections) DefaultFactoryRegistry(org.apache.camel.dataformat.bindy.format.factories.DefaultFactoryRegistry) Set(java.util.Set) DefaultFactoryRegistry(org.apache.camel.dataformat.bindy.format.factories.DefaultFactoryRegistry) FactoryRegistry(org.apache.camel.dataformat.bindy.format.factories.FactoryRegistry) Registry(org.apache.camel.spi.Registry) DefaultFactoryRegistry(org.apache.camel.dataformat.bindy.format.factories.DefaultFactoryRegistry) FactoryRegistry(org.apache.camel.dataformat.bindy.format.factories.FactoryRegistry)

Example 8 with Set

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);
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) Exchange(org.apache.camel.Exchange) Set(java.util.Set) Processor(org.apache.camel.Processor) ConstraintViolation(javax.validation.ConstraintViolation) CamelExecutionException(org.apache.camel.CamelExecutionException) Test(org.junit.Test)

Example 9 with Set

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);
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) Exchange(org.apache.camel.Exchange) Set(java.util.Set) Processor(org.apache.camel.Processor) ConstraintViolation(javax.validation.ConstraintViolation) CamelExecutionException(org.apache.camel.CamelExecutionException) Test(org.junit.Test)

Example 10 with Set

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);
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) Exchange(org.apache.camel.Exchange) Set(java.util.Set) Processor(org.apache.camel.Processor) ConstraintViolation(javax.validation.ConstraintViolation) CamelExecutionException(org.apache.camel.CamelExecutionException) Test(org.junit.Test)

Aggregations

Set (java.util.Set)6789 HashSet (java.util.HashSet)4372 HashMap (java.util.HashMap)2090 Map (java.util.Map)1865 Iterator (java.util.Iterator)1774 ArrayList (java.util.ArrayList)1113 List (java.util.List)980 Test (org.junit.Test)920 TreeSet (java.util.TreeSet)536 IOException (java.io.IOException)501 SSOException (com.iplanet.sso.SSOException)467 LinkedHashSet (java.util.LinkedHashSet)418 SMSException (com.sun.identity.sm.SMSException)347 IdRepoException (com.sun.identity.idm.IdRepoException)268 Collection (java.util.Collection)259 ImmutableSet (com.google.common.collect.ImmutableSet)256 File (java.io.File)245 SSOToken (com.iplanet.sso.SSOToken)226 Collectors (java.util.stream.Collectors)219 Test (org.testng.annotations.Test)209