@Test public void description_url_avatarUrl_and_userId_are_optional() { when(system2.now()).thenReturn(SOME_DATE); insertOrganization(copyOf(ORGANIZATION_DTO_1).setDescription(null).setUrl(null).setAvatarUrl(null)); Map<String, Object> row = selectSingleRow(); assertThat(row.get("uuid")).isEqualTo(ORGANIZATION_DTO_1.getUuid()); assertThat(row.get("key")).isEqualTo(ORGANIZATION_DTO_1.getKey()); assertThat(row.get("name")).isEqualTo(ORGANIZATION_DTO_1.getName()); assertThat(row.get("description")).isNull(); assertThat(row.get("url")).isNull(); assertThat(row.get("avatarUrl")).isNull(); assertThat(row.get("guarded")).isEqualTo(toBool(ORGANIZATION_DTO_1.isGuarded())); assertThat(row.get("userId")).isNull(); assertThat(row.get("createdAt")).isEqualTo(SOME_DATE); assertThat(row.get("updatedAt")).isEqualTo(SOME_DATE); assertThat(row.get("defaultTemplate")).isNull(); assertThat(row.get("projectDefaultTemplate")).isNull(); assertThat(row.get("viewDefaultTemplate")).isNull(); }
@Test public void countByQuery() { insertOrganization(copyOf(ORGANIZATION_DTO_1).setUuid("uuid3").setKey("key-3")); insertOrganization(copyOf(ORGANIZATION_DTO_1).setUuid("uuid1").setKey("key-1")); insertOrganization(copyOf(ORGANIZATION_DTO_1).setUuid("uuid2").setKey("key-2")); insertOrganization(copyOf(ORGANIZATION_DTO_1).setUuid("uuid5").setKey("key-5")); insertOrganization(copyOf(ORGANIZATION_DTO_1).setUuid("uuid4").setKey("key-4")); assertThat(underTest.countByQuery(dbSession, returnAll())).isEqualTo(5); assertThat(underTest.countByQuery(dbSession, newQueryWithKeys("key-1", "key-2"))).isEqualTo(2); assertThat(underTest.countByQuery(dbSession, newQueryWithKeys("unknown"))).isZero(); }
@Test public void deleteByUuid_deletes_row_with_specified_uuid() { insertOrganization(ORGANIZATION_DTO_1); String anotherUuid = "uuid"; insertOrganization(copyOf(ORGANIZATION_DTO_1).setUuid(anotherUuid).setKey("key")); assertThat(db.countRowsOfTable("organizations")).isEqualTo(2); assertThat(underTest.deleteByUuid(dbSession, anotherUuid)).isEqualTo(1); dbSession.commit(); assertThat(underTest.selectByUuid(dbSession, anotherUuid)).isEmpty(); assertThat(underTest.selectByUuid(dbSession, ORGANIZATION_DTO_1.getUuid())).isNotEmpty(); assertThat(db.countRowsOfTable("organizations")).isEqualTo(1); assertThat(underTest.deleteByUuid(dbSession, anotherUuid)).isEqualTo(0); assertThat(underTest.deleteByUuid(dbSession, ORGANIZATION_DTO_1.getUuid())).isEqualTo(1); dbSession.commit(); assertThat(underTest.selectByUuid(dbSession, ORGANIZATION_DTO_1.getUuid())).isEmpty(); assertThat(db.countRowsOfTable("organizations")).isEqualTo(0); }
@Test public void update_fails_if_name_is_null() { insertOrganization(ORGANIZATION_DTO_1); expectedException.expect(PersistenceException.class); underTest.update(dbSession, copyOf(ORGANIZATION_DTO_1).setName(null)); }