/** * Verify that index with name {@code indexName} does not exist on the table {@code tableName} */ public void assertIndexDoesNotExist(String tableName, String indexName) { try (Connection connection = getConnection(); ResultSet rs = connection.getMetaData().getIndexInfo(null, null, tableName.toUpperCase(Locale.ENGLISH), false, false)) { List<String> indices = new ArrayList<>(); while (rs.next()) { indices.add(rs.getString("INDEX_NAME").toLowerCase(Locale.ENGLISH)); } assertThat(indices).doesNotContain(indexName); } catch (SQLException e) { throw new IllegalStateException("Fail to check existence of index", e); } }
@Test public void selectForIndexing_all() { assertSelectForIndexing(null) .doesNotContain("DIS7") .doesNotContain("COPY8") .containsExactlyInAnyOrder("U1", "U2", "U3", "U4", "U5", "U6", "VW1"); }
@Test public void selectForIndexing_project() { assertSelectForIndexing("U1") .doesNotContain("DIS7") .doesNotContain("COPY8") .containsExactlyInAnyOrder("U1", "U2", "U3", "U4"); }
@Test public void asList_returnsModifiableList() throws Exception { List<String> modifiable = asList("Larry", "Moe", "Curly"); assertThat(modifiable.remove("Curly")).isTrue(); assertThat(modifiable).contains("Larry", "Moe").doesNotContain("Curly"); } }
@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 putThatDoesNotAddEventToPendingCallbacksCallsEventRelease() { createInstance(Operation.UPDATE, false, txRmtEvent, null); instance.put(); assertThat(instance.isCallbackEventInPending()).isFalse(); assertThat(pendingCallbacks).doesNotContain(event); verify(event, never()).changeRegionToBucketsOwner(); verify(event, never()).setOriginRemote(anyBoolean()); verify(event, times(1)).release(); }
@Test public void putThatDoesNotInvokesCallbacksDoesNotAddToPendingCallbacks() { createInstance(Operation.UPDATE, false, txRmtEvent, null); instance.put(); assertThat(instance.isCallbackEventInPending()).isFalse(); assertThat(pendingCallbacks).doesNotContain(event); verify(event, never()).changeRegionToBucketsOwner(); verify(event, never()).setOriginRemote(anyBoolean()); }
@Test public void do_not_check_db_compatibility_on_fresh_es() { // supposed to be ignored esDbCompatibility.setHasSameDbVendor(false); startNewCreator(new FakeIndexDefinition()); assertThat(logTester.logs(LoggerLevel.INFO)) .doesNotContain(LOG_DB_VENDOR_CHANGED) .doesNotContain(LOG_DB_SCHEMA_CHANGED) .contains("Create type fakes/fake") .contains("Create type metadatas/metadata"); }
@Test public void log_but_not_dump_information_when_report_is_not_uploaded() throws IOException { underTest.logSuccess(/* report not uploaded, no server task */null); assertThat(logTester.logs(LoggerLevel.INFO)) .contains("ANALYSIS SUCCESSFUL") .doesNotContain("dashboard/index"); assertThat(properties.metadataFilePath()).doesNotExist(); }
@Test public void verify_action_and_HealthChecker() { boolean standalone = new Random().nextBoolean(); when(webServer.isStandalone()).thenReturn(standalone); ComponentContainer container = new ComponentContainer(); underTest.configure(container); assertThat(classesAddedToContainer(container)) .describedAs("Verifying action and HealthChecker with standalone=%s", standalone) .contains(HealthCheckerImpl.class) .contains(HealthActionSupport.class) .contains(HealthAction.class) .doesNotContain(SafeModeHealthAction.class); }
@Test public void ignore_indices_that_do_not_exist() { underTest.deleteIndexes("a", "xxx", "c"); assertThat(loadExistingIndices()) .doesNotContain("a", "c") .contains("b"); assertThat(logTester.logs(LoggerLevel.INFO)) .contains("Drop Elasticsearch index [a]", "Drop Elasticsearch index [c]") .doesNotContain("Drop Elasticsearch index [xxx]"); }
@Test public void selectGroupNamesByQuery_does_not_return_anyone_when_group_roles_is_empty() { GroupDto group = db.users().insertGroup(); assertThat(underTest.selectGroupNamesByQuery(dbSession, newQuery().build())) .doesNotContain(ANYONE) .containsExactly(group.getName()); }
@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 provide_extensions_for_5_6() { SonarRuntime runtime = SonarRuntimeImpl.forSonarLint(Version.parse("5.4")); Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build(); new XooPlugin().define(context); assertThat(getExtensions(context)) .hasSize(48) .doesNotContain(XooBuiltInQualityProfilesDefinition.class); }
@Test public void apply_removes_any_organization_permission_to_user() { // give ADMIN perm to user2 so that user1 is not the only one with this permission and it can be removed from user1 db.users().insertPermissionOnUser(org1, user2, OrganizationPermission.ADMINISTER); permissionService.getAllOrganizationPermissions().stream() .forEach(perm -> db.users().insertPermissionOnUser(org1, user1, perm)); assertThat(db.users().selectPermissionsOfUser(user1, org1)) .containsOnly(permissionService.getAllOrganizationPermissions().toArray(new OrganizationPermission[0])); permissionService.getAllOrganizationPermissions().stream() .forEach(perm -> { UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), perm.getKey(), null, UserId.from(user1), permissionService); apply(change); assertThat(db.users().selectPermissionsOfUser(user1, org1)).doesNotContain(perm); }); }
@Test public void post_action_without_response_example() { WebService ws = context -> { NewController newController = context.createController("api/rule"); newDefaultAction(newController, "list").setPost(true).setResponseExample(null); newController.done(); }; ws.define(context); assertThat(logTester.logs(LoggerLevel.WARN)) .doesNotContain("The response example is not set on action api/rule/list"); }
@Test public void apply_removes_any_permission_from_a_private_project() { permissionService.getAllProjectPermissions() .forEach(permission -> db.users().insertProjectPermissionOnUser(user1, permission, privateProject)); permissionService.getAllProjectPermissions() .forEach(permission -> { UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), permission, new ProjectId(privateProject), UserId.from(user1), permissionService); apply(change); assertThat(db.users().selectProjectPermissionsOfUser(user1, privateProject)).doesNotContain(permission); }); }
@Test public void apply_has_no_effect_when_adding_permission_USER_on_a_public_project() { UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), USER, new ProjectId(publicProject), UserId.from(user1), permissionService); apply(change); assertThat(db.users().selectProjectPermissionsOfUser(user1, publicProject)).doesNotContain(USER); }
@Test public void apply_has_no_effect_when_adding_permission_CODEVIEWER_on_a_public_project() { UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), CODEVIEWER, new ProjectId(publicProject), UserId.from(user1), permissionService); apply(change); assertThat(db.users().selectProjectPermissionsOfUser(user1, publicProject)).doesNotContain(CODEVIEWER); }
@Test public void filter_unauthorized_components() { ComponentDto unauthorizedProject = db.components().insertPrivateProject(); ComponentDto project1 = db.components().insertPrivateProject(); ComponentDto project2 = db.components().insertPrivateProject(); indexer.indexOnStartup(emptySet()); authorizationIndexerTester.allowOnlyAnyone(project1); authorizationIndexerTester.allowOnlyAnyone(project2); SearchIdResult<String> result = underTest.search(ComponentQuery.builder().build(), new SearchOptions()); assertThat(result.getIds()).containsExactlyInAnyOrder(project1.uuid(), project2.uuid()) .doesNotContain(unauthorizedProject.uuid()); }