private void verifyCookie(Cookie cookie) { assertThat(cookie.getName()).isEqualTo("OAUTHSTATE"); assertThat(cookie.getValue()).isNotEmpty(); assertThat(cookie.getPath()).isEqualTo("/"); assertThat(cookie.isHttpOnly()).isTrue(); assertThat(cookie.getMaxAge()).isEqualTo(-1); assertThat(cookie.getSecure()).isFalse(); } }
@Test public void loadSecretKeyFromFile_trim_content() throws Exception { URL resource = getClass().getResource("/org/sonar/api/config/AesCipherTest/non_trimmed_secret_key.txt"); String path = new File(resource.toURI()).getCanonicalPath(); AesCipher cipher = new AesCipher(null); Key secretKey = cipher.loadSecretFileFromFile(path); assertThat(secretKey.getAlgorithm()).isEqualTo("AES"); assertThat(secretKey.getEncoded().length).isGreaterThan(10); }
@Test public void differentHashCode() { String s1 = "a"; String s2 = "c"; assertThat(s1.hashCode()).isNotEqualTo(s2.hashCode()); assertThat(compare(s1, s2)).isEqualTo(-1); assertThat(compare(s2, s1)).isEqualTo(1); }
@Test public void test_format_of_uuid() { String uuid = underTest.create(); assertThat(uuid.length()).isGreaterThan(10).isLessThan(40); // URL-safe: only letters, digits, dash and underscore. assertThat(uuid).matches("^[\\w\\-_]+$"); } }
@Test public void cancel_downloads() throws Exception { File file1 = new File(downloadDir, "file1.jar"); file1.createNewFile(); File file2 = new File(downloadDir, "file2.jar"); file2.createNewFile(); pluginDownloader.start(); assertThat(noDownloadedFiles()).isGreaterThan(0); pluginDownloader.cancelDownloads(); assertThat(noDownloadedFiles()).isZero(); }
@Test public void testIssueRange() throws Exception { List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/Single.xoo")); assertThat(issues).hasSize(1); Issue issue = issues.get(0); assertThat(issue.getMsg()).isEqualTo("Primary location"); assertThat(issue.getTextRange().getStartLine()).isEqualTo(6); assertThat(issue.getTextRange().getStartOffset()).isEqualTo(23); assertThat(issue.getTextRange().getEndLine()).isEqualTo(6); assertThat(issue.getTextRange().getEndOffset()).isEqualTo(50); }
@Test public void stringAndInt() { assertThat(IPUtil.ipv4StringToInt("192.168.0.1")).isEqualTo(-1062731775); assertThat(IPUtil.ipv4StringToInt("192.168.0.2")).isEqualTo(-1062731774); assertThat(IPUtil.intToIpv4String(-1062731775)).isEqualTo("192.168.0.1"); assertThat(IPUtil.intToIpv4String(-1062731774)).isEqualTo("192.168.0.2"); }
@Test public void testWithANonMatchingFile() throws IOException, InterruptedException { watcher.watch(); // Initial deployment assertWaitUntil(() -> deploy.get() == 1); File file = new File(root, "foo.nope"); file.createNewFile(); Thread.sleep(500); assertThat(undeploy.get()).isEqualTo(0); assertThat(deploy.get()).isEqualTo(1); }
@Test public void testEqualsAndHashCode() throws Exception { DefaultInputDir inputDir1 = new DefaultInputDir("ABCDE", "src"); DefaultInputDir inputDir2 = new DefaultInputDir("ABCDE", "src"); assertThat(inputDir1.equals(inputDir1)).isTrue(); assertThat(inputDir1.equals(inputDir2)).isTrue(); assertThat(inputDir1.equals("foo")).isFalse(); assertThat(inputDir1.hashCode()).isEqualTo(63545559); assertThat(inputDir1.toString()).contains("[moduleKey=ABCDE, relative=src, basedir=null"); }
@Test public void get_range_of_lines() { Optional<Iterable<DbFileSources.Line>> linesOpt = underTest.getLines(dbTester.getSession(), FILE_UUID, 5, 7); assertThat(linesOpt.isPresent()).isTrue(); List<DbFileSources.Line> lines = Lists.newArrayList(linesOpt.get()); assertThat(lines).hasSize(3); assertThat(lines.get(0).getLine()).isEqualTo(5); assertThat(lines.get(1).getLine()).isEqualTo(6); assertThat(lines.get(2).getLine()).isEqualTo(7); }
@Test public void response_is_empty_on_provisioned_projects() { ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid")); logInWithBrowsePermission(project); TreeWsResponse response = ws.newRequest() .setParam(PARAM_COMPONENT_ID, "project-uuid").executeProtobuf(TreeWsResponse.class); assertThat(response.getBaseComponent().getId()).isEqualTo("project-uuid"); assertThat(response.getComponentsList()).isEmpty(); assertThat(response.getPaging().getTotal()).isEqualTo(0); assertThat(response.getPaging().getPageSize()).isEqualTo(100); assertThat(response.getPaging().getPageIndex()).isEqualTo(1); }
@Test public void setColorWithAwtColorParam_colorHasBeakerColorType() { //given histogram = createWidget(); //when histogram.setColor(java.awt.Color.GREEN); //then assertThat(histogram.getColor() instanceof Color).isTrue(); LinkedHashMap model = getModelUpdate(); assertThat(model.size()).isEqualTo(1); assertThat(model.get(COLOR)).isNotNull(); }
@Test public void create_without_language() { FileAttributes underTest = new FileAttributes(true, null, 10); assertThat(underTest.isUnitTest()).isTrue(); assertThat(underTest.getLanguageKey()).isNull(); assertThat(underTest.getLines()).isEqualTo(10); }
@Test public void checkDefinitions() { CoreCustomMetrics coreCustomMetrics = new CoreCustomMetrics(); List<Metric> metrics = coreCustomMetrics.getMetrics(); assertThat(metrics.size()).isGreaterThan(2); for (Metric metric : metrics) { assertThat(metric.getUserManaged()).isTrue(); assertThat(metric.getDomain()).isEqualTo("Management"); } } }
@Test public void structuredUpdate_intProgressHasDescriptionAndValue() throws Exception { //when progress.structuredUpdate("msg", 5); //then Assertions.assertThat(progress.getIntProgress()).isNotNull(); Assertions.assertThat(progress.getIntProgress().getDescription()).isEqualTo("msg"); Assertions.assertThat(progress.getIntProgress().getValue()).isEqualTo(5); }
@Test public void test_default_result() { Result<Object> result = Result.of(); assertThat(result.ok()).isTrue(); assertThat(result.errors()).isEmpty(); assertThat(result.httpStatus()).isEqualTo(200); assertThat(result.get()).isNull(); Object obj = new Object(); result.set(obj); assertThat(result.get()).isSameAs(obj); }
@Test public void empty_file() throws Exception { File tempFile = temp.newFile(); FileUtils.touch(tempFile); Metadata metadata = new FileMetadata().readMetadata(new FileInputStream(tempFile), StandardCharsets.UTF_8, tempFile.getName()); assertThat(metadata.lines()).isEqualTo(1); assertThat(metadata.nonBlankLines()).isEqualTo(0); assertThat(metadata.hash()).isNotEmpty(); assertThat(metadata.originalLineStartOffsets()).containsOnly(0); assertThat(metadata.originalLineEndOffsets()).containsOnly(0); assertThat(metadata.isEmpty()).isTrue(); }
@Test public void shouldSendCommMsgWhenRoundChange() throws Exception { //given treeMap = createWidget(); //when treeMap.setRound(true); //then assertThat(treeMap.getRound()).isEqualTo(true); LinkedHashMap model = getModelUpdate(); assertThat(model.size()).isEqualTo(1); assertThat(model.get(ROUND)).isEqualTo(true); }
@Test public void search_tasks_by_component_key() { ComponentDto project = db.components().insertPrivateProject(); logInWithBrowsePermission(project); SnapshotDto analysis = db.components().insertSnapshot(project); insertActivity("T1", project, CeActivityDto.Status.SUCCESS, analysis); Ce.ComponentResponse response = ws.newRequest() .setParam(PARAM_COMPONENT, project.getDbKey()) .executeProtobuf(Ce.ComponentResponse.class); assertThat(response.hasCurrent()).isTrue(); Ce.Task current = response.getCurrent(); assertThat(current.getId()).isEqualTo("T1"); assertThat(current.getAnalysisId()).isEqualTo(analysis.getUuid()); assertThat(current.getWarningCount()).isZero(); assertThat(current.getWarningsList()).isEmpty(); }
@Test public void return_500_on_internal_error() { Request request = new TestRequest().setPath("api/foo"); DumbResponse response = run(request, newFailWs()); assertThat(response.stream().outputAsString()).isEqualTo("{\"errors\":[{\"msg\":\"An error has occurred. Please contact your administrator\"}]}"); assertThat(response.stream().status()).isEqualTo(500); assertThat(response.stream().mediaType()).isEqualTo(MediaTypes.JSON); assertThat(logTester.logs(LoggerLevel.ERROR)).filteredOn(l -> l.contains("Fail to process request api/foo")).isNotEmpty(); }