NOTICK NodeBasedTest take in cordapps (#6424)

In enterprise, `AuthDBTests` picked up a schema from a unit test and
included it in the cordapp it builds. This schema does not have a
migration and therefore fails the integration tests.

`NodeBasedTest` now lets cordapps to be defined and passed in to avoid
this issue. It defaults to making a cordapp from the tests base
directory if none are provided.
This commit is contained in:
Dan Newton 2020-07-02 16:14:51 +01:00 committed by GitHub
parent d97bc7dd12
commit 6bc2c79e23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 10 deletions

View File

@ -13,6 +13,7 @@ import net.corda.node.internal.NodeWithInfo;
import net.corda.testing.internal.InternalTestUtilsKt;
import net.corda.testing.node.User;
import net.corda.testing.node.internal.NodeBasedTest;
import net.corda.testing.node.internal.TestCordappInternal;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -30,10 +31,18 @@ import static net.corda.node.services.Permissions.invokeRpc;
import static net.corda.node.services.Permissions.startFlow;
import static net.corda.testing.core.TestConstants.ALICE_NAME;
import static net.corda.testing.core.TestConstants.DUMMY_NOTARY_NAME;
import static net.corda.testing.node.internal.InternalTestUtilsKt.FINANCE_CORDAPPS;
import static net.corda.testing.node.internal.InternalTestUtilsKt.cordappWithPackages;
public class CordaRPCJavaClientTest extends NodeBasedTest {
public CordaRPCJavaClientTest() {
super(Arrays.asList("net.corda.finance.contracts", CashSchemaV1.class.getPackage().getName()), Collections.singletonList(DUMMY_NOTARY_NAME));
super(cordapps(), Collections.singletonList(DUMMY_NOTARY_NAME));
}
private static Set<TestCordappInternal> cordapps() {
Set<TestCordappInternal> cordapps = new HashSet<>(FINANCE_CORDAPPS);
cordapps.add(cordappWithPackages(CashSchemaV1.class.getPackage().getName()));
return cordapps;
}
private List<String> perms = Arrays.asList(

View File

@ -40,6 +40,7 @@ import net.corda.testing.core.expect
import net.corda.testing.core.expectEvents
import net.corda.testing.core.sequence
import net.corda.testing.node.User
import net.corda.testing.node.internal.FINANCE_CORDAPPS
import net.corda.testing.node.internal.NodeBasedTest
import net.corda.testing.node.internal.ProcessUtilities
import net.corda.testing.node.internal.poll
@ -62,7 +63,7 @@ import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class CordaRPCClientTest : NodeBasedTest(listOf("net.corda.finance"), notaries = listOf(DUMMY_NOTARY_NAME)) {
class CordaRPCClientTest : NodeBasedTest(FINANCE_CORDAPPS, notaries = listOf(DUMMY_NOTARY_NAME)) {
companion object {
val rpcUser = User("user1", "test", permissions = setOf(all()))
val log = contextLogger()

View File

@ -2,9 +2,7 @@ package net.corda.client.rpc
import net.corda.core.context.Actor
import net.corda.core.context.Trace
import net.corda.core.internal.packageName
import net.corda.core.messaging.CordaRPCOps
import net.corda.finance.schemas.CashSchemaV1
import net.corda.node.internal.NodeWithInfo
import net.corda.node.services.Permissions
import net.corda.testing.core.ALICE_NAME
@ -14,7 +12,7 @@ import org.assertj.core.api.Assertions.assertThat
import org.junit.Before
import org.junit.Test
class FlowsExecutionModeTests : NodeBasedTest(emptyList()) {
class FlowsExecutionModeTests : NodeBasedTest() {
private val rpcUser = User("user1", "test", permissions = setOf(Permissions.all()))
private lateinit var node: NodeWithInfo

View File

@ -15,6 +15,7 @@ import net.corda.node.services.Permissions
import net.corda.node.services.config.PasswordEncryption
import net.corda.testing.core.ALICE_NAME
import net.corda.testing.node.internal.NodeBasedTest
import net.corda.testing.node.internal.cordappForClasses
import org.apache.activemq.artemis.api.core.ActiveMQSecurityException
import org.apache.shiro.authc.credential.DefaultPasswordService
import org.junit.After
@ -32,7 +33,7 @@ import kotlin.test.assertFailsWith
* check authentication/authorization of RPC connections.
*/
@RunWith(Parameterized::class)
class AuthDBTests : NodeBasedTest() {
class AuthDBTests : NodeBasedTest(cordappPackages = CORDAPPS) {
private lateinit var node: NodeWithInfo
private lateinit var client: CordaRPCClient
private lateinit var db: UsersDB
@ -43,6 +44,9 @@ class AuthDBTests : NodeBasedTest() {
@JvmStatic
@Parameterized.Parameters(name = "password encryption format = {0}")
fun encFormats() = arrayOf(PasswordEncryption.NONE, PasswordEncryption.SHIRO_1_CRYPT)
@Suppress("SpreadOperator")
private val CORDAPPS = setOf(cordappForClasses(*AuthDBTests::class.nestedClasses.map { it.java }.toTypedArray()))
}
@Suppress("MemberVisibilityCanBePrivate")

View File

@ -39,9 +39,10 @@ import kotlin.test.assertFalse
// TODO Some of the logic here duplicates what's in the driver - the reason why it's not straightforward to replace it by
// using DriverDSLImpl in `init()` and `stopAllNodes()` is because of the platform version passed to nodes (driver doesn't
// support this, and it's a property of the Corda JAR)
abstract class NodeBasedTest
@JvmOverloads
constructor(private val cordappPackages: List<String> = emptyList(), private val notaries: List<CordaX500Name> = emptyList()) {
abstract class NodeBasedTest @JvmOverloads constructor(
private val cordappPackages: Set<TestCordappInternal> = emptySet(),
private val notaries: List<CordaX500Name> = emptyList()
) {
companion object {
private val WHITESPACE = "\\s++".toRegex()
}
@ -120,7 +121,11 @@ constructor(private val cordappPackages: List<String> = emptyList(), private val
) + configOverrides
)
val customCordapps = cordappsForPackages(getCallerPackage(NodeBasedTest::class)?.let { cordappPackages + it } ?: cordappPackages)
val customCordapps = if (cordappPackages.isNotEmpty()) {
cordappPackages
} else {
cordappsForPackages(getCallerPackage(NodeBasedTest::class)?.let { listOf(it) } ?: emptyList())
}
TestCordappInternal.installCordapps(baseDirectory, emptySet(), customCordapps)
val parsedConfig = config.parseAsNodeConfiguration().value()