Replace GerritBaseTests#sanitizedMethodName with a TestRule

Use delegation to implement a new TestRule that wraps JUnit's TestName.
Avoids the need for inheriting from a base class just to use this
method.

Change-Id: Ia3d8487f9b3d65f62d8d1c815e4d009794af2779
This commit is contained in:
Dave Borowitz
2019-05-02 08:19:48 -07:00
parent 8add66e899
commit bbe05196fd
17 changed files with 121 additions and 33 deletions

View File

@@ -14,26 +14,11 @@
package com.google.gerrit.testing; package com.google.gerrit.testing;
import com.google.common.base.CharMatcher;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Rule; import org.junit.Rule;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.junit.rules.TestName;
@Ignore @Ignore
public abstract class GerritBaseTests { public abstract class GerritBaseTests {
@Rule public ExpectedException exception = ExpectedException.none(); @Rule public ExpectedException exception = ExpectedException.none();
@Rule public final TestName testName = new TestName();
protected String getSanitizedMethodName() {
String name = testName.getMethodName().toLowerCase();
name =
CharMatcher.inRange('a', 'z')
.or(CharMatcher.inRange('A', 'Z'))
.or(CharMatcher.inRange('0', '9'))
.negate()
.replaceFrom(name, '_');
name = CharMatcher.is('_').trimTrailingFrom(name);
return name;
}
} }

View File

