예제 #1
0
  @Test
  public void testInsert() throws Exception {
    Fight fight =
        new Fight(
            UUID.fromString("df40ccf7-6fd8-4c13-8eef-7742a87a55b0"),
            BasicScenario.Player1.PLAYER.getId(),
            BasicScenario.Player2.PLAYER.getId(),
            BasicScenario.Player2.Planet1.PLANET.getId(),
            new Ships(new Ship(ShipType.MOSQUITO, 5), new Ship(ShipType.MULE, 1)),
            new Ships(new Ship(ShipType.DAEDALUS, 1)),
            new Ships(new Ship(ShipType.MOSQUITO, 1)),
            new Ships(new Ship(ShipType.DAEDALUS, 1)),
            10,
            new Resources(10, 20, 0));
    sut.insert(fight);

    List<Map<String, Object>> fightRows = select("SELECT * FROM fight WHERE id = ?", fight.getId());
    List<Map<String, Object>> fightShipsRows =
        select("SELECT * FROM fight_ships WHERE fight_id = ?", fight.getId());

    assertThat(fightRows, hasSize(1));
    verifyFightRow(fightRows.get(0), fight);

    assertThat(fightShipsRows, hasSize(5));
    verifyFightShipsRows(fightShipsRows, fight);
  }
예제 #2
0
  @Test
  public void testFindWithId() throws Exception {
    Fight expected = FightScenario.Player1.FIGHT;
    Optional<FightWithPlanetAndPlayer> fight = sut.findWithId(expected.getId());

    assertThat(fight.isPresent(), is(true));
    assertThat(
        fight.get(),
        is(
            new FightWithPlanetAndPlayer(
                expected,
                BasicScenario.Player2.Planet1.PLANET,
                BasicScenario.Player1.PLAYER,
                BasicScenario.Player2.PLAYER)));
  }
예제 #3
0
 private boolean matchFightShipsRow(
     Fight fight, Ship ship, Map<String, Object> row, int category) {
   return row.get("fight_id").equals(fight.getId())
       && row.get("category").equals(category)
       && row.get("type").equals(ship.getType().getId())
       && row.get("amount").equals(ship.getAmount());
 }
예제 #4
0
  @Test
  public void testFindFightsWithPlayerSinceRound() throws Exception {
    Fight expected = FightScenario.Player1.FIGHT;
    // Find for attacker
    List<FightWithPlanetAndPlayer> fight =
        sut.findFightsWithPlayerSinceRound(expected.getAttackerId(), expected.getRound());

    assertThat(fight, hasSize(1));
    assertThat(
        fight.get(0),
        is(
            new FightWithPlanetAndPlayer(
                expected,
                BasicScenario.Player2.Planet1.PLANET,
                BasicScenario.Player1.PLAYER,
                BasicScenario.Player2.PLAYER)));
  }
예제 #5
0
  private void verifyFightShipsRows(List<Map<String, Object>> rows, Fight fight) {
    for (Ship ship : fight.getAttackingShips()) {
      assertThat(rows.stream().anyMatch(r -> matchFightShipsRow(fight, ship, r, 0)), is(true));
    }

    for (Ship ship : fight.getDefendingShips()) {
      assertThat(rows.stream().anyMatch(r -> matchFightShipsRow(fight, ship, r, 1)), is(true));
    }

    for (Ship ship : fight.getRemainingAttackerShips()) {
      assertThat(rows.stream().anyMatch(r -> matchFightShipsRow(fight, ship, r, 2)), is(true));
    }

    for (Ship ship : fight.getRemainingDefenderShips()) {
      assertThat(rows.stream().anyMatch(r -> matchFightShipsRow(fight, ship, r, 3)), is(true));
    }
  }
예제 #6
0
 private void verifyFightRow(Map<String, Object> row, Fight fight) {
   assertThat(row.get("id"), is(fight.getId()));
   assertThat(row.get("attacker_id"), is(fight.getAttackerId()));
   assertThat(row.get("defender_id"), is(fight.getDefenderId()));
   assertThat(row.get("planet_id"), is(fight.getPlanetId()));
   assertThat(row.get("round"), is(fight.getRound()));
   assertThat(row.get("crystals_looted"), is(fight.getLoot().getCrystals()));
   assertThat(row.get("gas_looted"), is(fight.getLoot().getGas()));
 }