/**
  * Each message will be divided into groups and create the map message
  *
  * @param producer Used for sending messages to a destination
  * @param session Used to produce the messages to be sent
  * @param messagesList List of messages to be sent
  */
 public static void publishTextMessage(
     MessageProducer producer, Session session, List<String> messagesList) throws JMSException {
   for (String message : messagesList) {
     TextMessage jmsMessage = session.createTextMessage();
     jmsMessage.setText(message);
     producer.send(jmsMessage);
   }
 }
 /**
  * Each message will be divided into groups and create the map message
  *
  * @param producer Used for sending messages to a destination
  * @param session Used to produce the messages to be sent
  * @param messagesList List of messages to be sent individual message event data should be in
  *     "attributeName(attributeType):attributeValue" format
  */
 public static void publishMapMessage(
     MessageProducer producer, Session session, List<String> messagesList)
     throws IOException, JMSException {
   String regexPattern = "(.*)\\((.*)\\):(.*)";
   Pattern pattern = Pattern.compile(regexPattern);
   for (String message : messagesList) {
     MapMessage mapMessage = session.createMapMessage();
     for (String line : message.split("\\n")) {
       if (line != null && !line.equalsIgnoreCase("")) {
         Matcher matcher = pattern.matcher(line);
         if (matcher.find()) {
           mapMessage.setObject(
               matcher.group(1), parseAttributeValue(matcher.group(2), matcher.group(3)));
         }
       }
     }
     producer.send(mapMessage);
   }
 }
  @Test
  public void genericEmergencyProcedureTest()
      throws HornetQException, InterruptedException, IOException, ClassNotFoundException {

    asynchProcedureStartWorker =
        new MessageConsumerWorker(
            "asyncProcedureStartCoreServer",
            new MessageConsumerWorkerHandler<AsyncProcedureStartMessage>() {

              @Override
              public void handleMessage(AsyncProcedureStartMessage message) {
                System.out.println(
                    ">>>>>>>>>>>Creating a new Procedure = " + message.getProcedureName());
                try {
                  ProceduresMGMTService.getInstance()
                      .newRequestedProcedure(
                          message.getEmergencyId(),
                          message.getProcedureName(),
                          message.getParameters());
                } catch (IOException ex) {
                  Logger.getLogger(GenericEmergencyProcedureTest.class.getName())
                      .log(Level.SEVERE, null, ex);
                }
              }
            });

    asynchProcedureStartWorker.start();

    MessageProducer producer = MessageFactory.createMessageProducer();
    Call initialCall = new Call(1, 2, new Date());

    producer.sendMessage(initialCall);
    producer.stop();

    Call call = (Call) consumer.receiveMessage();
    assertNotNull(call);

    GenericEmergencyProcedureImpl.getInstance().newPhoneCall(call);

    Thread.sleep(5000);

    doOperatorTask();

    // QUERY TO SEE THAT WE HAVE AN EMERGENCY ATTACHED TO THE CALL

    Thread.sleep(2000);

    doControlTask();

    Thread.sleep(6000);
    // I should have one task here, that has been created by the specific procedure started
    doGarageTask();

    Thread.sleep(3000);
    // I can asume that all the procedures are ended, we need to delegate this to the external
    // component
    AllProceduresEndedEvent allProceduresEndedEvent =
        new AllProceduresEndedEvent(null, new ArrayList<String>());
    GenericEmergencyProcedureImpl.getInstance()
        .allProceduresEnededNotification(allProceduresEndedEvent);
    // We should see the report in the console
    Thread.sleep(10000);
  }