@@ -0,0 +1,42 @@
// Copyright (C) 2019 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.testing;
import com.google.common.base.CharMatcher;
import org.junit.rules.TestName;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
public class GerritTestName implements TestRule {
private final TestName delegate = new TestName();
public String getSanitizedMethodName() {
String name = delegate.getMethodName().toLowerCase();
name =
CharMatcher.inRange('a', 'z')
.or(CharMatcher.inRange('A', 'Z'))
.or(CharMatcher.inRange('0', '9'))
.negate()
.replaceFrom(name, '_');
name = CharMatcher.is('_').trimTrailingFrom(name);
return name;
}
@Override
public Statement apply(Statement base, Description description) {
return delegate.apply(base, description);
}
}

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.elasticsearch;
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo; import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
import com.google.gerrit.server.query.account.AbstractQueryAccountsTest; import com.google.gerrit.server.query.account.AbstractQueryAccountsTest;
import com.google.gerrit.testing.ConfigSuite; import com.google.gerrit.testing.ConfigSuite;
import com.google.gerrit.testing.GerritTestName;
import com.google.gerrit.testing.InMemoryModule; import com.google.gerrit.testing.InMemoryModule;
import com.google.gerrit.testing.IndexConfig; import com.google.gerrit.testing.IndexConfig;
import com.google.inject.Guice; import com.google.inject.Guice;
@@ -24,6 +25,7 @@ import com.google.inject.Injector;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Rule;
public class ElasticV5QueryAccountsTest extends AbstractQueryAccountsTest { public class ElasticV5QueryAccountsTest extends AbstractQueryAccountsTest {
@ConfigSuite.Default @ConfigSuite.Default
@@ -52,6 +54,8 @@ public class ElasticV5QueryAccountsTest extends AbstractQueryAccountsTest {
} }
} }
@Rule public final GerritTestName testName = new GerritTestName();
@Override @Override
protected void initAfterLifecycleStart() throws Exception { protected void initAfterLifecycleStart() throws Exception {
super.initAfterLifecycleStart(); super.initAfterLifecycleStart();
@@ -62,7 +66,7 @@ public class ElasticV5QueryAccountsTest extends AbstractQueryAccountsTest {
protected Injector createInjector() { protected Injector createInjector() {
Config elasticsearchConfig = new Config(config); Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig); InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName(); String indicesPrefix = testName.getSanitizedMethodName();
ElasticTestUtils.configure( ElasticTestUtils.configure(
elasticsearchConfig, nodeInfo.port, indicesPrefix, ElasticVersion.V5_6); elasticsearchConfig, nodeInfo.port, indicesPrefix, ElasticVersion.V5_6);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig)); return Guice.createInjector(new InMemoryModule(elasticsearchConfig));

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.elasticsearch;
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo; import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
import com.google.gerrit.server.query.change.AbstractQueryChangesTest; import com.google.gerrit.server.query.change.AbstractQueryChangesTest;
import com.google.gerrit.testing.ConfigSuite; import com.google.gerrit.testing.ConfigSuite;
import com.google.gerrit.testing.GerritTestName;
import com.google.gerrit.testing.InMemoryModule; import com.google.gerrit.testing.InMemoryModule;
import com.google.gerrit.testing.IndexConfig; import com.google.gerrit.testing.IndexConfig;
import com.google.inject.Guice; import com.google.inject.Guice;
@@ -24,6 +25,7 @@ import com.google.inject.Injector;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Rule;
public class ElasticV5QueryChangesTest extends AbstractQueryChangesTest { public class ElasticV5QueryChangesTest extends AbstractQueryChangesTest {
@ConfigSuite.Default @ConfigSuite.Default
@@ -52,6 +54,8 @@ public class ElasticV5QueryChangesTest extends AbstractQueryChangesTest {
} }
} }
@Rule public final GerritTestName testName = new GerritTestName();
@Override @Override
protected void initAfterLifecycleStart() throws Exception { protected void initAfterLifecycleStart() throws Exception {
super.initAfterLifecycleStart(); super.initAfterLifecycleStart();
@@ -62,7 +66,7 @@ public class ElasticV5QueryChangesTest extends AbstractQueryChangesTest {
protected Injector createInjector() { protected Injector createInjector() {
Config elasticsearchConfig = new Config(config); Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig); InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName(); String indicesPrefix = testName.getSanitizedMethodName();
ElasticTestUtils.configure( ElasticTestUtils.configure(
elasticsearchConfig, nodeInfo.port, indicesPrefix, ElasticVersion.V5_6); elasticsearchConfig, nodeInfo.port, indicesPrefix, ElasticVersion.V5_6);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig)); return Guice.createInjector(new InMemoryModule(elasticsearchConfig));

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.elasticsearch;
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo; import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
import com.google.gerrit.server.query.group.AbstractQueryGroupsTest; import com.google.gerrit.server.query.group.AbstractQueryGroupsTest;
import com.google.gerrit.testing.ConfigSuite; import com.google.gerrit.testing.ConfigSuite;
import com.google.gerrit.testing.GerritTestName;
import com.google.gerrit.testing.InMemoryModule; import com.google.gerrit.testing.InMemoryModule;
import com.google.gerrit.testing.IndexConfig; import com.google.gerrit.testing.IndexConfig;
import com.google.inject.Guice; import com.google.inject.Guice;
@@ -24,6 +25,7 @@ import com.google.inject.Injector;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Rule;
public class ElasticV5QueryGroupsTest extends AbstractQueryGroupsTest { public class ElasticV5QueryGroupsTest extends AbstractQueryGroupsTest {
@ConfigSuite.Default @ConfigSuite.Default
@@ -52,6 +54,8 @@ public class ElasticV5QueryGroupsTest extends AbstractQueryGroupsTest {
} }
} }
@Rule public final GerritTestName testName = new GerritTestName();
@Override @Override
protected void initAfterLifecycleStart() throws Exception { protected void initAfterLifecycleStart() throws Exception {
super.initAfterLifecycleStart(); super.initAfterLifecycleStart();
@@ -62,7 +66,7 @@ public class ElasticV5QueryGroupsTest extends AbstractQueryGroupsTest {
protected Injector createInjector() { protected Injector createInjector() {
Config elasticsearchConfig = new Config(config); Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig); InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName(); String indicesPrefix = testName.getSanitizedMethodName();
ElasticTestUtils.configure( ElasticTestUtils.configure(
elasticsearchConfig, nodeInfo.port, indicesPrefix, ElasticVersion.V5_6); elasticsearchConfig, nodeInfo.port, indicesPrefix, ElasticVersion.V5_6);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig)); return Guice.createInjector(new InMemoryModule(elasticsearchConfig));

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.elasticsearch;
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo; import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
import com.google.gerrit.server.query.project.AbstractQueryProjectsTest; import com.google.gerrit.server.query.project.AbstractQueryProjectsTest;
import com.google.gerrit.testing.ConfigSuite; import com.google.gerrit.testing.ConfigSuite;
import com.google.gerrit.testing.GerritTestName;
import com.google.gerrit.testing.InMemoryModule; import com.google.gerrit.testing.InMemoryModule;
import com.google.gerrit.testing.IndexConfig; import com.google.gerrit.testing.IndexConfig;
import com.google.inject.Guice; import com.google.inject.Guice;
@@ -24,6 +25,7 @@ import com.google.inject.Injector;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Rule;
public class ElasticV5QueryProjectsTest extends AbstractQueryProjectsTest { public class ElasticV5QueryProjectsTest extends AbstractQueryProjectsTest {
@ConfigSuite.Default @ConfigSuite.Default
@@ -58,11 +60,13 @@ public class ElasticV5QueryProjectsTest extends AbstractQueryProjectsTest {
ElasticTestUtils.createAllIndexes(injector); ElasticTestUtils.createAllIndexes(injector);
} }
@Rule public final GerritTestName testName = new GerritTestName();
@Override @Override
protected Injector createInjector() { protected Injector createInjector() {
Config elasticsearchConfig = new Config(config); Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig); InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName(); String indicesPrefix = testName.getSanitizedMethodName();
ElasticTestUtils.configure( ElasticTestUtils.configure(
elasticsearchConfig, nodeInfo.port, indicesPrefix, ElasticVersion.V5_6); elasticsearchConfig, nodeInfo.port, indicesPrefix, ElasticVersion.V5_6);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig)); return Guice.createInjector(new InMemoryModule(elasticsearchConfig));

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.elasticsearch;
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo; import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
import com.google.gerrit.server.query.account.AbstractQueryAccountsTest; import com.google.gerrit.server.query.account.AbstractQueryAccountsTest;
import com.google.gerrit.testing.ConfigSuite; import com.google.gerrit.testing.ConfigSuite;
import com.google.gerrit.testing.GerritTestName;
import com.google.gerrit.testing.InMemoryModule; import com.google.gerrit.testing.InMemoryModule;
import com.google.gerrit.testing.IndexConfig; import com.google.gerrit.testing.IndexConfig;
import com.google.inject.Guice; import com.google.inject.Guice;
@@ -24,6 +25,7 @@ import com.google.inject.Injector;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Rule;
public class ElasticV6QueryAccountsTest extends AbstractQueryAccountsTest { public class ElasticV6QueryAccountsTest extends AbstractQueryAccountsTest {
@ConfigSuite.Default @ConfigSuite.Default
@@ -52,6 +54,8 @@ public class ElasticV6QueryAccountsTest extends AbstractQueryAccountsTest {
} }
} }
@Rule public final GerritTestName testName = new GerritTestName();
@Override @Override
protected void initAfterLifecycleStart() throws Exception { protected void initAfterLifecycleStart() throws Exception {
super.initAfterLifecycleStart(); super.initAfterLifecycleStart();
@@ -62,7 +66,7 @@ public class ElasticV6QueryAccountsTest extends AbstractQueryAccountsTest {
protected Injector createInjector() { protected Injector createInjector() {
Config elasticsearchConfig = new Config(config); Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig); InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName(); String indicesPrefix = testName.getSanitizedMethodName();
ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix); ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig)); return Guice.createInjector(new InMemoryModule(elasticsearchConfig));
} }

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.elasticsearch;
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo; import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
import com.google.gerrit.server.query.change.AbstractQueryChangesTest; import com.google.gerrit.server.query.change.AbstractQueryChangesTest;
import com.google.gerrit.testing.ConfigSuite; import com.google.gerrit.testing.ConfigSuite;
import com.google.gerrit.testing.GerritTestName;
import com.google.gerrit.testing.InMemoryModule; import com.google.gerrit.testing.InMemoryModule;
import com.google.gerrit.testing.IndexConfig; import com.google.gerrit.testing.IndexConfig;
import com.google.inject.Guice; import com.google.inject.Guice;
@@ -24,6 +25,7 @@ import com.google.inject.Injector;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Rule;
public class ElasticV6QueryChangesTest extends AbstractQueryChangesTest { public class ElasticV6QueryChangesTest extends AbstractQueryChangesTest {
@ConfigSuite.Default @ConfigSuite.Default
@@ -52,6 +54,8 @@ public class ElasticV6QueryChangesTest extends AbstractQueryChangesTest {
} }
} }
@Rule public final GerritTestName testName = new GerritTestName();
@Override @Override
protected void initAfterLifecycleStart() throws Exception { protected void initAfterLifecycleStart() throws Exception {
super.initAfterLifecycleStart(); super.initAfterLifecycleStart();
@@ -62,7 +66,7 @@ public class ElasticV6QueryChangesTest extends AbstractQueryChangesTest {
protected Injector createInjector() { protected Injector createInjector() {
Config elasticsearchConfig = new Config(config); Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig); InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName(); String indicesPrefix = testName.getSanitizedMethodName();
ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix); ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig)); return Guice.createInjector(new InMemoryModule(elasticsearchConfig));
} }

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.elasticsearch;
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo; import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
import com.google.gerrit.server.query.group.AbstractQueryGroupsTest; import com.google.gerrit.server.query.group.AbstractQueryGroupsTest;
import com.google.gerrit.testing.ConfigSuite; import com.google.gerrit.testing.ConfigSuite;
import com.google.gerrit.testing.GerritTestName;
import com.google.gerrit.testing.InMemoryModule; import com.google.gerrit.testing.InMemoryModule;
import com.google.gerrit.testing.IndexConfig; import com.google.gerrit.testing.IndexConfig;
import com.google.inject.Guice; import com.google.inject.Guice;
@@ -24,6 +25,7 @@ import com.google.inject.Injector;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Rule;
public class ElasticV6QueryGroupsTest extends AbstractQueryGroupsTest { public class ElasticV6QueryGroupsTest extends AbstractQueryGroupsTest {
@ConfigSuite.Default @ConfigSuite.Default
@@ -52,6 +54,8 @@ public class ElasticV6QueryGroupsTest extends AbstractQueryGroupsTest {
} }
} }
@Rule public final GerritTestName testName = new GerritTestName();
@Override @Override
protected void initAfterLifecycleStart() throws Exception { protected void initAfterLifecycleStart() throws Exception {
super.initAfterLifecycleStart(); super.initAfterLifecycleStart();
@@ -62,7 +66,7 @@ public class ElasticV6QueryGroupsTest extends AbstractQueryGroupsTest {
protected Injector createInjector() { protected Injector createInjector() {
Config elasticsearchConfig = new Config(config); Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig); InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName(); String indicesPrefix = testName.getSanitizedMethodName();
ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix); ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig)); return Guice.createInjector(new InMemoryModule(elasticsearchConfig));
} }

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.elasticsearch;
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo; import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
import com.google.gerrit.server.query.project.AbstractQueryProjectsTest; import com.google.gerrit.server.query.project.AbstractQueryProjectsTest;
import com.google.gerrit.testing.ConfigSuite; import com.google.gerrit.testing.ConfigSuite;
import com.google.gerrit.testing.GerritTestName;
import com.google.gerrit.testing.InMemoryModule; import com.google.gerrit.testing.InMemoryModule;
import com.google.gerrit.testing.IndexConfig; import com.google.gerrit.testing.IndexConfig;
import com.google.inject.Guice; import com.google.inject.Guice;
@@ -24,6 +25,7 @@ import com.google.inject.Injector;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Rule;
public class ElasticV6QueryProjectsTest extends AbstractQueryProjectsTest { public class ElasticV6QueryProjectsTest extends AbstractQueryProjectsTest {
@ConfigSuite.Default @ConfigSuite.Default
@@ -52,6 +54,8 @@ public class ElasticV6QueryProjectsTest extends AbstractQueryProjectsTest {
} }
} }
@Rule public final GerritTestName testName = new GerritTestName();
@Override @Override
protected void initAfterLifecycleStart() throws Exception { protected void initAfterLifecycleStart() throws Exception {
super.initAfterLifecycleStart(); super.initAfterLifecycleStart();
@@ -62,7 +66,7 @@ public class ElasticV6QueryProjectsTest extends AbstractQueryProjectsTest {
protected Injector createInjector() { protected Injector createInjector() {
Config elasticsearchConfig = new Config(config); Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig); InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName(); String indicesPrefix = testName.getSanitizedMethodName();
ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix); ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig)); return Guice.createInjector(new InMemoryModule(elasticsearchConfig));
} }

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.elasticsearch;
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo; import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
import com.google.gerrit.server.query.account.AbstractQueryAccountsTest; import com.google.gerrit.server.query.account.AbstractQueryAccountsTest;
import com.google.gerrit.testing.ConfigSuite; import com.google.gerrit.testing.ConfigSuite;
import com.google.gerrit.testing.GerritTestName;
import com.google.gerrit.testing.InMemoryModule; import com.google.gerrit.testing.InMemoryModule;
import com.google.gerrit.testing.IndexConfig; import com.google.gerrit.testing.IndexConfig;
import com.google.inject.Guice; import com.google.inject.Guice;
@@ -24,6 +25,7 @@ import com.google.inject.Injector;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Rule;
public class ElasticV7QueryAccountsTest extends AbstractQueryAccountsTest { public class ElasticV7QueryAccountsTest extends AbstractQueryAccountsTest {
@ConfigSuite.Default @ConfigSuite.Default
@@ -52,6 +54,8 @@ public class ElasticV7QueryAccountsTest extends AbstractQueryAccountsTest {
} }
} }
@Rule public final GerritTestName testName = new GerritTestName();
@Override @Override
protected void initAfterLifecycleStart() throws Exception { protected void initAfterLifecycleStart() throws Exception {
super.initAfterLifecycleStart(); super.initAfterLifecycleStart();
@@ -62,7 +66,7 @@ public class ElasticV7QueryAccountsTest extends AbstractQueryAccountsTest {
protected Injector createInjector() { protected Injector createInjector() {
Config elasticsearchConfig = new Config(config); Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig); InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName(); String indicesPrefix = testName.getSanitizedMethodName();
ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix); ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig)); return Guice.createInjector(new InMemoryModule(elasticsearchConfig));
} }

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.elasticsearch;
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo; import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
import com.google.gerrit.server.query.change.AbstractQueryChangesTest; import com.google.gerrit.server.query.change.AbstractQueryChangesTest;
import com.google.gerrit.testing.ConfigSuite; import com.google.gerrit.testing.ConfigSuite;
import com.google.gerrit.testing.GerritTestName;
import com.google.gerrit.testing.InMemoryModule; import com.google.gerrit.testing.InMemoryModule;
import com.google.gerrit.testing.IndexConfig; import com.google.gerrit.testing.IndexConfig;
import com.google.inject.Guice; import com.google.inject.Guice;
@@ -29,6 +30,7 @@ import org.eclipse.jgit.lib.Config;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Rule;
public class ElasticV7QueryChangesTest extends AbstractQueryChangesTest { public class ElasticV7QueryChangesTest extends AbstractQueryChangesTest {
@ConfigSuite.Default @ConfigSuite.Default
@@ -60,12 +62,15 @@ public class ElasticV7QueryChangesTest extends AbstractQueryChangesTest {
} }
} }
@Rule public final GerritTestName testName = new GerritTestName();
@After @After
public void closeIndex() { public void closeIndex() {
client.execute( client.execute(
new HttpPost( new HttpPost(
String.format( String.format(
"http://localhost:%d/%s*/_close", nodeInfo.port, getSanitizedMethodName())), "http://localhost:%d/%s*/_close",
nodeInfo.port, testName.getSanitizedMethodName())),
HttpClientContext.create(), HttpClientContext.create(),
null); null);
} }
@@ -80,7 +85,7 @@ public class ElasticV7QueryChangesTest extends AbstractQueryChangesTest {
protected Injector createInjector() { protected Injector createInjector() {
Config elasticsearchConfig = new Config(config); Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig); InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName(); String indicesPrefix = testName.getSanitizedMethodName();
ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix); ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig)); return Guice.createInjector(new InMemoryModule(elasticsearchConfig));
} }

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.elasticsearch;
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo; import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
import com.google.gerrit.server.query.group.AbstractQueryGroupsTest; import com.google.gerrit.server.query.group.AbstractQueryGroupsTest;
import com.google.gerrit.testing.ConfigSuite; import com.google.gerrit.testing.ConfigSuite;
import com.google.gerrit.testing.GerritTestName;
import com.google.gerrit.testing.InMemoryModule; import com.google.gerrit.testing.InMemoryModule;
import com.google.gerrit.testing.IndexConfig; import com.google.gerrit.testing.IndexConfig;
import com.google.inject.Guice; import com.google.inject.Guice;
@@ -24,6 +25,7 @@ import com.google.inject.Injector;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Rule;
public class ElasticV7QueryGroupsTest extends AbstractQueryGroupsTest { public class ElasticV7QueryGroupsTest extends AbstractQueryGroupsTest {
@ConfigSuite.Default @ConfigSuite.Default
@@ -52,6 +54,8 @@ public class ElasticV7QueryGroupsTest extends AbstractQueryGroupsTest {
} }
} }
@Rule public final GerritTestName testName = new GerritTestName();
@Override @Override
protected void initAfterLifecycleStart() throws Exception { protected void initAfterLifecycleStart() throws Exception {
super.initAfterLifecycleStart(); super.initAfterLifecycleStart();
@@ -62,7 +66,7 @@ public class ElasticV7QueryGroupsTest extends AbstractQueryGroupsTest {
protected Injector createInjector() { protected Injector createInjector() {
Config elasticsearchConfig = new Config(config); Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig); InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName(); String indicesPrefix = testName.getSanitizedMethodName();
ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix); ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig)); return Guice.createInjector(new InMemoryModule(elasticsearchConfig));
} }

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.elasticsearch;
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo; import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
import com.google.gerrit.server.query.project.AbstractQueryProjectsTest; import com.google.gerrit.server.query.project.AbstractQueryProjectsTest;
import com.google.gerrit.testing.ConfigSuite; import com.google.gerrit.testing.ConfigSuite;
import com.google.gerrit.testing.GerritTestName;
import com.google.gerrit.testing.InMemoryModule; import com.google.gerrit.testing.InMemoryModule;
import com.google.gerrit.testing.IndexConfig; import com.google.gerrit.testing.IndexConfig;
import com.google.inject.Guice; import com.google.inject.Guice;
@@ -24,6 +25,7 @@ import com.google.inject.Injector;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Rule;
public class ElasticV7QueryProjectsTest extends AbstractQueryProjectsTest { public class ElasticV7QueryProjectsTest extends AbstractQueryProjectsTest {
@ConfigSuite.Default @ConfigSuite.Default
@@ -52,6 +54,8 @@ public class ElasticV7QueryProjectsTest extends AbstractQueryProjectsTest {
} }
} }
@Rule public final GerritTestName testName = new GerritTestName();
@Override @Override
protected void initAfterLifecycleStart() throws Exception { protected void initAfterLifecycleStart() throws Exception {
super.initAfterLifecycleStart(); super.initAfterLifecycleStart();
@@ -62,7 +66,7 @@ public class ElasticV7QueryProjectsTest extends AbstractQueryProjectsTest {
protected Injector createInjector() { protected Injector createInjector() {
Config elasticsearchConfig = new Config(config); Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig); InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = getSanitizedMethodName(); String indicesPrefix = testName.getSanitizedMethodName();
ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix); ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig)); return Guice.createInjector(new InMemoryModule(elasticsearchConfig));
} }

