Пример #1
0
 /**
  * Test method for.
  *
  * <p>{@link org.jajuk.services.dj.AmbienceManager#update(org.jajuk.events.JajukEvent)} .
  */
 public final void testUpdate() {
   Properties prop = new Properties();
   Genre genre1 = GenreManager.getInstance().registerGenre("genre1");
   Genre genre2 = GenreManager.getInstance().registerGenre("genre2");
   Ambience ambience = new Ambience("23", "testamb", new String[] {"genre1"});
   prop.put(Const.DETAIL_OLD, genre1);
   prop.put(Const.DETAIL_NEW, genre2);
   AmbienceManager.getInstance().registerAmbience(ambience);
   AmbienceManager.getInstance().update(new JajukEvent(JajukEvents.GENRE_NAME_CHANGED, prop));
   assertEquals(1, AmbienceManager.getInstance().getAmbiences().size());
   assertEquals(
       1, AmbienceManager.getInstance().getAmbiences().iterator().next().getGenres().size());
   assertEquals(
       "genre2",
       AmbienceManager.getInstance()
           .getAmbiences()
           .iterator()
           .next()
           .getGenres()
           .iterator()
           .next()
           .getName());
 }
Пример #2
0
 /**
  * Test method for {@link org.jajuk.services.dj.AmbienceManager#load()}.
  *
  * @throws Exception the exception
  */
 public final void testLoad() throws Exception {
   // make sure "UpgradeManager.bFirstSession" is not set
   {
     Class<?> c = UpgradeManager.class;
     Field f = c.getDeclaredField("firstSession");
     f.setAccessible(true);
     f.setBoolean(null, Boolean.FALSE);
   }
   assertFalse(UpgradeManager.isFirstSession());
   assertEquals(0, AmbienceManager.getInstance().getAmbiences().size());
   // first without any key
   AmbienceManager.getInstance().load();
   // creates the 14 default ambiences
   assertEquals(14, AmbienceManager.getInstance().getAmbiences().size());
   // clean out all leftover ambiences from other testing
   for (Ambience amb : AmbienceManager.getInstance().getAmbiences()) {
     AmbienceManager.getInstance().removeAmbience(amb.getID());
   }
   assertEquals(0, AmbienceManager.getInstance().getAmbiences().size());
   { // remove all leftover properties
     Properties properties = Conf.getProperties();
     Enumeration<Object> e = properties.keys();
     while (e.hasMoreElements()) {
       String sKey = (String) e.nextElement();
       if (sKey.matches(Const.AMBIENCE_PREFIX + ".*")) {
         properties.remove(sKey);
       }
     }
   }
   // then add set some Ambience-items
   Genre genre1 = GenreManager.getInstance().registerGenre("genre1");
   Genre genre2 = GenreManager.getInstance().registerGenre("genre2");
   Conf.setProperty(
       Const.AMBIENCE_PREFIX + "12/myambience", genre1.getID() + "," + genre2.getID());
   assertEquals(0, AmbienceManager.getInstance().getAmbiences().size());
   { // check all the conditions to find out why it fails in Hudson
     assertFalse(UpgradeManager.isFirstSession());
     Properties properties = Conf.getProperties();
     Enumeration<Object> e = properties.keys();
     int nMatch = 0;
     while (e.hasMoreElements()) {
       String sKey = (String) e.nextElement();
       if (sKey.matches(Const.AMBIENCE_PREFIX + ".*")) {
         if (sKey.substring(Const.AMBIENCE_PREFIX.length()).indexOf('/') == -1) {
           continue;
         }
         nMatch++;
       }
     }
     assertEquals(properties.toString(), 1, nMatch);
   }
   AmbienceManager.getInstance().load();
   assertEquals(1, AmbienceManager.getInstance().getAmbiences().size());
   assertNotNull(AmbienceManager.getInstance().getAmbience("12"));
   // now test with an ambience with invalid format, i.e. only "12", not
   // "12/name"
   for (Ambience amb : AmbienceManager.getInstance().getAmbiences()) {
     AmbienceManager.getInstance().removeAmbience(amb.getID());
   }
   assertEquals(0, AmbienceManager.getInstance().getAmbiences().size());
   Conf.setProperty(Const.AMBIENCE_PREFIX + "12", genre1.getID() + "," + genre2.getID());
   Conf.removeProperty(Const.AMBIENCE_PREFIX + "12/myambience");
   AmbienceManager.getInstance().load();
   // now 14 as this could not be loaded and thus the default ones were
   // loaded...
   assertEquals(14, AmbienceManager.getInstance().getAmbiences().size());
   UpgradeManager.setFirstSession();
   AmbienceManager.getInstance().load();
 }