@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 sameHashCode() { // Next two Strings have same hash code in Java - see http://www.drmaciver.com/2008/07/javalangstringhashcode/ String s1 = "Od"; String s2 = "PE"; assertThat(s1.hashCode()).isEqualTo(s2.hashCode()); assertThat(compare(s1, s2)).isLessThan(0); assertThat(compare(s2, s1)).isGreaterThan(0); }
@Test public void read_metrics_from_class_reflection() { List<Metric> metrics = getMetrics(); assertThat(metrics.size()).isGreaterThan(100); assertThat(metrics).contains(NCLOC, DIRECTORIES); }
@Test public void shouldExecuteDdlAtStartup() throws SQLException { Connection connection = db.getDataSource().getConnection(); int tableCount = DdlUtilsTest.countTables(connection); connection.close(); assertThat(tableCount).isGreaterThan(30); } }
@Test public void shouldFormatDateTime() { assertThat(DateUtils.formatDateTime(new Date())).startsWith("20"); assertThat(DateUtils.formatDateTime(new Date()).length()).isGreaterThan(20); }
@Test public void shouldFormatDateTime_with_long() { assertThat(DateUtils.formatDateTime(System.currentTimeMillis())).startsWith("20"); assertThat(DateUtils.formatDateTime(System.currentTimeMillis()).length()).isGreaterThan(20); }
private void assertThatCustomProfileExists(QProfileDto profile) { assertThat(db.countSql(dbSession, "select count(*) from org_qprofiles where uuid = '" + profile.getKee() + "'")).isGreaterThan(0); //assertThat(db.countSql(dbSession, "select count(*) from project_qprofiles where profile_key = '" + profile.getKee() + "'")).isGreaterThan(0); //assertThat(db.countSql(dbSession, "select count(*) from default_qprofiles where qprofile_uuid = '" + profile.getKee() + "'")).isGreaterThan(0); assertThat(db.countSql(dbSession, "select count(*) from rules_profiles where kee = '" + profile.getRulesProfileUuid() + "'")).isEqualTo(1); assertThat(db.countSql(dbSession, "select count(*) from active_rules where profile_id = " + profile.getId())).isGreaterThan(0); assertThat(db.countSql(dbSession, "select count(*) from qprofile_changes where rules_profile_uuid = '" + profile.getRulesProfileUuid() + "'")).isGreaterThan(0); // TODO active_rule_parameters }
@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 completeDefaults_sets_the_port_of_elasticsearch_if_value_is_zero() { Properties p = new Properties(); p.setProperty("sonar.search.port", "0"); Props props = new Props(p); ProcessProperties.completeDefaults(props); assertThat(props.valueAsInt("sonar.search.port")).isGreaterThan(0); }
@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 format_date_time_null_safe() { assertThat(DateUtils.formatDateTimeNullSafe(new Date())).startsWith("20"); assertThat(DateUtils.formatDateTimeNullSafe(new Date()).length()).isGreaterThan(20); assertThat(DateUtils.formatDateTimeNullSafe(null)).isEmpty(); }
@Test public void loadSecretKeyFromFile() throws Exception { AesCipher cipher = new AesCipher(null); Key secretKey = cipher.loadSecretFileFromFile(pathToSecretKey()); assertThat(secretKey.getAlgorithm()).isEqualTo("AES"); assertThat(secretKey.getEncoded().length).isGreaterThan(10); }
@Test public void loadSecretKeyFromFile_trim_content() throws Exception { String path = getPath("non_trimmed_secret_key.txt"); AesCipher cipher = new AesCipher(null); Key secretKey = cipher.loadSecretFileFromFile(path); assertThat(secretKey.getAlgorithm()).isEqualTo("AES"); assertThat(secretKey.getEncoded().length).isGreaterThan(10); }
@Test public void loadSecretKeyFromFile() throws Exception { AesCipher cipher = new AesCipher(null); Key secretKey = cipher.loadSecretFileFromFile(pathToSecretKey()); assertThat(secretKey.getAlgorithm()).isEqualTo("AES"); assertThat(secretKey.getEncoded().length).isGreaterThan(10); }
@Test public void shouldCreateSchema_with_schema_migrations() throws SQLException { DriverManager.registerDriver(new Driver()); try (Connection connection = DriverManager.getConnection("jdbc:h2:mem:sonar_test")) { DdlUtils.createSchema(connection, "h2", true); int tableCount = countTables(connection); assertThat(tableCount).isGreaterThan(30); verifySchemaMigrationsNotPopulated(connection); } }
@Test public void readString() throws URISyntaxException { String text = new DefaultHttpDownloader(new MapSettings().asConfig()).readString(new URI(baseUrl), StandardCharsets.UTF_8); assertThat(text.length()).isGreaterThan(10); }
@Test public void toSystemInfoSection() { JvmStateSection underTest = new JvmStateSection(PROCESS_NAME); ProtobufSystemInfo.Section section = underTest.toProtobuf(); assertThat(section.getName()).isEqualTo(PROCESS_NAME); assertThat(section.getAttributesCount()).isGreaterThan(0); assertThat(section.getAttributesList()).extracting("key") .contains( "Max Memory (MB)", "Free Memory (MB)", "Heap Max (MB)", "System Load Average", "Threads"); }
@Test public void compareOrderWebSecurityConfigurerAdapterWhenLowestOrderToDefaultOrderThenGreaterThanZero() throws Exception { AnnotationAwareOrderComparator comparator = new AnnotationAwareOrderComparator(); assertThat(comparator.compare( new LowestPriorityWebSecurityConfig(), new DefaultOrderWebSecurityConfig())).isGreaterThan(0); }
@Test public void test_compareTo() { assertThat(parse("1.2").compareTo(parse("1.2.0"))).isEqualTo(0); assertThat(parse("1.2.3").compareTo(parse("1.2.3"))).isEqualTo(0); assertThat(parse("1.2.3").compareTo(parse("1.2.4"))).isLessThan(0); assertThat(parse("1.2.3").compareTo(parse("1.3"))).isLessThan(0); assertThat(parse("1.2.3").compareTo(parse("2.1"))).isLessThan(0); assertThat(parse("1.2.3").compareTo(parse("2.0.0"))).isLessThan(0); assertThat(parse("2.0").compareTo(parse("1.2"))).isGreaterThan(0); }
@Test public void test_compare() { TaskDefinition foo = TaskDefinition.builder().key("foo").taskClass(FooTask.class).description("Foo").build(); TaskDefinition bar = TaskDefinition.builder().key("bar").taskClass(FooTask.class).description("Bar").build(); assertThat(foo.compareTo(bar)).isGreaterThan(0); assertThat(foo.compareTo(foo)).isEqualTo(0); assertThat(bar.compareTo(foo)).isLessThan(0); }