private void assertThatIndexContainsOnly(ComponentDto... expectedComponents) { assertThat(es.getIds(INDEX_TYPE_COMPONENT)).containsExactlyInAnyOrder( Arrays.stream(expectedComponents).map(ComponentDto::uuid).toArray(String[]::new)); }
private void assertThatIndexContainsOnly(SnapshotDto... expectedProjects) { assertThat(es.getIds(INDEX_TYPE_PROJECT_MEASURES)).containsExactlyInAnyOrder( Arrays.stream(expectedProjects).map(SnapshotDto::getComponentUuid).toArray(String[]::new)); }
private void assertThatIndexContainsOnly(ComponentDto... expectedProjects) { assertThat(es.getIds(INDEX_TYPE_PROJECT_MEASURES)).containsExactlyInAnyOrder( Arrays.stream(expectedProjects).map(ComponentDto::uuid).toArray(String[]::new)); }
private void verifyOnlyIndexed(ActiveRuleDto... expected) { List<String> docs = es.getIds(INDEX_TYPE_ACTIVE_RULE); assertThat(docs).hasSize(expected.length); for (ActiveRuleDto activeRuleDto : expected) { assertThat(docs).contains(activeRuleDto.getId().toString()); } }
@Test public void mass_insert() { execute(new BigRepository()); assertThat(db.countRowsOfTable("rules")).isEqualTo(BigRepository.SIZE); assertThat(db.countRowsOfTable("rules_parameters")).isEqualTo(BigRepository.SIZE * 20); assertThat(es.getIds(RuleIndexDefinition.INDEX_TYPE_RULE)).hasSize(BigRepository.SIZE); }
RuleDto rule2 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, RULE_KEY2); RuleDto hotspotRule = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, HOTSPOT_RULE_KEY); assertThat(es.getIds(RuleIndexDefinition.INDEX_TYPE_RULE)).containsOnly(valueOf(rule1.getId()), valueOf(rule2.getId()), valueOf(hotspotRule.getId()));
@Test public void update_user_and_index_other_user() { createDefaultGroup(); UserDto user = db.users().insertUser(newLocalUser(DEFAULT_LOGIN, "Marius", "marius@email.com") .setScmAccounts(asList("ma", "marius33"))); UserDto otherUser = db.users().insertUser(); underTest.updateAndCommit(session, user, new UpdateUser() .setName("Marius2") .setEmail("marius2@mail.com") .setPassword("password2") .setScmAccounts(asList("ma2")), u -> { }, otherUser); assertThat(es.getIds(UserIndexDefinition.INDEX_TYPE_USER)).containsExactlyInAnyOrder(user.getUuid(), otherUser.getUuid()); }
@Test public void do_not_update_already_removed_rules() { execute(new FakeRepositoryV1()); assertThat(dbClient.ruleDao().selectAllDefinitions(db.getSession())).hasSize(3); RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, RULE_KEY1); RuleDto rule2 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, RULE_KEY2); RuleDto hotspotRule = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, HOTSPOT_RULE_KEY); assertThat(es.getIds(RuleIndexDefinition.INDEX_TYPE_RULE)).containsOnly(valueOf(rule1.getId()), valueOf(rule2.getId()), valueOf(hotspotRule.getId())); assertThat(rule2.getStatus()).isEqualTo(READY); when(system.now()).thenReturn(DATE2.getTime()); execute(new FakeRepositoryV2()); // On MySQL, need to update a rule otherwise rule2 will be seen as READY, but why ??? dbClient.ruleDao().update(db.getSession(), rule1.getDefinition()); db.getSession().commit(); // rule2 is removed rule2 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, RULE_KEY2); RuleDto rule3 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, RULE_KEY3); assertThat(rule2.getStatus()).isEqualTo(REMOVED); assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getIds()).containsOnly(rule1.getId(), rule3.getId()); when(system.now()).thenReturn(DATE3.getTime()); execute(new FakeRepositoryV2()); db.getSession().commit(); // -> rule2 is still removed, but not update at DATE3 rule2 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), defaultOrganization, RULE_KEY2); assertThat(rule2.getStatus()).isEqualTo(REMOVED); assertThat(rule2.getUpdatedAt()).isEqualTo(DATE2.getTime()); assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getIds()).containsOnly(rule1.getId(), rule3.getId()); }
@Test public void create_user_and_index_other_user() { createDefaultGroup(); UserDto otherUser = db.users().insertUser(); UserDto created = underTest.createAndCommit(db.getSession(), NewUser.builder() .setLogin("user") .setName("User") .setEmail("user@mail.com") .setPassword("PASSWORD") .build(), u -> { }, otherUser); assertThat(es.getIds(UserIndexDefinition.INDEX_TYPE_USER)).containsExactlyInAnyOrder(created.getUuid(), otherUser.getUuid()); }
@Test public void delete_rule_extension_from_index_when_setting_rule_tags_to_empty() { RuleDefinitionDto rule = dbTester.rules().insert(r -> r.setRuleKey(RuleTesting.randomRuleKeyOfMaximumLength())); underTest.commitAndIndex(dbTester.getSession(), rule.getId()); OrganizationDto organization = dbTester.organizations().insert(); RuleMetadataDto metadata = RuleTesting.newRuleMetadata(rule, organization).setTags(ImmutableSet.of("bla")); dbTester.getDbClient().ruleDao().insertOrUpdate(dbTester.getSession(), metadata); underTest.commitAndIndex(dbTester.getSession(), rule.getId(), organization); // index tags RuleExtensionDoc doc = new RuleExtensionDoc() .setRuleId(rule.getId()) .setScope(RuleExtensionScope.organization(organization.getUuid())); assertThat(es.getIds(RuleIndexDefinition.INDEX_TYPE_RULE_EXTENSION)).contains(doc.getId()); // update db table "rules_metadata" with empty tags and delete tags from index metadata = RuleTesting.newRuleMetadata(rule, organization).setTags(emptySet()); dbTester.getDbClient().ruleDao().insertOrUpdate(dbTester.getSession(), metadata); underTest.commitAndIndex(dbTester.getSession(), rule.getId(), organization); assertThat(es.getIds(RuleIndexDefinition.INDEX_TYPE_RULE_EXTENSION)).doesNotContain(doc.getId()); }