@Test public void updateRiver() { River river = riverDao.findById(2L); river.setRiverName("updated river name"); river.setDescription("updated description"); river.setRiverPublic(true); riverDao.update(river); em.flush(); String sql = "SELECT river_name, river_name_canonical, description, river_public FROM rivers WHERE id = ?"; Map<String, Object> results = this.jdbcTemplate.queryForMap(sql, 2); assertEquals("updated river name", (String) results.get("river_name")); assertEquals( TextUtil.getURLSlug("updated river name"), (String) results.get("river_name_canonical")); assertEquals("updated description", (String) results.get("description")); assertEquals(true, results.get("river_public")); }
@Test public void testCreateRiver() { River river = new River(); Account account = accountDao.findByUsernameOrEmail("user1"); river.setRiverName("Test river"); river.setDescription("test description"); river.setAccount(account); river.setRiverPublic(false); riverDao.create(river); assertNotNull(river.getId()); String sql = "SELECT account_id, river_name, description, river_public, river_name_canonical FROM rivers WHERE id = ?"; Map<String, Object> results = this.jdbcTemplate.queryForMap(sql, river.getId()); assertEquals("Test river", (String) results.get("river_name")); assertEquals(3L, ((Number) results.get("account_id")).longValue()); assertEquals(TextUtil.getURLSlug("Test river"), (String) results.get("river_name_canonical")); assertEquals("test description", (String) results.get("description")); assertEquals(false, results.get("river_public")); }
@Test public void findByName() { River r = riverDao.findByName("Private River 1"); assertEquals(2, (long) r.getId()); }
@Test public void findById() { River r = riverDao.findById(1L); assertEquals("Public River 1", r.getRiverName()); }