View File

@@ -80,6 +80,7 @@ import com.google.gerrit.server.util.OneOffRequestContext;
import com.google.gerrit.server.util.RequestContext; import com.google.gerrit.server.util.RequestContext;
import com.google.gerrit.server.util.ThreadLocalRequestContext; import com.google.gerrit.server.util.ThreadLocalRequestContext;
import com.google.gerrit.testing.GerritServerTests; import com.google.gerrit.testing.GerritServerTests;
import com.google.gerrit.testing.GerritTestName;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Provider; import com.google.inject.Provider;
@@ -94,10 +95,13 @@ import org.eclipse.jgit.lib.Repository;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@Ignore @Ignore
public abstract class AbstractQueryAccountsTest extends GerritServerTests { public abstract class AbstractQueryAccountsTest extends GerritServerTests {
@Rule public final GerritTestName testName = new GerritTestName();
@Inject protected Accounts accounts; @Inject protected Accounts accounts;
@Inject @ServerInitiated protected Provider<AccountsUpdate> accountsUpdate; @Inject @ServerInitiated protected Provider<AccountsUpdate> accountsUpdate;
@@ -751,7 +755,7 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
return null; return null;
} }
String suffix = getSanitizedMethodName(); String suffix = testName.getSanitizedMethodName();
if (name.contains("@")) { if (name.contains("@")) {
return name + "." + suffix; return name + "." + suffix;
} }

