Skip to content

Commit 85e742e

Browse files
committed
Add Quarkus native smoke test for cel-core with cel-generated-pb
None of the existing Quarkus smoke tests covers the non-relocated `cel-generated-pb` (Protobuf 4) native-image metadata: the standalone test uses the relocated copy and the other test uses `cel-generated-pb3`. Add `quarkus-smoke-core-pb4-jackson3`, using `cel-core`, `cel-generated-pb`, and `cel-jackson3`. `protobuf-java` is excluded from the enforced Quarkus BOM, because the generated classes require a Protobuf runtime at least as new as their gencode. Document that requirement in the README and point to `cel-standalone` for projects whose platform manages an older `protobuf-java`.
1 parent 8059679 commit 85e742e

8 files changed

Lines changed: 287 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ longer choose a generated protobuf runtime transitively. Add exactly one of thes
8181
Do not put both generated protobuf artifacts on the same classpath; they provide the same generated
8282
CEL protobuf classes for different protobuf runtime choices.
8383

84+
The generated protobuf classes check at runtime that `protobuf-java` is at least as new as the
85+
protobuf version they were generated with. If your framework or platform BOM manages an older
86+
`protobuf-java` (for example, Quarkus 4.0 manages 4.35.x), loading CEL-Java fails with a
87+
`ProtobufRuntimeVersionException`. Either override the managed `protobuf-java` version, or use
88+
[`cel-standalone`](#dependency-free-artifact), which relocates its protobuf dependencies.
89+
8490
## Usage
8591

8692
### Basic scripts

‎build-logic/src/main/kotlin/cel-conventions.gradle.kts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ val nonPublishedProjects =
2323
"cel-conformance",
2424
"cel-quarkus-smoke-standalone",
2525
"cel-quarkus-smoke-core-pb3-jackson3",
26+
"cel-quarkus-smoke-core-pb4-jackson3",
2627
)
2728

