Package org.mokai

Examples of org.mokai.ConnectorService


    // add processed validation
    MockEndpoint outboundEndpoint = getProcessedMessagesEndpoint(1);
    MockEndpoint failedEndpoint = getFailedMessagesEndpoint(0);

    MockProcessor processor = new MockProcessor();
    ConnectorService connectorService = new MockConnectorService("test", processor, resourceRegistry);
    connectorService.start();

    Assert.assertEquals(Status.UNKNOWN, connectorService.getStatus());

    simulateMessage(new Message(), "activemq:mokai-test");

    outboundEndpoint.assertIsSatisfied(DEFAULT_TIMEOUT);
    failedEndpoint.assertIsSatisfied(DEFAULT_TIMEOUT);

    Assert.assertEquals(Status.UNKNOWN, connectorService.getStatus());
    Assert.assertEquals(1, processor.getCount());

    Message message = (Message) processor.getMessage(0);
    Assert.assertNotNull(message);
    Assert.assertEquals("test", message.getDestination());
View Full Code Here


  }

  @Test
  public void testConnectorServiceState() throws Exception {
    Connector connector = Mockito.mock(Connector.class);
    ConnectorService processorService = new MockConnectorService("test", connector, resourceRegistry);
    Assert.assertEquals(State.STOPPED, processorService.getState());

    processorService.start();
    Assert.assertEquals(State.STARTED, processorService.getState());

    processorService.stop();
    Assert.assertEquals(State.STOPPED, processorService.getState());
  }
View Full Code Here

    Processor processor = Mockito.mock(Processor.class);
    Mockito
      .doThrow(new NullPointerException())
      .when(processor).process(Mockito.any(Message.class));

    ConnectorService processorService = new MockConnectorService("test", processor, resourceRegistry);
    processorService.start();

    // check that the status is UNKNOWN
    Assert.assertEquals(Status.UNKNOWN, processorService.getStatus());

    // simulate the message
    simulateMessage(new Message(), "activemq:mokai-test");

    // wait until the message fails
    failedEndpoint.assertIsSatisfied(DEFAULT_TIMEOUT);
    outboundEndpoint.assertIsSatisfied(DEFAULT_TIMEOUT);

    // check that the status is FAILED
    Assert.assertEquals(Status.FAILED, processorService.getStatus());

    // add processed validation
    outboundEndpoint.reset();
    outboundEndpoint.expectedMessageCount(1);
    failedEndpoint.reset();
    failedEndpoint.expectedMessageCount(0);

    Mockito.doNothing()
      .when(processor)
      .process(Mockito.any(Message.class));

    // simulate the message
    simulateMessage(new Message(), "activemq:mokai-test");

    // wait until the message is processed
    outboundEndpoint.assertIsSatisfied(DEFAULT_TIMEOUT);
    failedEndpoint.assertIsSatisfied(DEFAULT_TIMEOUT);

    // check that the status is back to UNKNOWN
    Assert.assertEquals(Status.UNKNOWN, processorService.getStatus());
  }
View Full Code Here

      Mockito.mock(Processor.class, Mockito.withSettings().extraInterfaces(Monitorable.class));
    Mockito
      .when(((Monitorable) processor).getStatus())
      .thenReturn(Status.OK);

    ConnectorService processorService = new MockConnectorService("test", processor, resourceRegistry);
    processorService.start();

    Assert.assertEquals(Status.OK, processorService.getStatus());

    // simulate the message
    simulateMessage(new Message(), "activemq:mokai-test");

    outboundEndpoint.assertIsSatisfied(DEFAULT_TIMEOUT);
    failedEndpoint.assertIsSatisfied(DEFAULT_TIMEOUT);

    Assert.assertEquals(Status.OK, processorService.getStatus());
  }
