@Test
 public void testBean() {
   ExpressionContext context = new ExpressionContext();
   DocumentModel source = doCreateDocument();
   EventContext eventContext = new DocumentEventContext(session, session.getPrincipal(), source);
   Map<String, Serializable> properties = new HashMap<String, Serializable>();
   properties.put("test", "test");
   eventContext.setProperties(properties);
   evaluatorUnderTest.bindValue(context, "context", eventContext);
   DocumentModel value =
       evaluatorUnderTest.evaluateExpression(
           context, "${context.arguments[0]}", DocumentModel.class);
   assertNotNull(value);
   assertEquals(source, value);
   String test =
       evaluatorUnderTest.evaluateExpression(context, "${context.properties.test}", String.class);
   assertNotNull(value);
   assertEquals("test", test);
 }
  @Override
  public void handleEvent(Event event) {
    EventContext eventContext = event.getContext();
    Serializable property =
        eventContext.getProperty(TaskService.TASK_INSTANCE_EVENT_PROPERTIES_KEY);
    if (property == null || !(property instanceof Task)) {
      // do nothing
      return;
    }
    Task task = (Task) property;

    Boolean validated =
        Boolean.valueOf(task.getVariable(TaskService.VariableName.validated.name()));

    String chain;
    if (validated) {
      chain = task.getVariable(OperationTaskVariableName.acceptOperationChain.name());
    } else {
      chain = task.getVariable(OperationTaskVariableName.rejectOperationChain.name());
    }

    if (!StringUtils.isEmpty(chain)) {
      try {
        // run the given operation
        AutomationService os = Framework.getService(AutomationService.class);
        OperationContext ctx = new OperationContext(eventContext.getCoreSession());
        if (eventContext instanceof DocumentEventContext) {
          ctx.setInput(((DocumentEventContext) eventContext).getSourceDocument());
          ctx.put(OperationTaskVariableName.taskDocument.name(), task.getDocument());
        }
        try {
          os.run(ctx, chain);
        } catch (InvalidChainException e) {
          log.error("Unknown chain: " + chain);
        }
      } catch (OperationException t) {
        log.error(t, t);
      }
    }
  }
  public static void notifyEvent(
      CoreSession coreSession,
      DocumentModel document,
      NuxeoPrincipal principal,
      Task task,
      String eventId,
      Map<String, Serializable> properties,
      String comment,
      String category)
      throws ClientException {
    // Default category
    if (category == null) {
      category = DocumentEventCategories.EVENT_DOCUMENT_CATEGORY;
    }
    if (properties == null) {
      properties = new HashMap<String, Serializable>();
    }

    EventContext eventContext = null;
    if (document != null) {
      properties.put(CoreEventConstants.REPOSITORY_NAME, document.getRepositoryName());
      properties.put(CoreEventConstants.SESSION_ID, coreSession.getSessionId());
      properties.put(CoreEventConstants.DOC_LIFE_CYCLE, document.getCurrentLifeCycleState());
      eventContext = new DocumentEventContext(coreSession, principal, document);
    } else {
      eventContext = new EventContextImpl(coreSession, principal);
    }
    properties.put(DocumentEventContext.COMMENT_PROPERTY_KEY, comment);
    properties.put(DocumentEventContext.CATEGORY_PROPERTY_KEY, category);
    properties.put(TaskService.TASK_INSTANCE_EVENT_PROPERTIES_KEY, task);
    String disableNotif = task.getVariable(TaskEventNames.DISABLE_NOTIFICATION_SERVICE);
    if (disableNotif != null && Boolean.TRUE.equals(Boolean.valueOf(disableNotif))) {
      properties.put(TaskEventNames.DISABLE_NOTIFICATION_SERVICE, Boolean.TRUE);
    }
    eventContext.setProperties(properties);

    Event event = eventContext.newEvent(eventId);
    getEventProducer().fireEvent(event);
  }