Skip to content

Commit 18a0b47

Browse files
committed
Make InternalYamlRestTest and JavaRestTestPlugin test suites compatible
1 parent 16a4e3d commit 18a0b47

File tree

12 files changed

+146
-35
lines changed

12 files changed

+146
-35
lines changed

build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/precommit/TestingConventionsPrecommitPluginFuncTest.groovy

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class TestingConventionsPrecommitPluginFuncTest extends AbstractGradleInternalPl
3232
"org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase",
3333
"org.elasticsearch.test.AbstractMultiClustersTestCase"
3434
)
35-
repository.generateJar('org.junit', 'junit', "4.42",
35+
repository.generateJar('junit', 'junit', "4.42",
3636
"org.junit.Assert", "org.junit.Test"
3737
)
3838
}
@@ -180,7 +180,7 @@ class TestingConventionsPrecommitPluginFuncTest extends AbstractGradleInternalPl
180180
181181
dependencies {
182182
yamlRestTestImplementation "org.apache.lucene:tests.util:1.0"
183-
yamlRestTestImplementation "org.junit:junit:4.42"
183+
yamlRestTestImplementation "junit:junit:4.42"
184184
}
185185
"""
186186

@@ -222,7 +222,7 @@ class TestingConventionsPrecommitPluginFuncTest extends AbstractGradleInternalPl
222222
223223
dependencies {
224224
${sourceSetName}Implementation "org.apache.lucene:tests.util:1.0"
225-
${sourceSetName}Implementation "org.junit:junit:4.42"
225+
${sourceSetName}Implementation "junit:junit:4.42"
226226
}
227227
tasks.withType(TestingConventionsCheckTask).configureEach {
228228
suffix 'IT'
@@ -243,7 +243,7 @@ class TestingConventionsPrecommitPluginFuncTest extends AbstractGradleInternalPl
243243
}
244244

245245
when:
246-
def result = gradleRunner("testingConventions").buildAndFail()
246+
def result = gradleRunner(taskName).buildAndFail()
247247
then:
248248
result.task(taskName).outcome == TaskOutcome.FAILED
249249
assertOutputContains(result.getOutput(), """\
@@ -266,7 +266,7 @@ class TestingConventionsPrecommitPluginFuncTest extends AbstractGradleInternalPl
266266
267267
dependencies {
268268
testImplementation "org.apache.lucene:tests.util:1.0"
269-
testImplementation "org.junit:junit:4.42"
269+
testImplementation "junit:junit:4.42"
270270
}
271271
"""
272272
}

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/DefaultElasticsearchRestTestSuite.java

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.gradle.internal.test.rest;
11+
12+
import org.gradle.api.artifacts.ConfigurationContainer;
13+
import org.gradle.api.internal.tasks.TaskDependencyFactory;
14+
import org.gradle.api.plugins.jvm.internal.DefaultJvmTestSuite;
15+
import org.gradle.api.tasks.SourceSetContainer;
16+
17+
public abstract class DefaultJavaRestTestSuite extends DefaultJvmTestSuite implements JavaRestTestSuite {
18+
public DefaultJavaRestTestSuite(
19+
String name,
20+
SourceSetContainer sourceSets,
21+
ConfigurationContainer configurations,
22+
TaskDependencyFactory taskDependencyFactory
23+
) {
24+
super(name, sourceSets, configurations, taskDependencyFactory);
25+
}
26+
}

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/DefaultYamlRestTestSuite.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
110
package org.elasticsearch.gradle.internal.test.rest;
211

312
import org.gradle.api.artifacts.ConfigurationContainer;

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/ElasticsearchRestTestSuite.java

Lines changed: 0 additions & 4 deletions
This file was deleted.

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/InternalJavaRestTestPlugin.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99

1010
package org.elasticsearch.gradle.internal.test.rest;
1111

12-
import org.elasticsearch.gradle.internal.test.RestIntegTestTask;
1312
import org.elasticsearch.gradle.util.GradleUtils;
13+
import org.gradle.api.Action;
1414
import org.gradle.api.Plugin;
1515
import org.gradle.api.Project;
1616
import org.gradle.api.plugins.JavaBasePlugin;
17+
import org.gradle.api.plugins.jvm.JvmTestSuiteTarget;
1718
import org.gradle.api.tasks.SourceSet;
18-
import org.gradle.api.tasks.SourceSetContainer;
19-
import org.gradle.api.tasks.TaskProvider;
19+
import org.gradle.testing.base.TestingExtension;
2020

21-
import static org.elasticsearch.gradle.internal.test.rest.RestTestUtil.registerTestTask;
2221
import static org.elasticsearch.gradle.internal.test.rest.RestTestUtil.setupJavaRestTestDependenciesDefaults;
2322

2423
/**
@@ -32,23 +31,31 @@ public class InternalJavaRestTestPlugin implements Plugin<Project> {
3231
public void apply(Project project) {
3332
project.getPluginManager().apply(RestTestBasePlugin.class);
3433

35-
// create source set
36-
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
37-
SourceSet javaTestSourceSet = sourceSets.create(SOURCE_SET_NAME);
34+
TestingExtension testing = project.getExtensions().getByType(TestingExtension.class);
35+
testing.getSuites().registerBinding(JavaRestTestSuite.class, DefaultJavaRestTestSuite.class);
36+
testing.getSuites().register(SOURCE_SET_NAME, JavaRestTestSuite.class, suite -> {
37+
suite.useJUnit();
38+
configureJavaRestSources(project, suite.getSources());
39+
if (project.findProject(":test:test-clusters") != null) {
40+
suite.getDependencies().getImplementation().add(suite.getDependencies().project(":test:test-clusters"));
41+
}
42+
suite.getTargets()
43+
.all(
44+
(Action<JvmTestSuiteTarget>) jvmTestSuiteTarget -> jvmTestSuiteTarget.getTestTask()
45+
.configure(
46+
test -> project.getTasks().named(JavaBasePlugin.CHECK_TASK_NAME).configure(check -> check.dependsOn(test))
47+
)
48+
);
49+
});
3850

39-
if (project.findProject(":test:test-clusters") != null) {
40-
project.getDependencies().add(javaTestSourceSet.getImplementationConfigurationName(), project.project(":test:test-clusters"));
41-
}
42-
43-
// setup the javaRestTest task
44-
TaskProvider<RestIntegTestTask> testTask = registerTestTask(project, javaTestSourceSet, SOURCE_SET_NAME, RestIntegTestTask.class);
45-
46-
project.getTasks().named(JavaBasePlugin.CHECK_TASK_NAME).configure(check -> check.dependsOn(testTask));
51+
}
4752

53+
private void configureJavaRestSources(Project project, SourceSet javaTestSourceSet) {
4854
// setup dependencies
4955
setupJavaRestTestDependenciesDefaults(project, javaTestSourceSet);
5056

5157
// setup IDE
5258
GradleUtils.setupIdeForTestSourceSet(project, javaTestSourceSet);
5359
}
60+
5461
}

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/InternalYamlRestTestPlugin.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import org.gradle.api.Plugin;
1515
import org.gradle.api.Project;
1616
import org.gradle.api.plugins.JavaBasePlugin;
17-
import org.gradle.api.plugins.JvmTestSuitePlugin;
18-
import org.gradle.api.plugins.jvm.JvmTestSuite;
1917
import org.gradle.api.plugins.jvm.JvmTestSuiteTarget;
2018
import org.gradle.api.tasks.SourceSet;
2119
import org.gradle.testing.base.TestingExtension;
@@ -38,7 +36,6 @@ public void apply(Project project) {
3836
testing.getSuites().register(SOURCE_SET_NAME, YamlRestTestSuite.class, suite -> {
3937
suite.useJUnit();
4038
configureYamlSourceSet(project, suite.getSources());
41-
suite.getDependencies().getImplementation().add(suite.getDependencies().project());
4239
suite.getTargets()
4340
.all(
4441
(Action<JvmTestSuiteTarget>) jvmTestSuiteTarget -> jvmTestSuiteTarget.getTestTask()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.gradle.internal.test.rest;
11+
12+
import org.gradle.api.plugins.jvm.JvmTestSuite;
13+
14+
public interface JavaRestTestSuite extends JvmTestSuite {}
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
110
package org.elasticsearch.gradle.internal.test.rest;
211

312
import org.gradle.api.plugins.jvm.JvmTestSuite;
413

5-
public interface RestTestSuite extends JvmTestSuite {
6-
}
14+
public interface RestTestSuite extends JvmTestSuite {}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.elasticsearch.gradle.internal.test.rest;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
23+
import org.gradle.api.plugins.jvm.JvmTestSuite;
24+
25+
public interface RestTestSuite extends JvmTestSuite {
26+
}

0 commit comments

Comments
 (0)