View Full Code Here

      Mockito.mock(Processor.class, Mockito.withSettings().extraInterfaces(Monitorable.class));
    Mockito
      .when(((Monitorable) processor).getStatus())
      .thenReturn(Status.FAILED);

    ConnectorService processorService = new MockConnectorService("test", processor, resourceRegistry);
    processorService.start();

    Assert.assertEquals(Status.FAILED, processorService.getStatus());

    // simulate the message
    simulateMessage(new Message(), "activemq:mokai-test");

    outboundEndpoint.assertIsSatisfied(DEFAULT_TIMEOUT);
    failedEndpoint.assertIsSatisfied(DEFAULT_TIMEOUT);

    Assert.assertEquals(Status.FAILED, processorService.getStatus());
  }
View Full Code Here

      .when(processor).process(Mockito.any(Message.class));
    Mockito
      .when(((Monitorable) processor).getStatus())
      .thenReturn(Status.OK);

    ConnectorService processorService = new MockConnectorService("test", processor, resourceRegistry);
    processorService.start();
    Assert.assertEquals(Status.OK, processorService.getStatus());

    // simulate the message
    simulateMessage(new Message(), "activemq:mokai-test");

    failedEndpoint.assertIsSatisfied(DEFAULT_TIMEOUT);
    outboundEndpoint.assertIsSatisfied(DEFAULT_TIMEOUT);

    Assert.assertEquals(Status.FAILED, processorService.getStatus());
  }
View Full Code Here

  public void testProcessingActions() throws Exception {
    MockEndpoint outboundEndpoint = getProcessedMessagesEndpoint(1);
    MockEndpoint failedEndpoint = getFailedMessagesEndpoint(0);

    MockProcessor processor = new MockProcessor();
    ConnectorService processorService = new MockConnectorService("test", processor, resourceRegistry);

    // add a pre-processing action
    MockAction preProcessingAction = new MockAction();
    processorService.addPreProcessingAction(preProcessingAction);

    // add another pre-processing action that changes the message
    processorService.addPreProcessingAction(new Action() {

      @Override
      public void execute(Message message) throws Exception {
        Message smsMessage = (Message) message;
        smsMessage.setProperty("from", "1234");
      }

    });

    // add a post-processing action
    MockAction postProcessingAction = new MockAction();
    processorService.addPostProcessingAction(postProcessingAction);

    // add another post-processing action that changes the message
    processorService.addPostProcessingAction(new Action() {

      @Override
      public void execute(Message message) throws Exception {
        Message smsMessage = (Message) message;
        smsMessage.setProperty("to", "1111");
      }

    });

    processorService.start();

    simulateMessage(new Message(), "activemq:mokai-test");

    outboundEndpoint.assertIsSatisfied(DEFAULT_TIMEOUT);
    failedEndpoint.assertIsSatisfied(DEFAULT_TIMEOUT);
View Full Code Here

  public void testPostReceivingActions() throws Exception {
    // validation route
    MockEndpoint inboundEndpoint = getReceivedMessagesEndpoint(1);

    SimpleReceiverProcessor processor = new SimpleReceiverProcessor();
    ConnectorService processorService = new MockConnectorService("test", processor, resourceRegistry);
    processorService.start();

    // add post-receiving action
    MockAction postReceivingAction = new MockAction();
    processorService.addPostReceivingAction(postReceivingAction);

    // add another post-receiving action that changes the message
    processorService.addPostReceivingAction(new Action() {

      @Override
      public void execute(Message message) throws Exception {
        message.setReference("germanescobar");
      }
View Full Code Here

    new MockConnectorService(null, new MockProcessor(), resourceRegistry);
  }

  @Test(expectedExceptions=IllegalArgumentException.class)
  public void shouldFailWithNullAcceptor() throws Exception {
    ConnectorService processorService = new MockConnectorService("test", new MockProcessor(), resourceRegistry);
    processorService.addAcceptor(null);
  }
View Full Code Here

    new MockConnectorService("", new MockProcessor(), resourceRegistry);
  }

  @Test
  public void testIdWithSpaces() throws Exception {
    ConnectorService processorService = new MockConnectorService("T e s T", new MockProcessor(), resourceRegistry);
    Assert.assertEquals("test", processorService.getId());
  }
View Full Code Here

TOP

Related Classes of org.mokai.ConnectorService

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.