2829
if (project.name !in nonPublishedProjects) {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (C) 2026 The Authors of CEL-Java
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
plugins {
18+
alias(libs.plugins.quarkus)
19+
id("cel-conventions")
20+
`java-library`
21+
}
22+
23+
description = "Quarkus native smoke test for cel-core, cel-generated-pb, and cel-jackson3"
24+
25+
val testNativeRequested =
26+
gradle.startParameter.taskNames.any { taskName ->
27+
taskName == "testNative" || taskName == "${project.path}:testNative"
28+
}
29+
30+
if (testNativeRequested) {
31+
quarkus {
32+
set("native.enabled", "true")
33+
set("native.container-build", "true")
34+
set("package.jar.enabled", "false")
35+
}
36+
}
37+
38+
dependencies {
39+
// cel-generated-pb requires a Protobuf runtime at least as new as its gencode, which can be newer
40+
// than the Protobuf version managed by the Quarkus BOM.
41+
implementation(enforcedPlatform(libs.quarkus.bom)) {
42+
exclude(group = "com.google.protobuf", module = "protobuf-java")
43+
}
44+
implementation("io.quarkus:quarkus-arc")
45+
implementation("io.quarkus:quarkus-rest-jackson")
46+
implementation(project(":cel-core"))
47+
implementation(project(":cel-generated-pb"))
48+
implementation(testFixtures(project(":cel-generated-pb")))
49+
implementation(project(":cel-jackson3"))
50+
51+
testImplementation("io.quarkus:quarkus-junit5")
52+
testImplementation("io.rest-assured:rest-assured")
53+
}
54+
55+
java {
56+
sourceCompatibility = JavaVersion.VERSION_21
57+
targetCompatibility = JavaVersion.VERSION_21
58+
}
59+
60+
tasks.withType<JavaCompile>().configureEach { options.release.set(21) }
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/*
2+
* Copyright (C) 2026 The Authors of CEL-Java
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.projectnessie.cel.quarkus.smoke.corepb4jackson3;
17+
18+
import static java.util.Arrays.asList;
19+
import static java.util.Map.of;
20+
import static org.projectnessie.cel.Env.newCustomEnv;
21+
import static org.projectnessie.cel.EnvOption.declarations;
22+
import static org.projectnessie.cel.EnvOption.types;
23+
import static org.projectnessie.cel.Library.StdLib;
24+
25+
import com.google.protobuf.Int32Value;
26+
import dev.cel.expr.conformance.proto3.NestedTestAllTypes;
27+
import dev.cel.expr.conformance.proto3.TestAllTypes;
28+
import io.quarkus.runtime.annotations.RegisterForReflection;
29+
import jakarta.ws.rs.GET;
30+
import jakarta.ws.rs.Path;
31+
import jakarta.ws.rs.Produces;
32+
import jakarta.ws.rs.core.MediaType;
33+
import java.time.Instant;
34+
import org.projectnessie.cel.Ast;
35+
import org.projectnessie.cel.Env;
36+
import org.projectnessie.cel.Env.AstIssuesTuple;
37+
import org.projectnessie.cel.Program;
38+
import org.projectnessie.cel.Program.EvalResult;
39+
import org.projectnessie.cel.checker.Decls;
40+
import org.projectnessie.cel.common.types.Err;
41+
import org.projectnessie.cel.common.types.pb.ProtoTypeRegistry;
42+
import org.projectnessie.cel.common.types.ref.Val;
43+
import org.projectnessie.cel.types.jackson3.Jackson3Registry;
44+
45+
@Path("/cel/native-smoke")
46+
public class SmokeResource {
47+
private static final String JACKSON_EXPRESSION =
48+
"input.name == \"reports\" && request.time < timestamp(\"2026-08-01T00:00:00Z\")";
49+
50+
private static final String PROTO_EXPRESSION = "proto.single_int32_wrapper == 123";
51+
52+
@GET
53+
@Produces(MediaType.APPLICATION_JSON)
54+
public SmokeResponse smoke() {
55+
return new SmokeResponse(
56+
"cel-core+cel-generated-pb+cel-jackson3", evaluateJackson(), evaluateProto());
57+
}
58+
59+
private boolean evaluateJackson() {
60+
Env env =
61+
newCustomEnv(
62+
Jackson3Registry.newRegistry(),
63+
asList(
64+
StdLib(),
65+
types(Input.class),
66+
declarations(
67+
Decls.newVar("input", Decls.newObjectType(Input.class.getName())),
68+
Decls.newVar("request.time", Decls.Timestamp))));
69+
70+
Program program = compile(env, JACKSON_EXPRESSION);
71+
EvalResult result =
72+
program.eval(
73+
of(
74+
"input",
75+
new Input("reports"),
76+
"request.time",
77+
Instant.parse("2026-07-31T23:59:59Z")));
78+
return booleanResult(result);
79+
}
80+
81+
private boolean evaluateProto() {
82+
Env env =
83+
newCustomEnv(
84+
ProtoTypeRegistry.newRegistry(),
85+
asList(
86+
StdLib(),
87+
types(TestAllTypes.getDefaultInstance()),
88+
declarations(
89+
Decls.newVar(
90+
"proto",
91+
Decls.newObjectType(TestAllTypes.getDescriptor().getFullName())))));
92+
93+
Program program = compile(env, PROTO_EXPRESSION);
94+
EvalResult result =
95+
program.eval(
96+
of(
97+
"proto",
98+
TestAllTypes.newBuilder().setSingleInt32Wrapper(Int32Value.of(123)).build()));
99+
return booleanResult(result);
100+
}
101+
102+
private static Program compile(Env env, String expression) {
103+
AstIssuesTuple parsed = env.parse(expression);
104+
if (parsed.hasIssues()) {
105+
throw new IllegalStateException("parse failed: " + parsed.getIssues());
106+
}
107+
108+
Ast ast = parsed.getAst();
109+
AstIssuesTuple checked = env.check(ast);
110+
if (checked.hasIssues()) {
111+
throw new IllegalStateException("check failed: " + checked.getIssues());
112+
}
113+
114+
return env.program(checked.getAst());
115+
}
116+
117+
private static boolean booleanResult(EvalResult result) {
118+
Val value = result.getVal();
119+
if (Err.isError(value)) {
120+
throw new IllegalStateException("evaluation failed: " + value);
121+
}
122+
return value.booleanValue();
123+
}
124+
125+
public record SmokeResponse(String engine, boolean jackson, boolean protobuf) {}
126+
127+
@RegisterForReflection(targets = {TestAllTypes.class, NestedTestAllTypes.class})
128+
static final class ProtobufReflection {}
129+
130+
@RegisterForReflection
131+
public static final class Input {
132+
private final String name;
133+
134+
public Input(String name) {
135+
this.name = name;
136+
}
137+
138+
public String getName() {
139+
return name;
140+
}
141+
}
142+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Copyright (C) 2026 The Authors of CEL-Java
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
quarkus.banner.enabled=false
18+
quarkus.http.test-port=8183
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (C) 2026 The Authors of CEL-Java
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.projectnessie.cel.quarkus.smoke.corepb4jackson3;
17+
18+
import io.quarkus.test.junit.QuarkusIntegrationTest;
19+
20+
@QuarkusIntegrationTest
21+
class SmokeResourceNativeIT extends SmokeResourceTest {}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (C) 2026 The Authors of CEL-Java
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.projectnessie.cel.quarkus.smoke.corepb4jackson3;
17+
18+
import static io.restassured.RestAssured.given;
19+
import static org.hamcrest.Matchers.equalTo;
20+
21+
import io.quarkus.test.junit.QuarkusTest;
22+
import org.junit.jupiter.api.Test;
23+
24+
@QuarkusTest
25+
class SmokeResourceTest {
26+
@Test
27+
void evaluatesCelExpressions() {
28+
given()
29+
.when()
30+
.get("/cel/native-smoke")
31+
.then()
32+
.statusCode(200)
33+
.body("engine", equalTo("cel-core+cel-generated-pb+cel-jackson3"))
34+
.body("jackson", equalTo(true))
35+
.body("protobuf", equalTo(true));
36+
}
37+
}

‎settings.gradle.kts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,6 @@ celProject("quarkus-smoke-standalone")
159159

160160
celProject("quarkus-smoke-core-pb3-jackson3")
161161

162+
celProject("quarkus-smoke-core-pb4-jackson3")
163+
162164
celProject("bom")

0 commit comments

Comments
 (0)