Package org.mokai

Examples of org.mokai.Acceptor


  @Test
  public void shouldReturnUriIfAtLeastOneAcceptorAccepts() throws Exception {
    Processor p1 = mock(Processor.class);
    when(p1.supports(any(Message.class))).thenReturn(true);

    Acceptor a1 = buildAcceptor(true);
    Acceptor a2 = buildAcceptor(false);

    ConnectorService connectorService = buildConnectorService("test1", p1, a1, a2);

    TestRouter router = new TestRouter(Collections.singletonList(connectorService));
View Full Code Here


  }

  @Test
  public void shouldReturnUnroutableUriIfNoProcessors() throws Exception {
    Connector c1 = mock(Connector.class);
    Acceptor a1 = buildAcceptor(true);
    ConnectorService connectorService = buildConnectorService("test1", c1, a1);

    TestRouter router = new TestRouter(Collections.singletonList(connectorService));

    String endpointUri = router.route(new Message());
View Full Code Here

  @Test
  public void shouldReturnFirstUriIfMoreThanOneAccepts() throws Exception {
    Processor p1 = mock(Processor.class);
    when(p1.supports(any(Message.class))).thenReturn(true);

    Acceptor a1 = buildAcceptor(true);

    ConnectorService cs1 = buildConnectorService("test1", p1, a1);
    ConnectorService cs2 = buildConnectorService("test2", p1, a1);

    List<ConnectorService> connectorServices = new ArrayList<ConnectorService>();
View Full Code Here

  @Test
  public void shouldReturnAcceptedUri() throws Exception {
    Processor p1 = mock(Processor.class);
    when(p1.supports(any(Message.class))).thenReturn(true);

    Acceptor a1 = buildAcceptor(false);
    Acceptor a2 = buildAcceptor(true);

    ConnectorService cs1 = buildConnectorService("test1", p1, a1);
    ConnectorService cs2 = buildConnectorService("test2", p1, a2);

    List<ConnectorService> connectorServices = new ArrayList<ConnectorService>();
View Full Code Here

    return connectorService;
  }

  public Acceptor buildAcceptor(boolean accepts) {
    Acceptor acceptor = mock(Acceptor.class);
    when(acceptor.accepts(any(Message.class))).thenReturn(accepts);

    return acceptor;
  }
View Full Code Here

    // iterate through all elements (can be "acceptor" or "and" elements)
    Iterator iterator = acceptorsElement.elementIterator();
    while (iterator.hasNext()) {
      Element acceptorElement = (Element) iterator.next();

      Acceptor acceptor = buildAcceptor(acceptorElement);
      acceptors.add(acceptor);
    }

    return acceptors;
  }
View Full Code Here

  @SuppressWarnings({ "unchecked", "rawtypes" })
  private Acceptor buildAcceptor(Element acceptorElement) throws ClassNotFoundException, InstantiationException,
      IllegalAccessException, SecurityException, IllegalArgumentException, NoSuchFieldException, NoSuchMethodException {

    Acceptor acceptor = null;

    if (acceptorElement.getName().equals("and")) {
      // and is just a wrapper of the AndAcceptor
      AndAcceptor andAcceptor = new AndAcceptor();

      Iterator acceptorIterator = acceptorElement.elementIterator();
      while (acceptorIterator.hasNext()) {
        Acceptor inner = buildAcceptor((Element) acceptorIterator.next());
        andAcceptor.addAcceptor(inner);
      }

      acceptor = andAcceptor;

    } else if (acceptorElement.getName().equals("or")) {
      // or is just a wrapper of the OrAcceptor
      OrAcceptor orAcceptor = new OrAcceptor();

      Iterator acceptorIterator = acceptorElement.elementIterator();
      while (acceptorIterator.hasNext()) {
        Acceptor inner = buildAcceptor((Element) acceptorIterator.next());
        orAcceptor.addAcceptor(inner);
      }

      acceptor = orAcceptor;
View Full Code Here

    List<Acceptor> acceptors = connectorService.getAcceptors();
    Assert.assertNotNull(acceptors);
    Assert.assertEquals(acceptors.size(), 3);

    Acceptor acceptor0 = acceptors.get(0);
    Assert.assertNotNull(acceptor0);
    Assert.assertEquals(acceptor0.getClass(), AndAcceptor.class);
    Assert.assertEquals(((AndAcceptor) acceptor0).getAcceptors().size(), 2);

    Acceptor acceptor1 = acceptors.get(1);
    Assert.assertNotNull(acceptor1);
    Assert.assertEquals(acceptor1.getClass(), AndAcceptor.class);
    Assert.assertEquals(((AndAcceptor) acceptor1).getAcceptors().size(), 2);

    Acceptor acceptor2 = acceptors.get(2);
    Assert.assertNotNull(acceptor2);
    Assert.assertEquals(acceptor2.getClass(), MockAcceptor.class);
  }
View Full Code Here

    List<Acceptor> acceptors = connectorService.getAcceptors();
    Assert.assertNotNull(acceptors);
    Assert.assertEquals(acceptors.size(), 2);

    Acceptor acceptor0 = acceptors.get(0);
    Assert.assertNotNull(acceptor0);
    Assert.assertEquals(acceptor0.getClass(), AndAcceptor.class);
    Assert.assertEquals(((AndAcceptor) acceptor0).getAcceptors().size(), 2);

    Iterator<Acceptor> andAcceptors = ((AndAcceptor) acceptor0).getAcceptors().iterator();
    boolean hasOrAcceptor = false;
    while (andAcceptors.hasNext()) {
      Acceptor a = andAcceptors.next();
      Assert.assertTrue( OrAcceptor.class.isInstance(a) || MockAcceptor.class.isInstance(a));

      if (OrAcceptor.class.isInstance(a)) {
        hasOrAcceptor = true;
        Assert.assertEquals( ((OrAcceptor) a).getAcceptors().size(), 2);
      }
    }
    Assert.assertTrue(hasOrAcceptor);

    Acceptor acceptor1 = acceptors.get(1);
    Assert.assertNotNull(acceptor1);
    Assert.assertEquals(acceptor1.getClass(), OrAcceptor.class);
    Assert.assertEquals(((OrAcceptor) acceptor1).getAcceptors().size(), 2);

    Iterator<Acceptor> orAcceptors = ((OrAcceptor) acceptor1).getAcceptors().iterator();
    boolean hasAndAcceptor = false;
    while (orAcceptors.hasNext()) {
      Acceptor a = orAcceptors.next();
      Assert.assertTrue( AndAcceptor.class.isInstance(a) || MockAcceptor.class.isInstance(a) );

      if (AndAcceptor.class.isInstance(a)) {
        hasAndAcceptor = true;
        Assert.assertEquals( ((AndAcceptor) a).getAcceptors().size(), 2 );
View Full Code Here

      routingEngine.start();

      // create the processor
      MockProcessor processor = new MockProcessor();
      ConnectorService processorService = routingEngine.addConnection("1", processor);
      processorService.addAcceptor(new Acceptor() {

        @Override
        public boolean accepts(Message message) {
          return false;
        }
View Full Code Here

TOP

Related Classes of org.mokai.Acceptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.