import java.util.Map;
import org.assertj.core.data.MapEntry;
import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
- @ClassRule
- public static EsTester es = new EsTester().addDefinitions(new ActivityIndexDefinition(new Settings()));
+ @Rule
+ public EsTester es = new EsTester(new ActivityIndexDefinition(new Settings()));
@Rule
public UserSessionRule userSession = UserSessionRule.standalone().login();
package org.sonar.server.activity.index;
import com.google.common.collect.ImmutableMap;
+import java.util.Arrays;
+import java.util.Date;
import org.junit.Before;
-import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
import org.sonar.server.activity.Activity;
import org.sonar.server.es.SearchOptions;
import org.sonar.server.es.SearchResult;
-import java.util.Arrays;
-import java.util.Date;
-
import static org.assertj.core.api.Assertions.assertThat;
public class ActivityIndexTest {
- @ClassRule
- public static EsTester es = new EsTester().addDefinitions(new ActivityIndexDefinition(new Settings()));
+ @Rule
+ public EsTester es = new EsTester(new ActivityIndexDefinition(new Settings()));
ActivityIndex underTest;
import java.util.Map;
import org.assertj.core.data.MapEntry;
import org.elasticsearch.action.update.UpdateRequest;
-import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.DateUtils;
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
- @Before
- public void setUp() {
- dbTester.truncateTables();
- }
-
/**
* Iterate over two rows in table.
*/
import java.util.Arrays;
import javax.annotation.Nullable;
import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
- @ClassRule
- public static EsTester es = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()));
+ @Rule
+ public EsTester es = new EsTester(new IssueIndexDefinition(new Settings()));
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
@Before
public void before() {
- db.truncateTables();
- es.truncateIndices();
-
issueIndex = new IssueIndex(es.client(), System2.INSTANCE, userSessionRule);
issueIndexer = new IssueIndexer(null, es.client());
issueAuthorizationIndexer = new IssueAuthorizationIndexer(null, es.client());
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@Rule
public ExpectedException thrown = ExpectedException.none();
- @ClassRule
- public static EsTester es = new EsTester().addDefinitions(new UserIndexDefinition(new Settings()));
+ @Rule
+ public EsTester es = new EsTester(new UserIndexDefinition(new Settings()));
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
@Before
public void before() {
- es.truncateIndices();
-
userIndex = new UserIndex(es.client());
usersAction = new UsersAction(userIndex, userSessionRule);
-
tester = new WsTester(new BatchWs(new BatchIndex(mock(Server.class)), usersAction));
}
@Before
public void setUp() {
- dbTester.truncateTables();
when(i18n.message(Locale.getDefault(), "qualifier.TRK", "Project")).thenReturn("Project");
service = new ComponentService(dbClient, i18n, userSessionRule, System2.INSTANCE, new ComponentFinder(dbClient));
}
@Before
public void setUp() {
- db.truncateTables();
ws = new WsTester(new ComponentsWs(mock(AppAction.class), new SearchViewComponentsAction(db.getDbClient(), userSessionRule, new ComponentFinder(db.getDbClient()))));
}
@Before
public void createDao() {
- dbTester.truncateTables();
globalSettings = new Settings();
PropertiesDao propertiesDao = new PropertiesDao(dbTester.myBatis());
session = dbClient.openSession(false);
package org.sonar.server.computation.issue;
import java.util.Collections;
-import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Test;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.log.LogTester;
public class ScmAccountToUserLoaderTest {
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new UserIndexDefinition(new Settings()));
+ @org.junit.Rule
+ public EsTester esTester = new EsTester(new UserIndexDefinition(new Settings()));
- @ClassRule
- public static LogTester logTester = new LogTester();
-
- @Before
- public void setUp() {
- esTester.truncateIndices();
- }
+ @org.junit.Rule
+ public LogTester logTester = new LogTester();
@Test
public void load_login_for_scm_account() throws Exception {
*/
package org.sonar.server.computation.metric;
-import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
private DbClient dbClient = dbTester.getDbClient();
private MetricRepositoryImpl underTest = new MetricRepositoryImpl(dbClient);
- @Before
- public void setUp() {
- dbTester.truncateTables();
- }
-
@Test(expected = NullPointerException.class)
public void getByKey_throws_NPE_if_arg_is_null() {
underTest.getByKey(null);
import org.elasticsearch.search.SearchHit;
import org.junit.After;
import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
private static final String ROOT_UUID = "ROOT_UUID";
private static final long SOME_DATE = 1000L;
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()));
+ @Rule
+ public EsTester esTester = new EsTester(new IssueIndexDefinition(new Settings()));
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
DbClient dbClient = dbTester.getDbClient();
- Settings settings;
+ Settings settings = new Settings();
IssueAuthorizationIndexer issueAuthorizationIndexer;
@Before
public void setUp() {
dbSession = dbClient.openSession(false);
- settings = new Settings();
- esTester.truncateIndices();
issueAuthorizationIndexer = new IssueAuthorizationIndexer(dbClient, esTester.client());
issueAuthorizationIndexer.setEnabled(true);
import java.util.List;
import org.elasticsearch.search.SearchHit;
-import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new TestIndexDefinition(new Settings()));
+ @Rule
+ public EsTester esTester = new EsTester(new TestIndexDefinition(new Settings()));
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
DbClient dbClient = dbTester.getDbClient();
- @Before
- public void setUp() {
- esTester.truncateIndices();
- }
-
@Override
protected ComputationStep step() {
TestIndexer testIndexer = new TestIndexer(dbClient, esTester.client());
@Before
public void setup() {
- dbTester.truncateTables();
when(system2.now()).thenReturn(NOW);
underTest = new PersistFileSourcesStep(dbClient, system2, treeRootHolder, reportReader, fileSourceRepository, scmInfoRepository, duplicationRepository);
}
@Before
public void setup() throws Exception {
- dbTester.truncateTables();
issueCache = new IssueCache(temp.newFile(), System2.INSTANCE);
system2 = mock(System2.class);
when(system2.now()).thenReturn(NOW);
public class BulkIndexerTest {
@Rule
- public EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition().setReplicas(1));
+ public EsTester esTester = new EsTester(new FakeIndexDefinition().setReplicas(1));
@Test
public void index_nothing() {
- esTester.truncateIndices();
-
BulkIndexer indexer = new BulkIndexer(esTester.client(), FakeIndexDefinition.INDEX);
indexer.start();
indexer.stop();
import com.google.common.collect.Collections2;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Iterables;
-import java.util.Collections;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import javax.annotation.Nonnull;
import org.sonar.api.config.Settings;
import org.sonar.core.platform.ComponentContainer;
+import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.Lists.newArrayList;
+import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
public class EsTester extends ExternalResource {
- private static final int INSTANCE_ID = RandomUtils.nextInt();
- private Node node;
- private EsClient client;
- private final List<IndexDefinition> definitions = newArrayList();
+ private final List<IndexDefinition> indexDefinitions;
+ private EsClient client = new EsClient(new Settings(), NodeHolder.INSTANCE.node.client());
+ private ComponentContainer container;
- public EsTester addDefinitions(IndexDefinition... defs) {
- Collections.addAll(definitions, defs);
- return this;
+ public EsTester(IndexDefinition... defs) {
+ this.indexDefinitions = asList(defs);
}
+ @Override
protected void before() throws Throwable {
- String nodeName = "tmp-es-" + INSTANCE_ID;
- node = NodeBuilder.nodeBuilder().local(true).data(true).settings(ImmutableSettings.builder()
- .put("cluster.name", nodeName)
- .put("node.name", nodeName)
- // the two following properties are probably not used because they are
- // declared on indices too
- .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
- .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
- // limit the number of threads created (see org.elasticsearch.common.util.concurrent.EsExecutors)
- .put("processors", 1)
- .put("http.enabled", false)
- .put("config.ignore_system_properties", true)
- // reuse the same directory than other tests for faster initialization
- .put("path.home", "target/" + nodeName)
- .put("gateway.type", "none"))
- .build();
- node.start();
- assertThat(DiscoveryNode.localNode(node.settings())).isTrue();
-
- // wait for node to be ready
- node.client().admin().cluster().prepareHealth()
- .setWaitForGreenStatus()
- .get();
-
- // delete the indices created by previous tests
- DeleteIndexResponse response = node.client().admin().indices().prepareDelete("_all").get();
- assertThat(response.isAcknowledged()).isTrue();
-
- client = new EsClient(new Settings(), node.client());
client.start();
+ truncateIndices();
- if (!definitions.isEmpty()) {
- ComponentContainer container = new ComponentContainer();
+ if (!indexDefinitions.isEmpty()) {
+ container = new ComponentContainer();
container.addSingleton(new Settings());
- container.addSingletons(definitions);
+ container.addSingletons(indexDefinitions);
container.addSingleton(client);
container.addSingleton(IndexDefinitions.class);
container.addSingleton(IndexCreator.class);
@Override
protected void after() {
+ if (container != null) {
+ container.stopComponents();
+ }
if (client != null) {
client.stop();
}
- if (node != null) {
- node.stop();
- node.close();
- }
}
- public void truncateIndices() {
- String[] indices = client.prepareState().get().getState().getMetaData().concreteAllIndices();
- for (String index : indices) {
- BulkIndexer.delete(client, index, client().prepareSearch(index).setQuery(matchAllQuery()));
- }
+ private void truncateIndices() {
+ client.nativeClient().admin().indices().prepareDelete("_all").get();
}
public void putDocuments(String index, String type, BaseDoc... docs) throws Exception {
}
public long countDocuments(String indexName, String typeName) {
- return client().prepareCount(indexName).setTypes(typeName).get().getCount();
+ return client().prepareSearch(indexName).setTypes(typeName).setSize(0).get().getHits().totalHits();
}
/**
return FluentIterable.from(getDocuments(indexName, typeName)).transform(SearchHitToId.INSTANCE).toList();
}
- public Node node() {
- return node;
- }
-
public EsClient client() {
return client;
}
}
}
+ private static class NodeHolder {
+ private static final NodeHolder INSTANCE = new NodeHolder();
+
+ private final Node node;
+
+ private NodeHolder() {
+ try {
+ String nodeName = "tmp-es-" + RandomUtils.nextInt();
+ Path tmpDir = Files.createTempDirectory("tmp-es");
+ tmpDir.toFile().deleteOnExit();
+
+ node = NodeBuilder.nodeBuilder().local(true).data(true).settings(ImmutableSettings.builder()
+ .put("cluster.name", nodeName)
+ .put("node.name", nodeName)
+ // the two following properties are probably not used because they are
+ // declared on indices too
+ .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
+ .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
+ // limit the number of threads created (see org.elasticsearch.common.util.concurrent.EsExecutors)
+ .put("processors", 1)
+ .put("http.enabled", false)
+ .put("config.ignore_system_properties", true)
+ .put("path.home", tmpDir))
+ .build();
+ node.start();
+ checkState(DiscoveryNode.localNode(node.settings()));
+ checkState(!node.isClosed());
+
+ // wait for node to be ready
+ node.client().admin().cluster().prepareHealth().setWaitForGreenStatus().get();
+
+ // delete the indices (should not exist)
+ DeleteIndexResponse response = node.client().admin().indices().prepareDelete("_all").get();
+ checkState(response.isAcknowledged());
+ } catch (IOException e) {
+ throw Throwables.propagate(e);
+ }
+ }
+ }
}
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.log.LogTester;
public class ProxyBulkRequestBuilderTest {
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+ @Rule
+ public EsTester esTester = new EsTester(new FakeIndexDefinition());
@Rule
public LogTester logTester = new LogTester();
public void no_trace_logs() {
logTester.setLevel(LoggerLevel.INFO);
testBulk();
- assertThat(logTester.logs()).isEmpty();
+ assertThat(logTester.logs(LoggerLevel.TRACE)).isEmpty();
}
@Test
public void trace_logs() {
logTester.setLevel(LoggerLevel.TRACE);
testBulk();
- assertThat(logTester.logs()).hasSize(1);
+ assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
}
private void testBulk() {
package org.sonar.server.es.request;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.log.LogTester;
public class ProxyCountRequestBuilderTest {
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+ @Rule
+ public EsTester esTester = new EsTester(new FakeIndexDefinition());
@Rule
public LogTester logTester = new LogTester();
logTester.setLevel(LoggerLevel.TRACE);
esTester.client().prepareCount(FakeIndexDefinition.INDEX).get();
- assertThat(logTester.logs()).hasSize(1);
+ assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
}
@Test
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.query.QueryBuilders;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.log.LogTester;
public class ProxyDeleteByQueryRequestBuilderTest {
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+ @Rule
+ public EsTester esTester = new EsTester(new FakeIndexDefinition());
@Rule
public LogTester logTester = new LogTester();
esTester.client().prepareDeleteByQuery(FakeIndexDefinition.INDEX).setQuery(QueryBuilders.matchAllQuery()).get();
- assertThat(logTester.logs()).hasSize(1);
+ assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
}
@Test
package org.sonar.server.es.request;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.log.LogTester;
public class ProxyFlushRequestBuilderTest {
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+ @Rule
+ public EsTester esTester = new EsTester(new FakeIndexDefinition());
@Rule
public LogTester logTester = new LogTester();
logTester.setLevel(LoggerLevel.TRACE);
esTester.client().prepareFlush(FakeIndexDefinition.INDEX).get();
- assertThat(logTester.logs()).hasSize(1);
+ assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
}
@Test
import org.elasticsearch.action.get.GetRequestBuilder;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.log.LogTester;
public class ProxyGetRequestBuilderTest {
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+ @Rule
+ public EsTester esTester = new EsTester(new FakeIndexDefinition());
@Rule
public LogTester logTester = new LogTester();
.setType(FakeIndexDefinition.TYPE)
.setId("ruleKey")
.get();
- assertThat(logTester.logs()).hasSize(1);
+ assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
}
@Test
import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.log.LogTester;
public class ProxyIndexRequestBuilderTest {
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+ @Rule
+ public EsTester esTester = new EsTester(new FakeIndexDefinition());
@Rule
public LogTester logTester = new LogTester();
.setSource(FakeIndexDefinition.newDoc(42).getFields())
.get();
assertThat(response.isCreated()).isTrue();
- assertThat(logTester.logs()).hasSize(1);
+ assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
}
@Test
package org.sonar.server.es.request;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.log.LogTester;
public class ProxyIndicesExistsRequestBuilderTest {
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+ @Rule
+ public EsTester esTester = new EsTester(new FakeIndexDefinition());
@Rule
public LogTester logTester = new LogTester();
esTester.client().prepareIndicesExist(FakeIndexDefinition.INDEX).get();
- assertThat(logTester.logs()).hasSize(1);
+ assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
}
@Test
package org.sonar.server.es.request;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.log.LogTester;
public class ProxyIndicesStatsRequestBuilderTest {
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+ @Rule
+ public EsTester esTester = new EsTester(new FakeIndexDefinition());
@Rule
public LogTester logTester = new LogTester();
esTester.client().prepareStats(FakeIndexDefinition.INDEX).get();
- assertThat(logTester.logs()).hasSize(1);
+ assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
}
@Test
import org.elasticsearch.action.get.MultiGetRequestBuilder;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.search.fetch.source.FetchSourceContext;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.log.LogTester;
public class ProxyMultiGetRequestBuilderTest {
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+ @Rule
+ public EsTester esTester = new EsTester(new FakeIndexDefinition());
@Rule
public LogTester logTester = new LogTester();
.fetchSourceContext(FetchSourceContext.FETCH_SOURCE));
request.get();
- assertThat(logTester.logs()).hasSize(1);
+ assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
}
@Test
package org.sonar.server.es.request;
import com.google.common.collect.ImmutableMap;
+import java.util.HashMap;
+import java.util.Map;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.log.LogTester;
import org.sonar.server.es.EsTester;
import org.sonar.server.es.FakeIndexDefinition;
-import java.util.HashMap;
-import java.util.Map;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public class ProxyPutMappingRequestBuilderTest {
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+ @Rule
+ public EsTester esTester = new EsTester(new FakeIndexDefinition());
@Rule
public LogTester logTester = new LogTester();
.setSource(mapDomain());
requestBuilder.get();
- assertThat(logTester.logs()).hasSize(1);
+ assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
}
@Test
import org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.log.LogTester;
public class ProxyRefreshRequestBuilderTest {
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+ @Rule
+ public EsTester esTester = new EsTester(new FakeIndexDefinition());
@Rule
public LogTester logTester = new LogTester();
RefreshRequestBuilder requestBuilder = esTester.client().prepareRefresh(FakeIndexDefinition.INDEX);
requestBuilder.get();
- assertThat(logTester.logs()).hasSize(1);
+ assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
}
@Test
package org.sonar.server.es.request;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.log.LogTester;
public class ProxySearchRequestBuilderTest {
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+ @Rule
+ public EsTester esTester = new EsTester(new FakeIndexDefinition());
@Rule
public LogTester logTester = new LogTester();
logTester.setLevel(LoggerLevel.TRACE);
esTester.client().prepareSearch(FakeIndexDefinition.INDEX).get();
- assertThat(logTester.logs()).hasSize(1);
+ assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
}
@Test
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.log.LogTester;
public class ProxySearchScrollRequestBuilderTest {
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+ @Rule
+ public EsTester esTester = new EsTester(new FakeIndexDefinition());
@Rule
public LogTester logTester = new LogTester();
import java.util.Collection;
import java.util.List;
import org.elasticsearch.search.SearchHit;
-import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()));
-
- @Before
- public void setUp() {
- dbTester.truncateTables();
- esTester.truncateIndices();
- }
+ @Rule
+ public EsTester esTester = new EsTester(new IssueIndexDefinition(new Settings()));
@Test
public void index_nothing() {
import java.util.TimeZone;
import javax.annotation.Nullable;
import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
public class IssueIndexDebtTest {
- @ClassRule
- public static EsTester tester = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()), new ViewIndexDefinition(new Settings()));
+ @Rule
+ public EsTester tester = new EsTester(new IssueIndexDefinition(new Settings()), new ViewIndexDefinition(new Settings()));
+
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
@Before
public void setUp() {
- tester.truncateIndices();
issueIndexer = new IssueIndexer(null, tester.client());
issueAuthorizationIndexer = new IssueAuthorizationIndexer(null, tester.client());
viewIndexer = new ViewIndexer(null, tester.client());
System2 system = mock(System2.class);
when(system.getDefaultTimeZone()).thenReturn(TimeZone.getTimeZone("+01:00"));
when(system.now()).thenReturn(System.currentTimeMillis());
-
index = new IssueIndex(tester.client(), system, userSessionRule);
}
import javax.annotation.Nullable;
import org.assertj.core.api.Fail;
import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
public class IssueIndexTest {
- @ClassRule
- public static EsTester tester = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()), new ViewIndexDefinition(new Settings()));
+ @Rule
+ public EsTester tester = new EsTester(new IssueIndexDefinition(new Settings()), new ViewIndexDefinition(new Settings()));
+
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
@Before
public void setUp() {
- tester.truncateIndices();
issueIndexer = new IssueIndexer(null, tester.client());
issueAuthorizationIndexer = new IssueAuthorizationIndexer(null, tester.client());
viewIndexer = new ViewIndexer(null, tester.client());
import java.util.Collections;
import java.util.List;
import javax.annotation.Nonnull;
-import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
public class IssueIndexerTest {
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()));
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public EsTester esTester = new EsTester(new IssueIndexDefinition(new Settings()));
- @Before
- public void setUp() {
- dbTester.truncateTables();
- esTester.truncateIndices();
- }
+ @Rule
+ public DbTester dbTester = DbTester.create(System2.INSTANCE);
@Test
public void index_nothing() {
import org.assertj.core.data.Offset;
import org.junit.After;
import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
- @ClassRule
- public static EsTester es = new EsTester().addDefinitions(new UserIndexDefinition(new Settings()));
+ @Rule
+ public EsTester es = new EsTester(new UserIndexDefinition(new Settings()));
DbClient dbClient = db.getDbClient();
public void setUp() {
ws = new WsTester(new CustomMeasuresWs(new CreateAction(dbClient, userSession, System2.INSTANCE, new CustomMeasureValidator(newFullTypeValidations()),
new CustomMeasureJsonWriter(new UserJsonWriter(userSession)), new ComponentFinder(dbClient))));
- db.truncateTables();
userSession.login("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
db.getDbClient().userDao().insert(dbSession, new UserDto()
package org.sonar.server.measure.custom.ws;
import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
private static final String DEFAULT_PROJECT_UUID = "project-uuid";
private static final String DEFAULT_PROJECT_KEY = "project-key";
- @ClassRule
- public static EsTester es = new EsTester().addDefinitions(new UserIndexDefinition(new Settings()));
+ @Rule
+ public EsTester es = new EsTester(new UserIndexDefinition(new Settings()));
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Rule
WsTester ws;
ComponentDto defaultProject;
- @BeforeClass
- public static void setUpClass() throws Exception {
+ @Before
+ public void setUp() throws Exception {
es.putDocuments(UserIndexDefinition.INDEX, UserIndexDefinition.TYPE_USER, new UserDoc()
.setLogin("login")
.setName("Login")
.setEmail("login@login.com")
.setActive(true));
- }
-
- @Before
- public void setUp() {
ws = new WsTester(new CustomMeasuresWs(new MetricsAction(dbClient, userSession, new ComponentFinder(dbClient))));
userSession.login("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
defaultProject = insertDefaultProject();
import java.util.Date;
import org.apache.commons.lang.StringUtils;
import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
- @ClassRule
- public static EsTester es = new EsTester().addDefinitions(new UserIndexDefinition(new Settings()));
+ @Rule
+ public EsTester es = new EsTester(new UserIndexDefinition(new Settings()));
WsTester ws;
DbClient dbClient = db.getDbClient();
package org.sonar.server.measure.custom.ws;
import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
public UserSessionRule userSessionRule = UserSessionRule.standalone();
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
- @ClassRule
- public static EsTester es = new EsTester().addDefinitions(new UserIndexDefinition(new Settings()));
+ @Rule
+ public EsTester es = new EsTester(new UserIndexDefinition(new Settings()));
DbClient dbClient = db.getDbClient();
- final DbSession dbSession = db.getSession();
+ DbSession dbSession = db.getSession();
System2 system = mock(System2.class);
WsTester ws;
package org.sonar.server.platform;
import com.google.common.collect.ImmutableMap;
-import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
public class BackendCleanupMediumTest {
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(
+ @Rule
+ public EsTester esTester = new EsTester(
new RuleIndexDefinition(new Settings()),
new IssueIndexDefinition(new Settings()),
new ViewIndexDefinition(new Settings())
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
- BackendCleanup backendCleanup;
-
- @Before
- public void setUp() {
- backendCleanup = new BackendCleanup(esTester.client(), dbTester.myBatis());
- }
+ BackendCleanup backendCleanup = new BackendCleanup(esTester.client(), dbTester.myBatis());
@Test
public void clear_db() {
import java.util.Map;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
-import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
import org.sonar.server.es.EsTester;
public class EsMonitorTest {
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()));
+ @Rule
+ public EsTester esTester = new EsTester(new IssueIndexDefinition(new Settings()));
EsMonitor underTest = new EsMonitor(esTester.client());
import com.google.common.collect.ImmutableMap;
import java.util.Arrays;
import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
public class BulkDeleteActionTest {
private static final String ACTION = "bulk_delete";
+
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
- @ClassRule
- public static EsTester es = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()),
+ @Rule
+ public EsTester es = new EsTester(new IssueIndexDefinition(new Settings()),
new TestIndexDefinition(new Settings()));
@Rule
dbClient,
userSessionRule)));
userSessionRule.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
- db.truncateTables();
- es.truncateIndices();
}
@Test
import com.google.common.collect.ImmutableMap;
import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
- @ClassRule
- public static EsTester es = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()),
+ @Rule
+ public EsTester es = new EsTester(
+ new IssueIndexDefinition(new Settings()),
new TestIndexDefinition(new Settings()));
@Rule
dbClient,
userSessionRule)));
userSessionRule.login("login").setGlobalPermissions(UserRole.ADMIN);
- db.truncateTables();
- es.truncateIndices();
}
@Test
import java.util.List;
import java.util.Map;
import org.junit.Before;
-import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
import org.sonar.api.rule.RuleKey;
public class ActiveRuleIndexTest {
- static final RuleKey RULE_KEY_1 = RuleTesting.XOO_X1;
- static final RuleKey RULE_KEY_2 = RuleTesting.XOO_X2;
+ private static final RuleKey RULE_KEY_1 = RuleTesting.XOO_X1;
+ private static final RuleKey RULE_KEY_2 = RuleTesting.XOO_X2;
+ private static final String QUALITY_PROFILE_KEY1 = "qp1";
+ private static final String QUALITY_PROFILE_KEY2 = "qp2";
- static final String QUALITY_PROFILE_KEY1 = "qp1";
- static final String QUALITY_PROFILE_KEY2 = "qp2";
-
- @ClassRule
- public static EsTester tester = new EsTester().addDefinitions(new RuleIndexDefinition(new Settings()));
+ @Rule
+ public EsTester tester = new EsTester(new RuleIndexDefinition(new Settings()));
ActiveRuleIndex index;
-
ActiveRuleIndexer activeRuleIndexer;
RuleIndexer ruleIndexer;
@Before
public void setUp() {
- tester.truncateIndices();
activeRuleIndexer = new ActiveRuleIndexer(null, tester.client());
ruleIndexer = new RuleIndexer(null, tester.client());
index = new ActiveRuleIndex(tester.client());
import com.google.common.collect.Iterators;
import java.util.Arrays;
import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
static final String QUALITY_PROFILE_KEY1 = "qp1";
static final String QUALITY_PROFILE_KEY2 = "qp2";
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new RuleIndexDefinition(new Settings()));
+ @Rule
+ public EsTester esTester = new EsTester(new RuleIndexDefinition(new Settings()));
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
@Before
public void setUp() {
- esTester.truncateIndices();
indexer = new ActiveRuleIndexer(dbTester.getDbClient(), esTester.client());
indexer.setEnabled(true);
}
import java.util.Map;
import org.joda.time.DateTime;
import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new ActivityIndexDefinition(new Settings()));
+ @Rule
+ public EsTester esTester = new EsTester(new ActivityIndexDefinition(new Settings()));
private DbClient db = dbTester.getDbClient();
private DbSession dbSession = dbTester.getSession();
@Before
public void before() {
- dbTester.truncateTables();
- esTester.truncateIndices();
-
- System2 system = mock(System2.class);
-
// create pre-defined rules
RuleDto xooRule1 = RuleTesting.newXooX1().setSeverity("MINOR");
db.ruleDao().insert(dbSession, xooRule1);
import java.util.Date;
import java.util.List;
import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Test;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Language;
@org.junit.Rule
public DbTester dbTester = DbTester.create(system);
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new RuleIndexDefinition(new Settings()));
+ @org.junit.Rule
+ public EsTester esTester = new EsTester(new RuleIndexDefinition(new Settings()));
RuleActivator ruleActivator = mock(RuleActivator.class);
@Before
public void before() {
- esTester.truncateIndices();
when(system.now()).thenReturn(DATE1.getTime());
ruleIndexer = new RuleIndexer(dbClient, esTester.client());
ruleIndexer.setEnabled(true);
RuleIndexDefinition underTest = new RuleIndexDefinition(settings);
@Rule
- public EsTester tester = new EsTester().addDefinitions(underTest);
+ public EsTester tester = new EsTester(underTest);
@Test
public void test_definition_of_index() {
import java.util.List;
import java.util.Map;
import org.junit.Before;
-import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
import org.sonar.api.rule.RuleKey;
static final String QUALITY_PROFILE_KEY1 = "qp1";
static final String QUALITY_PROFILE_KEY2 = "qp2";
- @ClassRule
- public static EsTester tester = new EsTester().addDefinitions(new RuleIndexDefinition(new Settings()));
+ @Rule
+ public EsTester tester = new EsTester(new RuleIndexDefinition(new Settings()));
RuleIndex index;
-
RuleIndexer ruleIndexer;
ActiveRuleIndexer activeRuleIndexer;
@Before
public void setUp() {
- tester.truncateIndices();
ruleIndexer = new RuleIndexer(null, tester.client());
activeRuleIndexer = new ActiveRuleIndexer(null, tester.client());
index = new RuleIndex(tester.client());
package org.sonar.server.rule.index;
import com.google.common.collect.Iterators;
-import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
public class RuleIndexerTest {
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new RuleIndexDefinition(new Settings()));
+ @Rule
+ public EsTester esTester = new EsTester(new RuleIndexDefinition(new Settings()));
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
.setCreatedAt(1500000000000L)
.setUpdatedAt(1600000000000L);
- @Before
- public void setUp() {
- esTester.truncateIndices();
- }
-
@Test
public void index_nothing() {
RuleIndexer indexer = createIndexer();
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogram.Interval;
-import org.junit.Before;
-import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.DateUtils;
import org.sonar.server.es.EsTester;
private static final String FIELD_TAGS = "tags";
private static final String FIELD_CREATED_AT = "createdAt";
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new FacetsTestDefinition());
-
- @Before
- public void setUp() {
- esTester.truncateIndices();
- }
+ @Rule
+ public EsTester esTester = new EsTester(new FacetsTestDefinition());
@Test
public void should_ignore_result_without_aggregations() {
package org.sonar.server.startup;
import javax.annotation.Nullable;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
@Rule
public DbTester tester = DbTester.create(system2);
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new RuleIndexDefinition(new Settings()));
+ @Rule
+ public EsTester esTester = new EsTester(new RuleIndexDefinition(new Settings()));
@Rule
public LogTester logTester = new LogTester();
import com.google.common.base.Optional;
import java.util.Arrays;
import java.util.List;
-import org.junit.Before;
-import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
import org.sonar.server.es.EsTester;
import static org.assertj.guava.api.Assertions.assertThat;
public class TestIndexTest {
- @ClassRule
- public static EsTester es = new EsTester().addDefinitions(new TestIndexDefinition(new Settings()));
+ @Rule
+ public EsTester es = new EsTester(new TestIndexDefinition(new Settings()));
TestIndex underTest = new TestIndex(es.client());
- @Before
- public void setup() {
- es.truncateIndices();
- }
-
@Test
public void coveredFiles() throws Exception {
es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE,
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
public class TestIndexerTest {
- @ClassRule
- public static EsTester es = new EsTester().addDefinitions(new TestIndexDefinition(new Settings()));
+ @Rule
+ public EsTester es = new EsTester(new TestIndexDefinition(new Settings()));
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
- private TestIndexer underTest;
+ private TestIndexer underTest = new TestIndexer(db.getDbClient(), es.client());
@Before
public void setUp() {
- es.truncateIndices();
- db.truncateTables();
- underTest = new TestIndexer(db.getDbClient(), es.client());
underTest.setEnabled(true);
}
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
-
public class ListActionTest {
- @ClassRule
- public static EsTester es = new EsTester().addDefinitions(new TestIndexDefinition(new Settings()));
+ @Rule
+ public EsTester es = new EsTester(new TestIndexDefinition(new Settings()));
@Rule
public ExpectedException expectedException = ExpectedException.none();
+
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
+
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
+
DbClient dbClient = db.getDbClient();
TestIndex testIndex;
@Before
public void setUp() {
- db.truncateTables();
- es.truncateIndices();
testIndex = new TestIndex(es.client());
-
ws = new WsTester(new TestsWs(new ListAction(dbClient, testIndex, userSessionRule, new ComponentFinder(dbClient))));
}
import java.util.List;
import org.elasticsearch.search.SearchHit;
import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
static final String DEFAULT_LOGIN = "marius";
- @ClassRule
- public static EsTester es = new EsTester().addDefinitions(new UserIndexDefinition(new Settings()));
+ @Rule
+ public EsTester es = new EsTester(new UserIndexDefinition(new Settings()));
System2 system2 = mock(System2.class);
@Before
public void setUp() {
- es.truncateIndices();
-
userIndexer = (UserIndexer) new UserIndexer(dbClient, es.client()).setEnabled(true);
userUpdater = new UserUpdater(newUserNotifier, settings, dbClient,
userIndexer, system2);
import java.util.List;
import java.util.Locale;
import org.junit.Before;
-import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
import org.sonar.server.es.EsTester;
private static final long DATE_1 = 1_500_000_000_000L;
private static final long DATE_2 = 1_500_000_000_001L;
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new UserIndexDefinition(new Settings()));
+ @Rule
+ public EsTester esTester = new EsTester(new UserIndexDefinition(new Settings()));
private UserIndex index;
@Before
public void setUp() {
- esTester.truncateIndices();
index = new UserIndex(esTester.client());
}
package org.sonar.server.user.index;
import java.util.List;
-import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
import static org.assertj.core.api.Assertions.assertThat;
-
public class UserIndexerTest {
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new UserIndexDefinition(new Settings()));
-
- @Before
- public void setUp() {
- dbTester.truncateTables();
- esTester.truncateIndices();
- }
+ @Rule
+ public EsTester esTester = new EsTester(new UserIndexDefinition(new Settings()));
@Test
public void index_nothing() {
import org.junit.After;
import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
- @ClassRule
- public static final EsTester esTester = new EsTester().addDefinitions(new UserIndexDefinition(settings));
+ @Rule
+ public EsTester esTester = new EsTester(new UserIndexDefinition(settings));
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone().login("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
@Before
public void setUp() {
- dbTester.truncateTables();
- esTester.truncateIndices();
-
System2 system2 = new System2();
UserDao userDao = new UserDao(dbTester.myBatis(), system2);
UserGroupDao userGroupDao = new UserGroupDao();
import java.util.Locale;
import org.junit.After;
import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
public class CreateActionTest {
- static final Settings settings = new Settings().setProperty("sonar.defaultGroup", "sonar-users");
+ private static final Settings settings = new Settings().setProperty("sonar.defaultGroup", "sonar-users");
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
- @ClassRule
- public static final EsTester esTester = new EsTester().addDefinitions(new UserIndexDefinition(settings));
+ @Rule
+ public EsTester esTester = new EsTester(new UserIndexDefinition(settings));
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
@Before
public void setUp() {
- dbTester.truncateTables();
- esTester.truncateIndices();
-
System2 system2 = new System2();
UserDao userDao = new UserDao(dbTester.myBatis(), system2);
UserGroupDao userGroupDao = new UserGroupDao();
package org.sonar.server.user.ws;
import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
- @ClassRule
- public static final EsTester esTester = new EsTester().addDefinitions(new UserIndexDefinition(settings));
+
+ @Rule
+ public EsTester esTester = new EsTester(new UserIndexDefinition(settings));
+
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
UserIndex index;
DbClient dbClient;
UserIndexer userIndexer;
-
DbSession dbSession;
@Before
public void setUp() {
- esTester.truncateIndices();
-
System2 system2 = new System2();
UserDao userDao = new UserDao(db.myBatis(), system2);
dbClient = new DbClient(db.database(), db.myBatis(), userDao, new GroupMembershipDao(db.myBatis()), new UserTokenDao());
import com.google.common.collect.Lists;
import java.util.List;
import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
public class SearchActionTest {
- @ClassRule
- public static final EsTester esTester = new EsTester().addDefinitions(new UserIndexDefinition(new Settings()));
+ @Rule
+ public EsTester esTester = new EsTester(new UserIndexDefinition(new Settings()));
+
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
+
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
+
UserDbTester userDb = new UserDbTester(db);
GroupDbTester groupDb = new GroupDbTester(db);
DbClient dbClient = db.getDbClient();
- final DbSession dbSession = db.getSession();
+ DbSession dbSession = db.getSession();
WsTester ws;
UserIndex index;
@Before
public void setUp() {
- esTester.truncateIndices();
index = new UserIndex(esTester.client());
ws = new WsTester(new UsersWs(new SearchAction(index, dbClient, new UserJsonWriter(userSession))));
}
import org.junit.After;
import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
@Rule
public DbTester dbTester = DbTester.create(system2);
- @ClassRule
- public static final EsTester esTester = new EsTester().addDefinitions(new UserIndexDefinition(settings));
+ @Rule
+ public EsTester esTester = new EsTester(new UserIndexDefinition(settings));
@Rule
public final UserSessionRule userSessionRule = UserSessionRule.standalone().login("admin")
.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
@Before
public void setUp() {
- dbTester.truncateTables();
- esTester.truncateIndices();
-
dbClient.groupDao().insert(session, new GroupDto().setName("sonar-users"));
session.commit();
package org.sonar.server.view.index;
import java.util.List;
-import org.junit.Before;
-import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
import org.sonar.server.es.EsTester;
public class ViewIndexTest {
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new ViewIndexDefinition(new Settings()));
+ @Rule
+ public EsTester esTester = new EsTester(new ViewIndexDefinition(new Settings()));
- private ViewIndex index;
-
- @Before
- public void setUp() {
- esTester.truncateIndices();
- index = new ViewIndex(esTester.client());
- }
+ ViewIndex index = new ViewIndex(esTester.client());
@Test
public void find_all_view_uuids() throws Exception {
import com.google.common.collect.Maps;
import java.util.List;
import java.util.Map;
-import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
- @ClassRule
- public static EsTester esTester = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()), new ViewIndexDefinition(new Settings()));
+ @Rule
+ public EsTester esTester = new EsTester(new IssueIndexDefinition(new Settings()), new ViewIndexDefinition(new Settings()));
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
ViewIndexer indexer = (ViewIndexer) new ViewIndexer(dbClient, esTester.client()).setEnabled(true);
- @Before
- public void setUp() {
- dbTester.truncateTables();
- esTester.truncateIndices();
- }
-
@Test
public void index_nothing() {
indexer.index();