@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); }
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()); }
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())); }
@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))); }