private void getAndInitializeFlows() throws InitialisationException {
    // Flow for creating opportunities in sfdc A instance
    createOpportunityInAFlow = getSubFlow("createOpportunityInAFlow");
    createOpportunityInAFlow.initialise();

    // Flow for creating opportunities in sfdc B instance
    createOpportunityInBFlow = getSubFlow("createOpportunityInBFlow");
    createOpportunityInBFlow.initialise();

    // Flow for deleting opportunities in sfdc A instance
    deleteOpportunityFromAFlow = getSubFlow("deleteOpportunityFromAFlow");
    deleteOpportunityFromAFlow.initialise();

    // Flow for deleting opportunities in sfdc B instance
    deleteOpportunityFromBFlow = getSubFlow("deleteOpportunityFromBFlow");
    deleteOpportunityFromBFlow.initialise();

    // Flow for querying opportunities in sfdc A instance
    queryOpportunityFromAFlow = getSubFlow("queryOpportunityFromAFlow");
    queryOpportunityFromAFlow.initialise();

    // Flow for querying opportunities in sfdc B instance
    queryOpportunityFromBFlow = getSubFlow("queryOpportunityFromBFlow");
    queryOpportunityFromBFlow.initialise();
  }
 @SuppressWarnings("unchecked")
 private void createTestDataInSandBox() throws MuleException, Exception {
   SubflowInterceptingChainLifecycleWrapper flow = getSubFlow("hireEmployee");
   flow.initialise();
   logger.info("creating a workday employee...");
   try {
     flow.process(getTestEvent(prepareNewHire(), MessageExchangePattern.REQUEST_RESPONSE));
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  private void deleteTestDataFromSandBox() throws MuleException, Exception {
    // Delete the created users in SFDC
    logger.info("deleting test data...");
    SubflowInterceptingChainLifecycleWrapper deleteFlow = getSubFlow("deleteSFDC");
    deleteFlow.initialise();

    List<String> idList = new ArrayList<String>();
    idList.add(SFDC_ID);
    idList.add(ACCOUNT_ID);
    idList.add(CONTACT_ID);
    deleteFlow.process(getTestEvent(idList, MessageExchangePattern.REQUEST_RESPONSE));
    // Delete the created users in Workday
    SubflowInterceptingChainLifecycleWrapper flow = getSubFlow("getWorkdaytoTerminateFlow");
    flow.initialise();

    try {
      MuleEvent response =
          flow.process(getTestEvent(getEmployee(), MessageExchangePattern.REQUEST_RESPONSE));
      flow = getSubFlow("terminateWorkdayEmployee");
      flow.initialise();
      flow.process(
          getTestEvent(prepareTerminate(response), MessageExchangePattern.REQUEST_RESPONSE));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 private static void cleanUpSandboxesByRemovingTestOpportunities()
     throws MuleException, Exception {
   final List<String> idList = new ArrayList<String>();
   for (String opportunity : opportunitiesCreatedInA) {
     idList.add(opportunity);
   }
   deleteOpportunityFromAFlow.process(
       getTestEvent(idList, MessageExchangePattern.REQUEST_RESPONSE));
   idList.clear();
   for (String opportunity : opportunitiesCreatedInB) {
     idList.add(opportunity);
   }
   deleteOpportunityFromBFlow.process(
       getTestEvent(idList, MessageExchangePattern.REQUEST_RESPONSE));
 }
  @SuppressWarnings("unchecked")
  @Test
  public void testMainFlow() throws Exception {
    Thread.sleep(20000);
    runSchedulersOnce(POLL_FLOW_NAME);
    waitForPollToRun();
    helper.awaitJobTermination(TIMEOUT_MILLIS, DELAY_MILLIS);
    helper.assertJobWasSuccessful();

    SubflowInterceptingChainLifecycleWrapper flow = getSubFlow("getWorkdayEmployee");
    flow.initialise();
    MuleEvent response =
        flow.process(getTestEvent(getEmployee(), MessageExchangePattern.REQUEST_RESPONSE));
    EmployeeType workerRes = (EmployeeType) response.getMessage().getPayload();
    logger.info("worker id:" + workerRes.getEmployeeData().get(0).getEmployeeID());

    flow = getSubFlow("retrieveCaseSFDC");
    flow.initialise();

    ConsumerIterator<Map<String, Object>> iterator =
        (ConsumerIterator<Map<String, Object>>)
            flow.process(
                    getTestEvent(
                        workerRes.getEmployeeData().get(0).getEmployeeID(),
                        MessageExchangePattern.REQUEST_RESPONSE))
                .getMessage()
                .getPayload();
    Map<String, Object> caseMap = iterator.next();
    SFDC_ID = caseMap.get("Id").toString();
    ACCOUNT_ID = caseMap.get("AccountId").toString();
    CONTACT_ID = caseMap.get("ContactId").toString();
    assertEquals(
        "Subject should be synced",
        employee.getGivenName() + " " + employee.getFamilyName() + " Case",
        caseMap.get("Subject"));
    assertEquals("Email should be synced", EMAIL, caseMap.get("SuppliedEmail"));
  }