private static void deleteRootComponent(String rootUuid, PurgeMapper mapper, PurgeCommands commands) { List<IdUuidPair> rootAndModulesOrSubviews = mapper.selectRootAndModulesOrSubviewsByProjectUuid(rootUuid); long rootId = rootAndModulesOrSubviews.stream() .filter(pair -> pair.getUuid().equals(rootUuid)) .map(IdUuidPair::getId) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Couldn't find root component with uuid " + rootUuid)); commands.deletePermissions(rootId); commands.deleteLinks(rootUuid); commands.deleteAnalyses(rootUuid); commands.deleteByRootAndModulesOrSubviews(rootAndModulesOrSubviews); commands.deleteComponents(rootUuid); commands.deleteIssues(rootUuid); commands.deleteFileSources(rootUuid); commands.deleteCeActivity(rootUuid); commands.deleteCeQueue(rootUuid); commands.deleteWebhooks(rootUuid); commands.deleteWebhookDeliveries(rootUuid); commands.deleteProjectMappings(rootUuid); commands.deleteProjectAlmBindings(rootUuid); commands.deleteBranch(rootUuid); commands.deleteLiveMeasures(rootUuid); }
@Test public void shouldDeleteIssuesAndIssueChanges() { dbTester.prepareDbUnit(getClass(), "shouldDeleteResource.xml"); PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler); purgeCommands.deleteIssues("uuid_1"); assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(1); assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1); assertThat(dbTester.countRowsOfTable("events")).isEqualTo(3); assertThat(dbTester.countRowsOfTable("issues")).isZero(); assertThat(dbTester.countRowsOfTable("issue_changes")).isZero(); }