View File

@@ -58,6 +58,7 @@ import com.google.gerrit.server.util.OneOffRequestContext;
import com.google.gerrit.server.util.RequestContext; import com.google.gerrit.server.util.RequestContext;
import com.google.gerrit.server.util.ThreadLocalRequestContext; import com.google.gerrit.server.util.ThreadLocalRequestContext;
import com.google.gerrit.testing.GerritServerTests; import com.google.gerrit.testing.GerritServerTests;
import com.google.gerrit.testing.GerritTestName;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Provider; import com.google.inject.Provider;
@@ -69,10 +70,13 @@ import java.util.Optional;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@Ignore @Ignore
public abstract class AbstractQueryGroupsTest extends GerritServerTests { public abstract class AbstractQueryGroupsTest extends GerritServerTests {
@Rule public final GerritTestName testName = new GerritTestName();
@Inject protected Accounts accounts; @Inject protected Accounts accounts;
@Inject @ServerInitiated protected Provider<AccountsUpdate> accountsUpdate; @Inject @ServerInitiated protected Provider<AccountsUpdate> accountsUpdate;
@@ -185,7 +189,7 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
@Test @Test
public void byInname() throws Exception { public void byInname() throws Exception {
String namePart = getSanitizedMethodName(); String namePart = testName.getSanitizedMethodName();
namePart = CharMatcher.is('_').removeFrom(namePart); namePart = CharMatcher.is('_').removeFrom(namePart);
GroupInfo group1 = createGroup("group-" + namePart); GroupInfo group1 = createGroup("group-" + namePart);
@@ -536,7 +540,7 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
return null; return null;
} }
return name + "_" + getSanitizedMethodName(); return name + "_" + testName.getSanitizedMethodName();
} }
protected int getSchemaVersion() { protected int getSchemaVersion() {

View File

@@ -57,6 +57,7 @@ import com.google.gerrit.server.util.OneOffRequestContext;
import com.google.gerrit.server.util.RequestContext; import com.google.gerrit.server.util.RequestContext;
import com.google.gerrit.server.util.ThreadLocalRequestContext; import com.google.gerrit.server.util.ThreadLocalRequestContext;
import com.google.gerrit.testing.GerritServerTests; import com.google.gerrit.testing.GerritServerTests;
import com.google.gerrit.testing.GerritTestName;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Provider; import com.google.inject.Provider;
@@ -68,10 +69,13 @@ import java.util.Set;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@Ignore @Ignore
public abstract class AbstractQueryProjectsTest extends GerritServerTests { public abstract class AbstractQueryProjectsTest extends GerritServerTests {
@Rule public final GerritTestName testName = new GerritTestName();
@Inject protected Accounts accounts; @Inject protected Accounts accounts;
@Inject @ServerInitiated protected Provider<AccountsUpdate> accountsUpdate; @Inject @ServerInitiated protected Provider<AccountsUpdate> accountsUpdate;
@@ -185,7 +189,7 @@ public abstract class AbstractQueryProjectsTest extends GerritServerTests {
@Test @Test
public void byInname() throws Exception { public void byInname() throws Exception {
String namePart = getSanitizedMethodName(); String namePart = testName.getSanitizedMethodName();
namePart = CharMatcher.is('_').removeFrom(namePart); namePart = CharMatcher.is('_').removeFrom(namePart);
ProjectInfo project1 = createProject(name("project1-" + namePart)); ProjectInfo project1 = createProject(name("project1-" + namePart));
@@ -443,6 +447,6 @@ public abstract class AbstractQueryProjectsTest extends GerritServerTests {
return null; return null;
} }
return name + "_" + getSanitizedMethodName(); return name + "_" + testName.getSanitizedMethodName();
} }
} }