Refine search
@Test public void shouldGetFieldsOfSingleClass() { List<String> fields = fieldsName(FieldUtils2.getFields(FieldsWithDifferentModifiers.class, true)); assertThat(fields).contains("publicField"); assertThat(fields).contains("protectedField"); assertThat(fields).contains("packageField"); assertThat(fields).contains("privateField"); assertThat(fields).contains("publicStaticField"); assertThat(fields).contains("protectedStaticField"); assertThat(fields).contains("packageStaticField"); assertThat(fields).contains("privateStaticField"); }
@Test(groups = CLI, timeOut = TIMEOUT) public void shouldHandleSession() throws IOException { launchPrestoCliWithServerArgument(); presto.waitForPrompt(); presto.getProcessInput().println("use hive.default;"); assertThat(presto.readLinesUntilPrompt()).contains("USE"); presto.getProcessInput().println("select * from nation;"); assertThat(trimLines(presto.readLinesUntilPrompt())).containsAll(nationTableInteractiveLines); presto.getProcessInput().println("show session;"); assertThat(squeezeLines(presto.readLinesUntilPrompt())) .contains("join_distribution_type|PARTITIONED|PARTITIONED|varchar|The join method to use. Options are BROADCAST,PARTITIONED,AUTOMATIC"); presto.getProcessInput().println("set session join_distribution_type = 'BROADCAST';"); assertThat(presto.readLinesUntilPrompt()).contains("SET SESSION"); presto.getProcessInput().println("show session;"); assertThat(squeezeLines(presto.readLinesUntilPrompt())) .contains("join_distribution_type|BROADCAST|PARTITIONED|varchar|The join method to use. Options are BROADCAST,PARTITIONED,AUTOMATIC"); }
private void assertError(String expectedError) throws Exception { assertThat(logTester.logs(LoggerLevel.WARN)).contains(expectedError); verify(response).sendRedirect("/sessions/unauthorized"); assertThat(oAuth2IdentityProvider.isInitCalled()).isFalse(); }
@Test public void persist_built_in_profiles_that_are_not_persisted_yet() { BuiltInQProfile builtInQProfile = builtInQProfileRepositoryRule.add(FOO_LANGUAGE, "Sonar way"); builtInQProfileRepositoryRule.initialize(); underTest.start(); assertThat(insert.callLogs).containsExactly(builtInQProfile); assertThat(update.callLogs).isEmpty(); assertThat(logTester.logs(LoggerLevel.INFO)).contains("Register profile foo/Sonar way"); }
@Test public void shouldGetFieldsOfClassHierarchy() { List<String> fields = fieldsName(FieldUtils2.getFields(Child.class, true)); assertThat(fields).contains("publicField"); assertThat(fields).contains("protectedField"); assertThat(fields).contains("packageField"); assertThat(fields).contains("privateField"); assertThat(fields).contains("publicStaticField"); assertThat(fields).contains("protectedStaticField"); assertThat(fields).contains("packageStaticField"); assertThat(fields).contains("privateStaticField"); assertThat(fields).contains("childPrivateField"); }
@Test public void update_built_in_profile_if_it_already_exists() { RulesProfileDto ruleProfile = newRuleProfileDto(rp -> rp.setIsBuiltIn(true).setName("Sonar way").setLanguage(FOO_LANGUAGE.getKey())); db.getDbClient().qualityProfileDao().insert(db.getSession(), ruleProfile); db.commit(); BuiltInQProfile builtIn = builtInQProfileRepositoryRule.add(FOO_LANGUAGE, ruleProfile.getName(), false); builtInQProfileRepositoryRule.initialize(); underTest.start(); assertThat(insert.callLogs).isEmpty(); assertThat(update.callLogs).containsExactly(builtIn); assertThat(logTester.logs(LoggerLevel.INFO)).contains("Update profile foo/Sonar way"); }
private void assertError(String expectedError) throws Exception { assertThat(logTester.logs(LoggerLevel.WARN)).contains(expectedError); verify(response).sendRedirect("/sessions/unauthorized"); assertThat(oAuth2IdentityProvider.isInitCalled()).isFalse(); }
@Test public void shouldGetOnlyAccessibleFields() { List<String> fields = fieldsName(FieldUtils2.getFields(Child.class, false)); assertThat(fields).contains("publicField"); assertThat(fields).contains("publicStaticField"); }
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 verify_installed_HealthChecks_implementations() { ComponentContainer container = new ComponentContainer(); underTest.configure(container); List<Class<?>> checks = classesAddedToContainer(container).stream().filter(NodeHealthCheck.class::isAssignableFrom).collect(Collectors.toList()); assertThat(checks) .hasSize(3) .contains(WebServerSafemodeNodeCheck.class) .contains(DbConnectionNodeCheck.class) .contains(EsStatusNodeCheck.class); }
private static void assertAddedExtensions(ComponentContainer container, Class... classes) { Collection<ComponentAdapter<?>> adapters = container.getPicoContainer().getComponentAdapters(); assertThat(adapters) .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + classes.length); Stream<Class> installedExtensions = adapters.stream() .map(t -> (Class) t.getComponentImplementation()) .filter(t -> !PropertyDefinitions.class.isAssignableFrom(t) && t != ComponentContainer.class); assertThat(installedExtensions) .contains(classes) .hasSize(classes.length); }
@Test public void verify_installed_NodeHealthChecks_implementations_when_standalone() { when(webServer.isStandalone()).thenReturn(true); ComponentContainer container = new ComponentContainer(); underTest.configure(container); List<Class<?>> checks = classesAddedToContainer(container).stream().filter(NodeHealthCheck.class::isAssignableFrom).collect(Collectors.toList()); assertThat(checks) .hasSize(4) .contains(WebServerStatusNodeCheck.class) .contains(DbConnectionNodeCheck.class) .contains(EsStatusNodeCheck.class) .contains(CeStatusNodeCheck.class); }
private void verifySearch(RuleQuery query, RuleDefinitionDto... expectedRules) { SearchIdResult<Integer> result = underTest.search(query, new SearchOptions()); assertThat(result.getTotal()).isEqualTo((long) expectedRules.length); assertThat(result.getIds()).hasSize(expectedRules.length); for (RuleDefinitionDto expectedRule : expectedRules) { assertThat(result.getIds()).contains(expectedRule.getId()); } }
@Test public void verify_action_and_HealthChecker() { ComponentContainer container = new ComponentContainer(); underTest.configure(container); assertThat(classesAddedToContainer(container)) .contains(HealthCheckerImpl.class) .contains(HealthActionSupport.class) .contains(SafeModeHealthAction.class) .doesNotContain(HealthAction.class); }
@Test public void verify_installed_ClusterHealthChecks_implementations_in_clustering() { when(webServer.isStandalone()).thenReturn(false); ComponentContainer container = new ComponentContainer(); underTest.configure(container); List<Class<?>> checks = classesAddedToContainer(container).stream().filter(ClusterHealthCheck.class::isAssignableFrom).collect(Collectors.toList()); assertThat(checks) .hasSize(2) .contains(EsStatusClusterCheck.class) .contains(AppNodeClusterCheck.class); }
@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 verify_installed_NodeHealthChecks_implementations_when_clustered() { when(webServer.isStandalone()).thenReturn(false); ComponentContainer container = new ComponentContainer(); underTest.configure(container); List<Class<?>> checks = classesAddedToContainer(container).stream().filter(NodeHealthCheck.class::isAssignableFrom).collect(Collectors.toList()); assertThat(checks) .hasSize(3) .contains(WebServerStatusNodeCheck.class) .contains(DbConnectionNodeCheck.class) .contains(CeStatusNodeCheck.class) .doesNotContain(EsStatusNodeCheck.class); }
@Test public void init_logs_warning() { underTest.init(mock(DatabaseMetaData.class)); assertThat(logs.logs(LoggerLevel.WARN)).contains("H2 database should be used for evaluation purpose only."); }
@Test public void do_not_fail_when_response_is_committed_after_other_error() throws Exception { system.isCommitted = true; system.pluginStreamException = new RuntimeException("Simulating a error"); when(pluginRepository.hasPlugin("myplugin")).thenReturn(true); Response response = call("/static/myplugin/foo.css"); assertThat(response.code()).isEqualTo(200); assertThat(logTester.logs(LoggerLevel.ERROR)).contains("Unable to load resource [static/foo.css] from plugin [myplugin]"); }