Skip to content

Commit 537c409

Browse files
committed
Add support for configuring expected outcomes
See gh-210
1 parent 9aca5d7 commit 537c409

File tree

4 files changed

+133
-8
lines changed

4 files changed

+133
-8
lines changed

gradle/plugins/aot-smoke-test-plugin/src/main/java/org/springframework/aot/gradle/AotSmokeTestPlugin.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
package org.springframework.aot.gradle;
1818

1919
import java.net.URI;
20+
import java.util.ArrayList;
2021
import java.util.HashMap;
22+
import java.util.List;
2123
import java.util.Locale;
2224
import java.util.Map;
2325
import java.util.Set;
@@ -48,6 +50,7 @@
4850
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile;
4951

5052
import org.springframework.aot.gradle.dsl.AotSmokeTestExtension;
53+
import org.springframework.aot.gradle.dsl.AotSmokeTestExtension.Outcome;
5154
import org.springframework.aot.gradle.tasks.AppTest;
5255
import org.springframework.aot.gradle.tasks.DescribeSmokeTest;
5356
import org.springframework.aot.gradle.tasks.StartApplication;
@@ -130,7 +133,20 @@ private void configureBootJavaProject(Project project) {
130133
.getAllSource()
131134
.isEmpty();
132135
boolean appTests = !appTest.getAllSource().isEmpty();
133-
return new SmokeTest(project.getName(), project.getParent().getName(), project.getPath(), tests, appTests);
136+
List<String> expectedToFail = new ArrayList<String>();
137+
if (extension.getAppTest().getOutcome().get() == Outcome.FAILURE) {
138+
expectedToFail.add("appTest");
139+
}
140+
if (extension.getNativeAppTest().getOutcome().get() == Outcome.FAILURE) {
141+
expectedToFail.add("nativeAppTest");
142+
}
143+
if (extension.getTest().getOutcome().get() == Outcome.FAILURE) {
144+
expectedToFail.add("test");
145+
}
146+
if (extension.getNativeTest().getOutcome().get() == Outcome.FAILURE) {
147+
expectedToFail.add("nativeTest");
148+
}
149+
return new SmokeTest(project.getName(), project.getParent().getName(), project.getPath(), tests, appTests, expectedToFail);
134150
});
135151
TaskProvider<DescribeSmokeTest> describeSmokeTest = project.getTasks()
136152
.register("describeSmokeTest", DescribeSmokeTest.class);

gradle/plugins/aot-smoke-test-plugin/src/main/java/org/springframework/aot/gradle/SmokeTest.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.aot.gradle;
1818

1919
import java.io.Serializable;
20+
import java.util.List;
2021
import java.util.Properties;
2122

2223
/**
@@ -28,13 +29,9 @@
2829
* @param path path of the smoke test project
2930
* @param tests whether the smoke test contains any unit tests
3031
* @param appTests whether the smoke test contains any app tests
32+
* @param expectedToFail names of tasks that are expected to fail
3133
*/
3234
public record SmokeTest(String name, String group, String path, boolean tests,
33-
boolean appTests) implements Serializable {
34-
35-
SmokeTest(Properties properties) {
36-
this(properties.getProperty("name"), properties.getProperty("group"), properties.getProperty("path"),
37-
Boolean.valueOf(properties.getProperty("tests")), Boolean.valueOf(properties.getProperty("appTests")));
38-
}
35+
boolean appTests, List<String> expectedToFail) implements Serializable {
3936

4037
}

gradle/plugins/aot-smoke-test-plugin/src/main/java/org/springframework/aot/gradle/dsl/AotSmokeTestExtension.java

+112-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
import javax.inject.Inject;
2020

21+
import org.gradle.api.Action;
2122
import org.gradle.api.Project;
23+
import org.gradle.api.model.ObjectFactory;
2224
import org.gradle.api.provider.Property;
2325

