Merge pull request #7647 from corda/bk/jd17_fixes_15_jan

ENT-11113 Test case no longer using reflection to change final modifier on node logger
This commit is contained in:
Adel El-Beik 2024-01-18 12:24:03 +00:00 committed by GitHub
commit 4b92233cdd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,24 +2,19 @@ package net.corda.node.services.config
import com.typesafe.config.Config import com.typesafe.config.Config
import com.typesafe.config.ConfigFactory import com.typesafe.config.ConfigFactory
import net.corda.node.internal.Node
import org.assertj.core.api.Assertions.assertThatExceptionOfType import org.assertj.core.api.Assertions.assertThatExceptionOfType
import org.junit.After import org.junit.After
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.Before
import org.junit.Ignore
import org.junit.Test import org.junit.Test
import org.mockito.ArgumentMatchers.contains import java.io.ByteArrayOutputStream
import org.mockito.kotlin.spy import java.io.PrintStream
import org.mockito.kotlin.verify
import org.slf4j.Logger
import java.lang.reflect.Field
import java.lang.reflect.Modifier
import java.nio.file.Files import java.nio.file.Files
import java.nio.file.Path import java.nio.file.Path
import kotlin.io.path.deleteExisting import kotlin.io.path.deleteExisting
import kotlin.io.path.div import kotlin.io.path.div
import kotlin.test.assertFalse import kotlin.test.assertFalse
import kotlin.test.assertTrue
class ConfigHelperTests { class ConfigHelperTests {
private var baseDir: Path? = null private var baseDir: Path? = null
@ -70,24 +65,19 @@ class ConfigHelperTests {
} }
} }
@Test(timeout = 300_000) @Test(timeout = 300_000)
@Ignore("TODO JDK17: Modifiers no longer supported")
fun `bad keys are ignored and warned for`() { fun `bad keys are ignored and warned for`() {
val loggerField = Node::class.java.getDeclaredField("staticLog") val originalOut = System.out
loggerField.isAccessible = true try {
val modifiersField = Field::class.java.getDeclaredField("modifiers") val outContent = ByteArrayOutputStream()
modifiersField.isAccessible = true System.setOut(PrintStream(outContent));
modifiersField.setInt(loggerField, loggerField.modifiers and Modifier.FINAL.inv())
val originalLogger = loggerField.get(null) as Logger
val spyLogger = spy(originalLogger)
loggerField.set(null, spyLogger)
val config = loadConfig("corda_bad_key" to "2077") val config = loadConfig("corda_bad_key" to "2077")
assertTrue(outContent.toString().contains("(property or environment variable) cannot be mapped to an existing Corda"))
verify(spyLogger).warn(contains("(property or environment variable) cannot be mapped to an existing Corda"))
assertFalse(config?.hasPath("corda_bad_key") ?: true) assertFalse(config?.hasPath("corda_bad_key") ?: true)
} finally {
loggerField.set(null, originalLogger) System.setOut(originalOut);
}
} }
/** /**