private void verifyOrganization1(Optional<OrganizationDto> optional) { assertThat(optional).isNotEmpty(); verifyOrganization1(optional.get()); }
@Test public void get_return_to_parameter() { when(request.getCookies()).thenReturn(new Cookie[] {new Cookie(AUTHENTICATION_COOKIE_NAME, "{\"return_to\":\"/settings\"}")}); Optional<String> redirection = underTest.getReturnTo(request); assertThat(redirection).isNotEmpty(); assertThat(redirection.get()).isEqualTo("/settings"); }
@Test public void get_allowEmailShift_parameter() { when(request.getCookies()).thenReturn(new Cookie[] {new Cookie(AUTHENTICATION_COOKIE_NAME, "{\"allowEmailShift\":\"true\"}")}); Optional<Boolean> allowEmailShift = underTest.getAllowEmailShift(request); assertThat(allowEmailShift).isNotEmpty(); assertThat(allowEmailShift.get()).isTrue(); }
@Test public void getAllowUpdateLogin() { when(request.getCookies()).thenReturn(new Cookie[] {new Cookie(AUTHENTICATION_COOKIE_NAME, "{\"allowUpdateLogin\":\"true\"}")}); Optional<Boolean> allowLoginUpdate = underTest.getAllowUpdateLogin(request); assertThat(allowLoginUpdate).isNotEmpty(); assertThat(allowLoginUpdate.get()).isTrue(); }
private void verifyGetDefaultTemplates(OrganizationDto organizationDto, @Nullable String expectedProject, @Nullable String expectedView) { Optional<DefaultTemplates> optional = underTest.getDefaultTemplates(dbSession, organizationDto.getUuid()); assertThat(optional).isNotEmpty(); DefaultTemplates defaultTemplates = optional.get(); assertThat(defaultTemplates.getProjectUuid()).isEqualTo(expectedProject); assertThat(defaultTemplates.getApplicationsUuid()).isEqualTo(expectedView); }
@Test public void should_have_empty_branch_purge_date() { PurgeConfiguration conf = new PurgeConfiguration(new IdUuidPair(1L, "1"), emptyList(), 30, Optional.of(10), System2.INSTANCE, emptyList()); assertThat(conf.maxLiveDateOfInactiveShortLivingBranches()).isNotEmpty(); long tenDaysAgo = DateUtils.addDays(new Date(System2.INSTANCE.now()), -10).getTime(); assertThat(conf.maxLiveDateOfInactiveShortLivingBranches().get().getTime()).isBetween(tenDaysAgo - 5000, tenDaysAgo + 5000); }
@Test public void translate_offset_for_each_line() { Component component = createComponent(1); List<ScannerReport.LineSgnificantCode> significantCode = new ArrayList<>(); significantCode.add(createLineSignificantCode(1, 1, 2)); reportReader.putSignificantCode(component.getReportAttributes().getRef(), significantCode); assertThat(underTest.getRangesPerLine(component)).isNotEmpty(); LineRange[] lines = underTest.getRangesPerLine(component).get(); assertThat(lines).hasSize(1); assertThat(lines[0].startOffset()).isEqualTo(1); assertThat(lines[0].endOffset()).isEqualTo(2); }
@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 mark_all_non_existing_index_types_as_uninitialized() { startNewCreator(context -> { NewIndex i = context.create("fakes", SETTINGS_CONFIGURATION); i.createType("t1"); i.createType("t2"); }); assertThat(metadataIndex.getHash("fakes")).isNotEmpty(); assertThat(metadataIndex.getInitialized(new IndexType("fakes", "t1"))).isFalse(); assertThat(metadataIndex.getInitialized(new IndexType("fakes", "t2"))).isFalse(); }
@Test public void testGetArgumentOfNoneShouldNotBeEmpty() { Optional<Argument> arg = unit.build(new GenericType<Option<Integer>>() {}.getType(), Option.none(), null); assertThat(arg).isNotEmpty(); }
@Test public void testGetLeftEitherArgumentShouldNotBeEmpty() { Optional<Argument> arg = unit.build(new GenericType<Either<String, Integer>>() {}.getType(), Either.left("error"), null); assertThat(arg).isNotEmpty(); }
@Test public void testGetRightEitherArgumentInferredShouldNotBeEmpty() { Optional<Argument> arg = unit.build(new GenericType<Either<?, ?>>() {}.getType(), Either.right(1), null); assertThat(arg).isNotEmpty(); }
@Test public void selectById_return_rule_even_if_organization_does_not_exist() { RuleDefinitionDto ruleDefinition = db.rules().insert(); assertThat(underTest.selectById(ruleDefinition.getId(), "dfdfdf", db.getSession())) .isNotEmpty(); }
@Test public void selectByKey_return_rule_even_if_organization_does_not_exist() { RuleDefinitionDto ruleDefinition = db.rules().insert(); assertThat(underTest.selectByKey(db.getSession(), OrganizationTesting.newOrganizationDto(), ruleDefinition.getKey())) .isNotEmpty(); }
@Test public void selectByComponentUuidAndMetricKey() { LiveMeasureDto measure = newLiveMeasure().setMetricId(metric.getId()); underTest.insert(db.getSession(), measure); Optional<LiveMeasureDto> selected = underTest.selectByComponentUuidAndMetricKey(db.getSession(), measure.getComponentUuid(), metric.getKey()); assertThat(selected).isNotEmpty(); assertThat(selected.get()).isEqualToComparingFieldByField(measure); }
@Test public void submit_with_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_task_without_component_when_there_is_a_pending_task_without_component() { CeTaskSubmit taskSubmit = createTaskSubmit("no_component"); CeQueueDto dto = insertPendingInQueue(null); Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_MAIN_COMPONENT); assertThat(task).isNotEmpty(); assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession())) .extracting(CeQueueDto::getUuid) .containsOnly(dto.getUuid(), task.get().getUuid()); }
@Test public void submit_with_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_task_when_there_is_a_pending_task_for_another_main_component() { String mainComponentUuid = randomAlphabetic(5); String otherMainComponentUuid = randomAlphabetic(6); CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null); CeQueueDto dto = insertPendingInQueue(newComponent(otherMainComponentUuid)); Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_MAIN_COMPONENT); assertThat(task).isNotEmpty(); assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession())) .extracting(CeQueueDto::getUuid) .containsOnly(dto.getUuid(), task.get().getUuid()); }
@Test public void select_first_snapshots() { ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization()); db.getDbClient().componentDao().insert(dbSession, project); db.getDbClient().snapshotDao().insert(dbSession, newAnalysis(project).setCreatedAt(5L), newAnalysis(project).setCreatedAt(2L), newAnalysis(project).setCreatedAt(1L)); dbSession.commit(); Optional<SnapshotDto> dto = underTest.selectOldestSnapshot(dbSession, project.uuid()); assertThat(dto).isNotEmpty(); assertThat(dto.get().getCreatedAt()).isEqualTo(1L); assertThat(underTest.selectOldestSnapshot(dbSession, "blabla")).isEmpty(); }
@Test public void deleteProject_deletes_project_mappings() { ComponentDto project = db.components().insertPublicProject(); dbClient.projectMappingsDao().put(dbSession, "a.key.type", "a.key", project.uuid()); dbClient.projectMappingsDao().put(dbSession, "a.key.type", "another.key", "D2"); underTest.deleteProject(dbSession, project.uuid()); assertThat(dbClient.projectMappingsDao().get(dbSession, "a.key.type", "a.key")).isEmpty(); assertThat(dbClient.projectMappingsDao().get(dbSession, "a.key.type", "another.key")).isNotEmpty(); }
@Test public void deleteProject_deletes_project_alm_bindings() { ALM alm = ALM.GITHUB; String repoId = "123"; String otherRepoId = repoId + "-foo"; ComponentDto project = db.components().insertPublicProject(); ComponentDto otherProject = db.components().insertPublicProject(); dbClient.projectAlmBindingsDao().insertOrUpdate(dbSession, alm, repoId, project.uuid(), null, "foo"); dbClient.projectAlmBindingsDao().insertOrUpdate(dbSession, alm, otherRepoId, otherProject.uuid(), null, "bar"); underTest.deleteProject(dbSession, project.uuid()); assertThat(dbClient.projectAlmBindingsDao().findProjectKey(dbSession, alm, repoId)).isEmpty(); assertThat(dbClient.projectAlmBindingsDao().findProjectKey(dbSession, alm, otherRepoId)).isNotEmpty(); }