2426
/**
@@ -30,9 +32,22 @@ public class AotSmokeTestExtension {
3032

3133
private final Property<Boolean> webApplication;
3234

35+
private final Expectation appTest;
36+
37+
private final Expectation nativeAppTest;
38+
39+
private final Expectation test;
40+
41+
private final Expectation nativeTest;
42+
3343
@Inject
3444
public AotSmokeTestExtension(Project project) {
35-
this.webApplication = project.getObjects().property(Boolean.class);
45+
ObjectFactory objects = project.getObjects();
46+
this.webApplication = objects.property(Boolean.class);
47+
this.appTest = objects.newInstance(Expectation.class, project);
48+
this.nativeAppTest = objects.newInstance(Expectation.class, project);
49+
this.test = objects.newInstance(Expectation.class, project);
50+
this.nativeTest = objects.newInstance(Expectation.class, project);
3651
}
3752

3853
/**
@@ -43,4 +58,100 @@ public Property<Boolean> getWebApplication() {
4358
return this.webApplication;
4459
}
4560

61+
/**
62+
* Expectations for {@code appTest}.
63+
*/
64+
public Expectation getAppTest() {
65+
return this.appTest;
66+
}
67+
68+
/**
69+
* Configure expectations for {@code appTest}.
70+
*/
71+
public void appTest(Action<Expectation> action) {
72+
action.execute(this.appTest);
73+
}
74+
75+
/**
76+
* Expectations for {@code nativeAppTest}.
77+
*/
78+
public Expectation getNativeAppTest() {
79+
return this.nativeAppTest;
80+
}
81+
82+
/**
83+
* Configure expectations for {@code nativeAppTest}.
84+
*/
85+
public void nativeAppTest(Action<Expectation> action) {
86+
action.execute(this.nativeAppTest);
87+
}
88+
89+
/**
90+
* Expectations for {@code test}.
91+
*/
92+
public Expectation getTest() {
93+
return this.test;
94+
}
95+
96+
/**
97+
* Configure expectations for {@code test}.
98+
*/
99+
public void test(Action<Expectation> action) {
100+
action.execute(this.test);
101+
}
102+
103+
/**
104+
* Expectations for {@code nativeTest}.
105+
*/
106+
public Expectation getNativeTest() {
107+
return this.nativeTest;
108+
}
109+
110+
/**
111+
* Configure expectations for {@code nativeTest}.
112+
*/
113+
public void nativeTest(Action<Expectation> action) {
114+
action.execute(this.nativeTest);
115+
}
116+
117+
public static class Expectation {
118+
119+
private final Property<Outcome> outcome;
120+
121+
@Inject
122+
public Expectation(Project project) {
123+
this.outcome = project.getObjects().property(Outcome.class);
124+
this.outcome.convention(Outcome.SUCCESS);
125+
}
126+
127+
/**
128+
* The expected outcome.
129+
*/
130+
public Property<Outcome> getOutcome() {
131+
return this.outcome;
132+
}
133+
134+
/**
135+
* Note that expected outcome is failure
136+
*/
137+
public void expectedToFail(Action<Object> action) {
138+
this.outcome.set(Outcome.FAILURE);
139+
}
140+
141+
}
142+
143+
public static enum Outcome {
144+
145+
/**
146+
* The expected outcome is failure.
147+
*/
148+
FAILURE,
149+
150+
/**
151+
* The expected outcome is success.
152+
*/
153+
SUCCESS
154+
155+
}
156+
46157
}

gradle/plugins/aot-smoke-test-plugin/src/main/java/org/springframework/aot/gradle/tasks/DescribeSmokeTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void describeSmokeTest() throws IOException {
6161
properties.add("name=" + smokeTest.name());
6262
properties.add("path=" + smokeTest.path());
6363
properties.add("tests=" + smokeTest.tests());
64+
properties.add("expectedToFail=" + String.join(",", smokeTest.expectedToFail()));
6465
Files.write(propertiesFile.toPath(), properties);
6566
}
6667

0 commit comments

Comments
 (0)