@Test(dataProvider = "getSetInvalidStateParams")
  public void testSetInvalidState(ImageState originalState, ImageState newState) throws Exception {
    ImageEntity image = new ImageEntity();
    image.setState(originalState);

    try {
      image.setState(newState);
      fail("setState should throw exception");
    } catch (IllegalStateException ex) {
      assertThat(ex.getMessage(), is(String.format("%s -> %s", originalState, newState)));
    }
  }
 @Test(dataProvider = "getSetValidStateParams")
 public void testSetValidState(ImageState originalState, ImageState newState) throws Exception {
   ImageEntity image = new ImageEntity();
   image.setState(originalState);
   image.setState(newState);
 }
  @RequestMapping(
      value = {"/workspace/trade-union-activists/add-event"},
      method = RequestMethod.POST)
  public String addEvents(
      @ModelAttribute("uploadForm") FileUploadForm uploadForm,
      @RequestParam String eventName,
      @RequestParam String typeOfEvent,
      @RequestParam String countParticipants,
      @RequestParam String dateBegin,
      @RequestParam String dateEnd,
      @RequestParam String descriptionEvent,
      @RequestParam String roleUser,
      @RequestParam String intervalsOfAMailingGroup,
      Principal principal,
      ModelMap modelMap) {
    TypeOfEventEntity typeOfEventEntity = eventTypeService.findById(typeOfEvent);
    EventEntity eventEntity = new EventEntity();
    eventEntity.setRoleParticipants("[" + roleUser + "]");
    eventEntity.setIdEvent(Utils.generateIdentifier());
    eventEntity.setEventDescription(descriptionEvent);
    eventEntity.setIntervalsOfAMailingGroup(intervalsOfAMailingGroup);
    eventEntity.setEventName(eventName);
    eventEntity.setCountParticipants(new Integer(countParticipants));
    eventEntity.setDateAndTimeBegin(Utils.convertStringToSqlFormatDate(dateBegin));
    eventEntity.setDateAndTimeEnd(Utils.convertStringToSqlFormatDate(dateEnd));
    eventEntity.setIdTypeOfEvent(typeOfEventEntity.getIdTypeOfEvent());
    eventEntity.setEventStatus(eventService.checkStatusEvent(dateBegin, dateEnd));
    eventEntity.setTheCurrentNumberOfParticipants(0);
    eventEntity.setIdOrganizer(userService.findByUsername(principal.getName()).getIdUser());
    eventEntity.setEventOrganizer(userService.findByUsername(principal.getName()));

    Set<ImageEntity> imageEntityList = new HashSet<>();

    byte fileBytes[];
    FileOutputStream fos = null;
    List<MultipartFile> list = uploadForm.getFiles();
    Set<String> filenames = new HashSet<>();
    if (list != null && list.size() > 0) {
      for (MultipartFile multipartFile : list) {
        String fileName = multipartFile.getOriginalFilename();

        String webappRoot = servletContext.getRealPath("/");
        String relativeFolder =
            "/resources" + File.separator + "img" + File.separator + "files" + File.separator;
        String path = webappRoot + relativeFolder + fileName;

        if (checkFormatFileUtils.checkingForImage(fileName)) {
          ImageEntity imageEntity = new ImageEntity();
          imageEntity.setIdImage(Utils.generateIdentifier());
          imageEntity.setPathToTheFileSystem(relativeFolder + fileName);
          imageEntityList.add(imageEntity);
        }
        File file = new File(path);

        try {

          fos = new FileOutputStream(file);
          fileBytes = multipartFile.getBytes();
          fos.write(fileBytes);
          filenames.add(fileName);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }

    /*newsEntity.setNewsDocuments(documentEntities);*/
    eventEntity.setEventImages(imageEntityList);

    eventService.save(eventEntity);
    modelMap.addAttribute("textPage", ActionMessage.SUCCESS_EVENT_REGISTER);
    return "pages/general/success-template-page";
  }