diff --git a/core/build.gradle b/core/build.gradle index 8cbced662..32668a2cc 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +import java.lang.reflect.Constructor + plugins { id 'java-library' } @@ -660,6 +662,33 @@ task outcastTest(type: FilteringTest) { maxParallelForks 5 } +// Whitebox test verifying that RegistryTool can be instantiated. Note the +// use of runtimeClasspath. This test emulates the logic in RegistryCli#run. +// A to-do is added there to refactor. +// TODO(weiminyu): Need a similar test for Registry server. +task registryToolIntegrationTest { + dependsOn compileJava + doLast { + def classLoader = + new URLClassLoader(sourceSets.main.runtimeClasspath.collect { + it.toURI().toURL() + } as URL[]) + def commandClasses = + (classLoader.loadClass('google.registry.tools.RegistryTool') + .getDeclaredField('COMMAND_MAP').get(null) as Map).values() + + commandClasses.each { + try { + Constructor c = ((Class) it).getDeclaredConstructor() + c.setAccessible(true) + c.newInstance() + } catch (Throwable e) { + throw new RuntimeException("Failed to instantiate ${it}:\n ${e}") + } + } + } +} + // Dedicated test suite for schema-dependent tests. task sqlIntegrationTest(type: FilteringTest) { systemProperties project.getProperties().subMap('sql_schema_resource_root') @@ -779,7 +808,7 @@ test { // Don't run any tests from this task, all testing gets done in the // FilteringTest tasks. exclude "**" -}.dependsOn(fragileTest, outcastTest, standardTest) +}.dependsOn(fragileTest, outcastTest, standardTest, registryToolIntegrationTest) createUberJar('nomulus', 'nomulus', 'google.registry.tools.RegistryTool') project.nomulus.dependsOn project(':third_party').jar diff --git a/core/gradle/dependency-locks/compileClasspath.lockfile b/core/gradle/dependency-locks/compileClasspath.lockfile index 619076b60..b845be83b 100644 --- a/core/gradle/dependency-locks/compileClasspath.lockfile +++ b/core/gradle/dependency-locks/compileClasspath.lockfile @@ -205,7 +205,6 @@ org.jetbrains:annotations:17.0.0 org.joda:joda-money:1.0.1 org.json:json:20160810 org.jvnet.staxex:stax-ex:1.8 -org.mockito:mockito-core:1.9.5 org.mortbay.jetty:jetty-util:6.1.26 org.mortbay.jetty:jetty:6.1.26 org.objenesis:objenesis:1.2 diff --git a/core/src/main/java/google/registry/tools/RegistryCli.java b/core/src/main/java/google/registry/tools/RegistryCli.java index 0b21014c7..4fb7ede2f 100644 --- a/core/src/main/java/google/registry/tools/RegistryCli.java +++ b/core/src/main/java/google/registry/tools/RegistryCli.java @@ -104,6 +104,8 @@ final class RegistryCli implements AutoCloseable, CommandRunner { // Create all command instances. It would be preferrable to do this in the constructor, but // JCommander mutates the command instances and doesn't reset them so we have to do it for every // run. + // TODO(weiminyu): extract this into a standalone static method to simplify + // :core:registryToolIntegrationTest try { for (Map.Entry> entry : commands.entrySet()) { Command command = entry.getValue().getDeclaredConstructor().newInstance(); diff --git a/java_common.gradle b/java_common.gradle index 6acd4ff6a..1f19579e9 100644 --- a/java_common.gradle +++ b/java_common.gradle @@ -54,7 +54,9 @@ tasks.test.finalizedBy jacocoTestReport configurations { deploy_jar.extendsFrom runtimeClasspath - runtimeClasspath { + all.findAll { + it.name in ['runtimeClasspath', 'compileClasspath'] + }.each { // JUnit is from org.apache.beam:beam-runners-google-cloud-dataflow-java, // testcontainer (which we use in the nomulus tool), and json-simple. // We should really be excluding this, however GenerateSqlCommand in @@ -62,7 +64,7 @@ configurations { //exclude group: 'junit' // Mockito is from org.apache.beam:beam-runners-google-cloud-dataflow-java // See https://issues.apache.org/jira/browse/BEAM-8862 - exclude group: 'org.mockito', module: 'mockito-core' + it.exclude group: 'org.mockito', module: 'mockito-core' } }