Example #1
0
  @Override
  public String ask(Tweet question) throws TwitterException {

    String nomPokeKO = question.getScreenName();
    String tweet = question.getText();
    final int expbase = 200;

    if (tweet.contains("#KO")) {

      DAOCombat dao = DAOFactoryJPA.createDAOCombat();

      EntityManager em = DAOFactoryJPA.getEntityManager();

      List<Combat> combats = dao.findByPoke(em.find(Pokemon.class, nomPokeKO));
      Combat combatCourant = combats.get(combats.size() - 1);

      combatCourant.setLoser(nomPokeKO);

      Pokemon pokeWin = dao.findWinner(combatCourant.getNumCombat());
      combatCourant.setWinner(pokeWin.getNomP());

      dao.update(combatCourant);

      Pokemon poke = em.find(Pokemon.class, pokeWin.getNomP());

      int level = poke.getLvl();

      int exp = expbase * level / SET_XP;

      exp = poke.getXp() + exp;

      em.getTransaction().begin();

      poke.setXp(exp);

      em.persist(poke);

      em.getTransaction().commit();

      return "@" + pokeWin.getNomP() + " #Win +" + exp + "xp" + " #PokeBattle";
    }

    return null;
  }
  @BeforeClass
  public static void initTestFixture() throws Exception {
    entityManagerFactory = Persistence.createEntityManagerFactory("pokebattlePUTest");
    em = entityManagerFactory.createEntityManager();
    DAOFactoryJPA.setEntityManager(em);
    // ... suite des initialisations pour les tests
    Connection connection =
        ((EntityManagerImpl) (em.getDelegate())).getServerSession().getAccessor().getConnection();

    dbUnitConnection = new DatabaseConnection(connection);
    // Loads the data set from a file
    dataset =
        new FlatXmlDataSetBuilder()
            .build(
                Thread.currentThread()
                    .getContextClassLoader()
                    .getResourceAsStream("pokemonDataset.xml"));
  }