@Before
  public void before() throws Exception {

    when(resourceMock1.getPathWithinContext()).thenReturn(resourceName1);
    when(resourceMock1.getFile()).thenReturn(fileMock1);

    when(resourceMock2.getDescription()).thenReturn(resourceName2);
    when(resourceMock2.getFile()).thenReturn(fileMock2);

    when(resourceMock3.getFile()).thenReturn(fileMock3);
    when(fileMock3.getAbsolutePath()).thenReturn(resourceName3);

    when(resourceMock4.getFile()).thenReturn(fileMock4);
    when(fileMock4.getAbsolutePath()).thenReturn(resourceName4);

    when(resourceMock5.getFile()).thenReturn(fileMock5);
    when(fileMock5.getAbsolutePath()).thenReturn(resourceName5);

    when(resourceMock1.getInputStream()).thenReturn(inputStreamMock);
    when(resourceMock2.getInputStream()).thenReturn(inputStreamMock);
    when(resourceMock3.getInputStream()).thenReturn(inputStreamMock);
    when(resourceMock4.getInputStream()).thenReturn(inputStreamMock);
    when(resourceMock5.getInputStream()).thenReturn(inputStreamMock);

    when(repositoryServiceMock.createDeployment()).thenReturn(deploymentBuilderMock);
    when(deploymentBuilderMock.enableDuplicateFiltering()).thenReturn(deploymentBuilderMock);
    when(deploymentBuilderMock.name(isA(String.class))).thenReturn(deploymentBuilderMock);

    when(deploymentBuilderMock.deploy()).thenReturn(deploymentMock);
  }
  @BeforeClass
  public static void init() throws FileNotFoundException {
    servers = new AllServers();
    servers.start();

    // Create Activiti process engine
    processEngine =
        ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration()
            .buildProcessEngine();

    RepositoryService repositoryService = processEngine.getRepositoryService();
    DeploymentBuilder builder = repositoryService.createDeployment();
    String xmlFile = "PaymentProcess.bpmn";
    builder.addClasspathResource("diagrams/" + xmlFile);
    builder.name(xmlFile);
    builder.deploy();
    runtimeService = processEngine.getRuntimeService();
  }
  @BeforeClass
  public static void init() {
    MailServiceImpl service = new MailServiceImpl();
    service.setRecipient("wfm@localhost");

    service.setMessage("hello");
    service.sendMessage();
    // Create Activiti process engine
    processEngine =
        ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration()
            .setMailServerPort(1025)
            .buildProcessEngine();
    runtimeService = processEngine.getRuntimeService();
    RepositoryService repositoryService = processEngine.getRepositoryService();
    DeploymentBuilder builder = repositoryService.createDeployment();
    String xmlFile = "EventTest.bpmn";
    builder.addClasspathResource("diagrams/" + xmlFile);
    builder.name(xmlFile);
    builder.deploy();
  }
  /**
   * * 文件上传功能,该功能需要在bean配置中添加multipartResolver,并引入commons-fileupload包 否则会出现下面的错误
   * org.springframework.web.util.NestedServletException: Request processing failed; nested
   * exception is java.lang.IllegalArgumentException: Expected MultipartHttpServletRequest: is a
   * MultipartResolver configured?
   *
   * @param file
   * @return
   */
  @RequestMapping(value = "/deploy")
  public String deploy(@RequestParam(value = "file") MultipartFile file) {
    String filenName = file.getOriginalFilename();
    try {
      InputStream fileInputStream = file.getInputStream();

      String extension = FilenameUtils.getExtension(filenName);
      DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
      if (extension.equals("zip") || extension.equals("bar")) {
        ZipInputStream zip = new ZipInputStream(fileInputStream);
        deploymentBuilder.addZipInputStream(zip);
      } else {
        deploymentBuilder.addInputStream(filenName, fileInputStream);
      }
      deploymentBuilder.deploy();
    } catch (Exception ex) {
      log.error("error on deploy process,because of file input stream");
    }
    return "redirect:/workflow/process-list";
  }
  protected void autoDeployResources(ProcessEngine processEngine) {
    if (deploymentResources != null && deploymentResources.length > 0) {
      RepositoryService repositoryService = processEngine.getRepositoryService();

      DeploymentBuilder deploymentBuilder =
          repositoryService.createDeployment().enableDuplicateFiltering().name(deploymentName);

      for (Resource resource : deploymentResources) {
        String resourceName = null;

        if (resource instanceof ContextResource) {
          resourceName = ((ContextResource) resource).getPathWithinContext();

        } else if (resource instanceof ByteArrayResource) {
          resourceName = resource.getDescription();

        } else {
          try {
            resourceName = resource.getFile().getAbsolutePath();
          } catch (IOException e) {
            resourceName = resource.getFilename();
          }
        }

        try {
          if (resourceName.endsWith(".bar")
              || resourceName.endsWith(".zip")
              || resourceName.endsWith(".jar")) {
            deploymentBuilder.addZipInputStream(new ZipInputStream(resource.getInputStream()));
          } else {
            deploymentBuilder.addInputStream(resourceName, resource.getInputStream());
          }
        } catch (IOException e) {
          throw new ActivitiException(
              "couldn't auto deploy resource '" + resource + "': " + e.getMessage(), e);
        }
      }

      deploymentBuilder.deploy();
    }
  }