mirror of
https://github.com/google/nomulus.git
synced 2025-04-29 19:47:51 +02:00
Verify RegistryTool can instantiate (#400)
* Verify RegistryTool can instantiate Add a task that instantiates all command classes in RegistryTool with runtimeClasspath. Also make sure that runtimeClasspath is a superset of compileClasspath.
This commit is contained in:
parent
dc88b770da
commit
697a45c855
4 changed files with 36 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<String, ? extends Class<? extends Command>> entry : commands.entrySet()) {
|
||||
Command command = entry.getValue().getDeclaredConstructor().newInstance();
|
||||
|
|
|
@ -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'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue