Package es.twentymobile.mule.modules.jpa

Source Code of es.twentymobile.mule.modules.jpa.JpaConnectorTest

/**
* This file was automatically generated by the Mule Development Kit
*/
package es.twentymobile.mule.modules.jpa;

import org.mule.api.MuleEvent;
import org.mule.construct.Flow;
import org.mule.tck.junit4.FunctionalTestCase;
import org.mule.tck.junit4.AbstractMuleContextTestCase;

import org.junit.Assert;
import org.junit.Test;

import es.twentymobile.jpa.db.test.Books;

/**
* @author Jose Maria Alvarez Fernandez at 20:20 Mobile Spain, S.A.
* @author Adolfo Gonzalaez Blazquez at 20:20 Mobile Spain, S.A.
*/
public class JpaConnectorTest extends FunctionalTestCase {

  @Override
  protected String getConfigResources() {
    return "mule-config.xml";
  }

  @Test
  public void testProcessorFlow() throws Exception {
    Books book = new Books();
    book.setId(1);
    runFlowWithPayloadAndExpect("testFlow", "Book one", book);
  }

  @Test
  public void testSourceFlow() throws Exception {
    runFlowAndExpect("testFlowIn", "Jose Maria Alvarez");
  }
 
  @Test
  public void testMaxResults() throws Exception {
    runFlowAndExpect("testFlowMaxResults", "Book one");
  }
 
  @Test
  public void testStartPosition() throws Exception {
    runFlowAndExpect("testFlowStartPosition", "Book two");
  }

  /**
   * Run the flow specified by name and assert equality on the expected output
   *
   * @param flowName
   *            The name of the flow to run
   * @param expect
   *            The expected output
   */
  protected <T> void runFlowAndExpect(String flowName, T expect) throws Exception {
    Flow flow = lookupFlowConstruct(flowName);
    MuleEvent event = AbstractMuleContextTestCase.getTestEvent(null);
    MuleEvent responseEvent = flow.process(event);

    Assert.assertEquals(expect, responseEvent.getMessage().getPayload());
  }

  /**
   * Run the flow specified by name using the specified payload and assert
   * equality on the expected output
   *
   * @param flowName
   *            The name of the flow to run
   * @param expect
   *            The expected output
   * @param payload
   *            The payload of the input event
   */
  protected <T, U> void runFlowWithPayloadAndExpect(String flowName, T expect, U payload) throws Exception {
    Flow flow = lookupFlowConstruct(flowName);
    MuleEvent event = AbstractMuleContextTestCase.getTestEvent(payload);
    MuleEvent responseEvent = flow.process(event);

    Assert.assertEquals(expect, responseEvent.getMessage().getPayload());
  }

  /**
   * Retrieve a flow by name from the registry
   *
   * @param name
   *            Name of the flow to retrieve
   */
  protected Flow lookupFlowConstruct(String name) {
    return (Flow) AbstractMuleContextTestCase.muleContext.getRegistry().lookupFlowConstruct(name);
  }
}
TOP

Related Classes of es.twentymobile.mule.modules.jpa.JpaConnectorTest

TOP
Copyright © 2018 www.massapi.com. 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.