public void testBeanValidation() throws Exception {
    Artist a = new Artist();
    a.setName("TOO OLD ARTIST");
    a.setAge(120);

    XPersistence.getManager().persist(a);
    try {
      XPersistence.commit();
    } catch (RollbackException ex) {

      if (ex.getCause() instanceof javax.validation.ConstraintViolationException) {
        javax.validation.ConstraintViolationException vex =
            (javax.validation.ConstraintViolationException) ex.getCause();
        assertEquals("1 invalid value is expected", 1, vex.getConstraintViolations().size());
        ConstraintViolation violation = vex.getConstraintViolations().iterator().next();
        assertEquals("Bean", "Artist", violation.getRootBeanClass().getSimpleName());
        String expectedMessage =
            "es".equals(Locale.getDefault().getLanguage())
                ? "tiene que ser menor o igual que 90"
                : "must be less than or equal to 90";
        assertEquals("Message text", expectedMessage, violation.getMessage());
        return;
      }
    }
    fail("A constraint violation exception should be thrown");
  }
Example #2
0
 public void loadDataArtist(String path) {
   allArtists = new HashMap<Integer, Artist>();
   List<String> data = loadData(path);
   for (String str : data) {
     int artistId = Integer.parseInt(str);
     Artist artist = new Artist();
     artist.setId(artistId);
     allArtists.put(artistId, artist);
   }
 }
Example #3
0
  public void loadDataTrack(String path) {

    allTracks = new HashMap<Integer, Track>();
    List<String> data = loadData(path);
    for (String str : data) {
      Track track = new Track();
      String[] strArray = str.split("\\|");
      int trackId = Integer.parseInt(strArray[0]);
      int trackAlbum = -1; // -1 means none
      int trackArtist = -1;
      List<Integer> trackGenres = new LinkedList<Integer>();
      if (!strArray[1].equals("None")) {
        trackAlbum = Integer.parseInt(strArray[1]);
        if (allAlbums.containsKey(trackAlbum)) {
          Album album = allAlbums.get(trackAlbum);
          List<Integer> tracksInList = album.getTracks();
          tracksInList.add(trackId);
          album.setTracks(tracksInList);
          allAlbums.put(trackAlbum, album);
        }
      }
      if (!strArray[2].equals("None")) {
        trackArtist = Integer.parseInt(strArray[2]);
        if (allArtists.containsKey(trackArtist)) {
          Artist artist = allArtists.get(trackArtist);
          List<Integer> tracksInList = artist.getTracks();
          tracksInList.add(trackId);
          artist.setTracks(tracksInList);
          allArtists.put(trackArtist, artist);
        }
      }
      if (strArray.length > 3) {
        for (int i = 0; i < strArray.length - 3; i++) {
          int trackGenre = Integer.parseInt(strArray[i + 3]);
          trackGenres.add(trackGenre);
          if (allGenres.containsKey(trackGenre)) {
            Genre genre = allGenres.get(trackGenre);
            List<Integer> tracksInList = genre.getTracks();
            tracksInList.add(trackId);
            genre.setTracks(tracksInList);
            allGenres.put(trackGenre, genre);
          }
        }
      } else {
        trackGenres.add(-1);
      }
      track.setId(trackId);
      track.setAlbumId(trackAlbum);
      track.setArtistId(trackArtist);
      track.setGenreId(trackGenres);
      allTracks.put(trackId, track);
    }
  }
  private void reload() {
    UltimateFestivalOrganizerSoap ufo = UFOService.getInstance();

    venues = ufo.getAllVenues().getVenue();
    artists = ufo.getAllButDeletedArtists().getArtist();

    // Performances
    performances.clear();

    if (performancesSessionBean.getSelectedDate() == null) {
      return;
    }

    // fill with new
    for (Venue v : venues) {
      performances.put(v.getId(), new HashMap<>());

      for (int hour = 14; hour <= 23; ++hour) {
        Performance p = new Performance();
        p.setVenue(v);

        Calendar c = new GregorianCalendar();
        c.setTime(performancesSessionBean.getSelectedDate());
        c.add(Calendar.HOUR_OF_DAY, hour);
        p.setDateTime(dateToGregorian(c.getTime()));

        Artist a = new Artist();
        a.setId(0);
        p.setArtist(a);

        performances.get(v.getId()).put(hour, p);
      }
    }

    // fill with existing
    List<Performance> allPerformances =
        ufo.getPerformancesByDate(dateToGregorian(performancesSessionBean.getSelectedDate()))
            .getPerformance();
    for (Performance p : allPerformances) {
      int venueId = p.getVenue().getId();
      int hour = p.getDateTime().getHour();

      performances.get(venueId).put(hour, p);
    }
  }