Skip to content

Nikita tkachenko/junit 6 #9264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions dd-java-agent/agent-ci-visibility/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ buildscript {

plugins {
id 'com.gradleup.shadow'
id 'java-test-fixtures'
}

apply from: "$rootDir/gradle/java.gradle"
Expand All @@ -39,28 +38,23 @@ dependencies {
api libs.slf4j

implementation libs.bundles.asm
implementation group: 'org.jacoco', name: 'org.jacoco.core', version: '0.8.12'
implementation group: 'org.jacoco', name: 'org.jacoco.report', version: '0.8.12'
implementation group: 'org.jacoco', name: 'org.jacoco.core', version: '0.8.13'
implementation group: 'org.jacoco', name: 'org.jacoco.report', version: '0.8.13'

implementation project(':communication')
implementation project(':components:json')
implementation project(':internal-api')
implementation project(':internal-api:internal-api-9')

testImplementation project(":utils:test-utils")
testImplementation project(':dd-java-agent:testing')
testImplementation("com.google.jimfs:jimfs:1.1") // an in-memory file system for testing code that works with files

testImplementation libs.scala
testImplementation libs.kotlin

testFixturesApi project(':dd-java-agent:testing')
testFixturesApi project(':utils:test-utils')

testFixturesApi group: 'org.skyscreamer', name: 'jsonassert', version: '1.5.1'
testFixturesApi group: 'org.freemarker', name: 'freemarker', version: '2.3.31'
testFixturesApi group: 'com.jayway.jsonpath', name: 'json-path', version: '2.8.0'
testFixturesApi group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.16.0'
testFixturesApi group: 'org.msgpack', name: 'jackson-dataformat-msgpack', version: '0.9.6'
testImplementation group: 'org.skyscreamer', name: 'jsonassert', version: '1.5.1'
testImplementation group: 'org.freemarker', name: 'freemarker', version: '2.3.31'

testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.9.2") // Required to update dependency lock files
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apply from: "$rootDir/gradle/java.gradle"
apply from: "$rootDir/gradle/version.gradle"

dependencies {
api project(':dd-java-agent:agent-ci-visibility')
api project(':dd-java-agent:instrumentation-testing')
api project(':utils:test-utils')

api group: 'org.skyscreamer', name: 'jsonassert', version: '1.5.1'
api group: 'org.freemarker', name: 'freemarker', version: '2.3.31'
api group: 'com.jayway.jsonpath', name: 'json-path', version: '2.8.0'
api group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.16.0'
api group: 'org.msgpack', name: 'jackson-dataformat-msgpack', version: '0.9.6'
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import datadog.trace.api.civisibility.config.TestFQN
import datadog.trace.api.civisibility.config.TestIdentifier
import datadog.trace.api.civisibility.config.TestMetadata
import datadog.trace.api.civisibility.telemetry.CiVisibilityMetricCollector
import datadog.trace.civisibility.CiVisibilityTestUtils
import freemarker.core.Environment
import freemarker.core.InvalidReferenceException
import freemarker.template.Template
import freemarker.template.TemplateException
import freemarker.template.TemplateExceptionHandler
import okhttp3.HttpUrl
import okhttp3.OkHttpClient
import org.apache.commons.io.IOUtils
Expand Down Expand Up @@ -233,7 +237,7 @@ class ConfigurationApiImplTest extends Specification {
httpServer {
handlers {
prefix(path) {
def expectedRequestBody = CiVisibilityTestUtils.getFreemarkerTemplate(requestTemplate, requestData)
def expectedRequestBody = getFreemarkerTemplate(requestTemplate, requestData)

def response = response
try {
Expand All @@ -242,7 +246,7 @@ class ConfigurationApiImplTest extends Specification {
response.status(400).send(error.getMessage().bytes)
}

def responseBody = CiVisibilityTestUtils.getFreemarkerTemplate(responseTemplate, responseData).bytes
def responseBody = getFreemarkerTemplate(responseTemplate, responseData).bytes
def header = request.getHeader("Accept-Encoding")
def gzipSupported = header != null && header.contains("gzip")
if (gzipSupported) {
Expand Down Expand Up @@ -315,4 +319,37 @@ class ConfigurationApiImplTest extends Specification {
}
return bitSet
}

static final TemplateExceptionHandler SUPPRESS_EXCEPTION_HANDLER = new TemplateExceptionHandler() {
@Override
void handleTemplateException(TemplateException e, Environment environment, Writer writer) throws TemplateException {
if (e instanceof InvalidReferenceException) {
writer.write('"<VALUE_MISSING>"')
} else {
throw e
}
}
}

static final freemarker.template.Configuration FREEMARKER = new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_30) { {
setClassLoaderForTemplateLoading(ConfigurationApiImplTest.classLoader, "")
setDefaultEncoding("UTF-8")
setTemplateExceptionHandler(SUPPRESS_EXCEPTION_HANDLER)
setLogTemplateExceptions(false)
setWrapUncheckedExceptions(true)
setFallbackOnNullLoopVariable(false)
setNumberFormat("0.######")
}
}

static String getFreemarkerTemplate(String templatePath, Map<String, Object> replacements, List<Map<?, ?>> replacementsSource = []) {
try {
Template coveragesTemplate = FREEMARKER.getTemplate(templatePath)
StringWriter coveragesOut = new StringWriter()
coveragesTemplate.process(replacements, coveragesOut)
return coveragesOut.toString()
} catch (Exception e) {
throw new RuntimeException("Could not get Freemarker template " + templatePath + "; replacements map: " + replacements + "; replacements source: " + replacementsSource, e)
}
}
}
5 changes: 2 additions & 3 deletions dd-java-agent/agent-iast/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import net.ltgt.gradle.errorprone.CheckSeverity
plugins {
id 'com.gradleup.shadow'
id 'me.champeau.jmh'
id 'java-test-fixtures'
id 'com.google.protobuf' version '0.8.18'
id 'net.ltgt.errorprone' version '3.1.0'
}
Expand Down Expand Up @@ -52,8 +51,8 @@ dependencies {
implementation libs.moshi
implementation libs.bundles.asm

testFixturesApi project(':dd-java-agent:testing')
testFixturesApi project(':utils:test-utils')
testImplementation project(':utils:test-utils')
testImplementation project(':dd-java-agent:agent-bootstrap')
testImplementation libs.bytebuddy
testImplementation('org.skyscreamer:jsonassert:1.5.1')
testImplementation libs.groovy.yaml
Expand Down
8 changes: 8 additions & 0 deletions dd-java-agent/agent-iast/iast-testing/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apply from: "$rootDir/gradle/java.gradle"
apply from: "$rootDir/gradle/version.gradle"

dependencies {
api project(':dd-java-agent:agent-iast')
api project(':dd-java-agent:instrumentation-testing')
api project(':utils:test-utils')
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ trait IastRequestContextPreparationTrait {
}

static void iastSystemCleanup() {
get().getSubscriptionService(RequestContextSlot.IAST).reset()
datadog.trace.bootstrap.instrumentation.api.AgentTracer.get().getSubscriptionService(RequestContextSlot.IAST).reset()
InstrumentationBridge.clearIastModules()
}

Expand Down Expand Up @@ -75,8 +75,8 @@ trait IastRequestContextPreparationTrait {

private static Logger withLogger(final String name) {
final logger = LoggerFactory.getLogger(name)
if (logger instanceof ch.qos.logback.classic.Logger) {
((ch.qos.logback.classic.Logger) logger).level = ch.qos.logback.classic.Level.DEBUG
if (logger instanceof Logger) {
((Logger) logger).level = ch.qos.logback.classic.Level.DEBUG
}
return logger
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.datadog.iast.test

import datadog.trace.api.iast.SourceTypes
import okhttp3.FormBody
import okhttp3.MediaType
import okhttp3.Request
import okhttp3.RequestBody
Expand Down Expand Up @@ -94,7 +93,7 @@ abstract class IastSourcesTest<SERVER> extends IastHttpServerTest<SERVER> {
void 'test form source'() {
when:
final url = "${address}/iast/sources/form"
final body = new FormBody.Builder().add('name', 'value').build()
final body = new Request.Builder().add('name', 'value').build()
final request = new Request.Builder().url(url).post(body).build()
final response = client.newCall(request).execute()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ class TaintedObjectCollection {
} else if (obj instanceof Pattern) {
valueMatcher = Matchers.matchesPattern(obj)
} else {
valueMatcher = equalTo(obj)
valueMatcher = org.hamcrest.Matchers.equalTo(obj)
}
}

private static Matcher toMatcher(Object obj) {
if (obj instanceof Matcher) {
obj
} else if (obj instanceof Pattern) {
matchesPattern(obj)
org.hamcrest.Matchers.matchesPattern(obj)
} else if (obj == null) {
nullValue()
org.hamcrest.Matchers.nullValue()
} else {
equalTo(obj)
org.hamcrest.Matchers.equalTo(obj)
}
}

Expand All @@ -79,15 +79,15 @@ class TaintedObjectCollection {
}

void range(int start, int length, SourceMatcher source) {
ranges << new RangeMatcher(start, equalTo(length), source)
ranges << new RangeMatcher(start, org.hamcrest.Matchers.equalTo(length), source)
}

void range(int start, Matcher<Integer> length, SourceMatcher source) {
ranges << new RangeMatcher(start, length, source)
}

void range(SourceMatcher source) {
ranges << new RangeMatcher(0, greaterThan(0), source)
ranges << new RangeMatcher(0, org.hamcrest.Matchers.greaterThan(0), source)
}

@Override
Expand Down
12 changes: 12 additions & 0 deletions dd-java-agent/appsec/appsec-testing/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apply from: "$rootDir/gradle/java.gradle"
apply from: "$rootDir/gradle/version.gradle"

dependencies {
api project(':dd-java-agent:appsec')
api project(':dd-java-agent:instrumentation-testing')
api project(':utils:test-utils')
}

configurations.api {
exclude group: 'org.eclipse.jetty', module: 'jetty-server'
}
7 changes: 1 addition & 6 deletions dd-java-agent/appsec/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import groovy.json.JsonSlurper
plugins {
id 'com.gradleup.shadow'
id 'me.champeau.jmh'
id 'java-test-fixtures'
}

apply from: "$rootDir/gradle/java.gradle"
Expand All @@ -26,11 +25,7 @@ dependencies {
testImplementation libs.logback.classic
testImplementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.16.0'

testFixturesApi project(':dd-java-agent:testing')
}

configurations.testFixturesApi {
exclude group: 'org.eclipse.jetty', module: 'jetty-server'
testImplementation project(':utils:test-utils')
}

shadowJar {
Expand Down
27 changes: 27 additions & 0 deletions dd-java-agent/instrumentation-testing/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apply from: "$rootDir/gradle/java.gradle"

dependencies {
api libs.bytebuddy
api libs.bytebuddyagent
api libs.slf4j
api libs.bundles.spock
api libs.bundles.test.logging
api libs.guava

api project(':dd-java-agent:testing')

implementation project(':dd-java-agent:agent-debugger')

implementation 'org.junit.platform:junit-platform-runner:1.9.0'

testImplementation project(':utils:test-utils')
testImplementation project(':dd-java-agent:instrumentation:trace-annotation')

testImplementation group: 'cglib', name: 'cglib', version: '3.2.5'
// test instrumenting java 1.1 bytecode
testImplementation group: 'net.sf.jt400', name: 'jt400', version: '6.1'

// We have autoservices defined in test subtree, looks like we need this to be able to properly rebuild this
testAnnotationProcessor libs.autoservice.processor
testCompileOnly libs.autoservice.annotation
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import net.bytebuddy.dynamic.DynamicType
import net.bytebuddy.utility.JavaModule
import okhttp3.HttpUrl
import okhttp3.OkHttpClient
import org.junit.runner.RunWith
import org.junit.jupiter.api.extension.ExtendWith
import org.slf4j.LoggerFactory
import org.spockframework.mock.MockUtil
import org.spockframework.mock.runtime.MockInvocation
Expand Down Expand Up @@ -107,7 +107,7 @@ import static datadog.trace.util.AgentThreadFactory.AgentThread.TASK_SCHEDULER
*/
// CodeNarc incorrectly thinks ".class" is unnecessary in @RunWith
@SuppressWarnings('UnnecessaryDotClass')
@RunWith(SpockRunner.class)
@ExtendWith(SpockExtension.class)
abstract class AgentTestRunner extends DDSpecification implements AgentBuilder.Listener {
private static final long TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(20)

Expand Down
Loading