@Test public void selectByUuids_returns_empty_when_no_uuid_exist() { insertOrganization(ORGANIZATION_DTO_1); insertOrganization(ORGANIZATION_DTO_2); assertThat(underTest.selectByUuids(dbSession, of("foo uuid", "bar uuid"))) .isEmpty(); }
@Test public void selectByUuids_returns_empty_when_no_single_uuid_exist() { insertOrganization(ORGANIZATION_DTO_1); insertOrganization(ORGANIZATION_DTO_2); assertThat(underTest.selectByUuids(dbSession, of("foo uuid"))) .isEmpty(); }
@Test public void selectByUuids_is_case_sensitive() { insertOrganization(ORGANIZATION_DTO_1); insertOrganization(ORGANIZATION_DTO_2); assertThat(underTest.selectByUuids( dbSession, of(ORGANIZATION_DTO_1.getUuid().toUpperCase(Locale.ENGLISH), ORGANIZATION_DTO_2.getUuid().toUpperCase(Locale.ENGLISH)))) .isEmpty(); }
@Test public void deleteByUuid_does_not_fail_on_non_existing_row() { insertOrganization(ORGANIZATION_DTO_1); assertThat(underTest.deleteByUuid(dbSession, "uuid")).isEqualTo(0); dbSession.commit(); }
@Test public void selectByQuery_with_only_non_existent_keys_returns_empty() { insertOrganization(ORGANIZATION_DTO_1); insertOrganization(ORGANIZATION_DTO_2); OrganizationQuery organizationQuery = newQueryWithKeys(PERMISSION_1, PERMISSION_2, "dog"); assertThat(underTest.selectByQuery(dbSession, organizationQuery, forPage(1).andSize(10))) .isEmpty(); }
@Test public void insert_persists_boolean_property_guarded_of_OrganizationDto() { insertOrganization(ORGANIZATION_DTO_2); Map<String, Object> row = selectSingleRow(); assertThat(row.get("guarded")).isEqualTo(toBool(ORGANIZATION_DTO_2.isGuarded())); }
@Test public void selectByUuid_returns_row_data_of_specified_uuid() { insertOrganization(ORGANIZATION_DTO_1); assertThat(underTest.selectByUuid(dbSession, "foo uuid")).isEmpty(); }
@Test public void selectByQuery_with_keys_returns_empty_on_table_with_single_row_when_not_requesting_the_first_page() { insertOrganization(ORGANIZATION_DTO_1); insertOrganization(ORGANIZATION_DTO_2); OrganizationQuery organizationQuery = newQueryWithKeys(ORGANIZATION_DTO_1.getKey(), ORGANIZATION_DTO_2.getKey()); assertThat(underTest.selectByQuery(dbSession, organizationQuery, forPage(2).andSize(2))).isEmpty(); assertThat(underTest.selectByQuery(dbSession, organizationQuery, forPage(Math.abs(new Random().nextInt(10)) + 3).andSize(1))).isEmpty(); assertThat(underTest.selectByQuery(dbSession, organizationQuery, forPage(3).andSize(10))).isEmpty(); }
@Test public void getDefaultTemplates_returns_empty_when_row_exists_but_all_default_templates_columns_are_null() { insertOrganization(ORGANIZATION_DTO_1); assertThat(underTest.getDefaultTemplates(dbSession, ORGANIZATION_DTO_1.getUuid())).isEmpty(); }
@Test public void getDefaultTemplates_returns_data_when_project_and_view_default_template_column_are_not_null() { insertOrganization(ORGANIZATION_DTO_1); setDefaultTemplate(ORGANIZATION_DTO_1, PERMISSION_1, PERMISSION_2); verifyGetDefaultTemplates(ORGANIZATION_DTO_1, PERMISSION_1, PERMISSION_2); }
@Test public void selectByQuery_returns_empty_on_table_with_single_row_when_not_requesting_the_first_page() { insertOrganization(ORGANIZATION_DTO_1); assertThat(underTest.selectByQuery(dbSession, returnAll(), forPage(2).andSize(1))).isEmpty(); assertThat(underTest.selectByQuery(dbSession, returnAll(), forPage(Math.abs(new Random().nextInt(10)) + 2).andSize(1))).isEmpty(); assertThat(underTest.selectByQuery(dbSession, returnAll(), forPage(2).andSize(10))).isEmpty(); }
@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 getDefaultGroupId_returns_data_when_default_group_id_is_not_null() { when(system2.now()).thenReturn(DATE_3); insertOrganization(ORGANIZATION_DTO_1); underTest.setDefaultGroupId(dbSession, ORGANIZATION_DTO_1.getUuid(), GroupTesting.newGroupDto().setId(10)); Optional<Integer> optional = underTest.getDefaultGroupId(dbSession, ORGANIZATION_DTO_1.getUuid()); assertThat(optional).isNotEmpty(); assertThat(optional.get()).isEqualTo(10); verifyOrganizationUpdatedAt(ORGANIZATION_DTO_1.getUuid(), DATE_3); }
@Test public void getDefaultGroupId_returns_empty_when_default_group_id_is_null() { insertOrganization(ORGANIZATION_DTO_1.setDefaultGroupId(null)); assertThat(underTest.getDefaultGroupId(dbSession, ORGANIZATION_DTO_1.getUuid())).isEmpty(); }
@Test public void selectByKey_returns_row_data_when_key_exists() { OrganizationDto organizationDto = newOrganizationDto(); insertOrganization(organizationDto); Optional<OrganizationDto> optional = underTest.selectByKey(dbSession, organizationDto.getKey()); verifyOrganization(optional.get(), organizationDto); }
@Test public void selectByQuery_with_keys_returns_single_row_of_table_when_requesting_first_page_of_size_1_or_more() { insertOrganization(ORGANIZATION_DTO_1); insertOrganization(ORGANIZATION_DTO_2); OrganizationQuery organizationQuery = newQueryWithKeys(ORGANIZATION_DTO_1.getKey(), ORGANIZATION_DTO_2.getKey()); assertThat(underTest.selectByQuery(dbSession, organizationQuery, forPage(1).andSize(1))) .hasSize(1); assertThat(underTest.selectByQuery(dbSession, organizationQuery, forPage(1).andSize(10))) .hasSize(2) .extracting(OrganizationDto::getUuid) .containsOnly(ORGANIZATION_DTO_1.getUuid(), ORGANIZATION_DTO_2.getUuid()); }
@Test public void selectByQuery_with_ignores_non_existent_keys() { insertOrganization(ORGANIZATION_DTO_1); insertOrganization(ORGANIZATION_DTO_2); OrganizationQuery organizationQuery = newQueryWithKeys(ORGANIZATION_DTO_1.getKey(), PERMISSION_1, ORGANIZATION_DTO_2.getKey(), PERMISSION_2, "dog"); assertThat(underTest.selectByQuery(dbSession, organizationQuery, forPage(1).andSize(10))) .hasSize(2) .extracting(OrganizationDto::getUuid) .containsOnly(ORGANIZATION_DTO_1.getUuid(), ORGANIZATION_DTO_2.getUuid()); }
@Test public void selectByQuery_with_empty_list_of_keys_returns_all() { insertOrganization(ORGANIZATION_DTO_1); insertOrganization(ORGANIZATION_DTO_2); OrganizationQuery organizationQuery = newOrganizationQueryBuilder().setKeys(Lists.emptyList()).build(); assertThat(underTest.selectByQuery(dbSession, organizationQuery, forPage(1).andSize(10))) .extracting(OrganizationDto::getUuid) .containsOnly(ORGANIZATION_DTO_1.getUuid(), ORGANIZATION_DTO_2.getUuid()); }
@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)); }
@Test public void getDefaultTemplates_returns_data_when_project_default_templates_column_is_not_null() { insertOrganization(ORGANIZATION_DTO_1); underTest.setDefaultTemplates(dbSession, ORGANIZATION_DTO_1.getUuid(), new DefaultTemplates().setProjectUuid(PERMISSION_1)); verifyGetDefaultTemplates(ORGANIZATION_DTO_1, PERMISSION_1, null); }