Skip to content

Commit aff90da

Browse files
CEL Dev Teamcopybara-github
authored andcommitted
Hello World
PiperOrigin-RevId: 751467412
1 parent 4803f75 commit aff90da

31 files changed

+4064
-0
lines changed
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
load("@rules_java//java:java_library.bzl", "java_library")
2+
3+
package(
4+
default_applicable_licenses = ["//:license"],
5+
default_testonly = True,
6+
default_visibility = [
7+
"//testing/testrunner:__pkg__",
8+
],
9+
)
10+
11+
java_library(
12+
name = "test_executor",
13+
srcs = ["TestExecutor.java"],
14+
tags = [
15+
],
16+
deps = [
17+
":cel_test_suite",
18+
":cel_test_suite_exception",
19+
":cel_test_suite_text_proto_parser",
20+
":cel_test_suite_yaml_parser",
21+
":junit_xml_reporter",
22+
"//java/com/google/common/time",
23+
"@maven//:com_google_guava_guava",
24+
"@maven//:junit_junit",
25+
],
26+
)
27+
28+
java_library(
29+
name = "junit_xml_reporter",
30+
srcs = ["JUnitXmlReporter.java"],
31+
tags = [
32+
],
33+
deps = ["@maven//:com_google_guava_guava"],
34+
)
35+
36+
java_library(
37+
name = "cel_user_test_template",
38+
srcs = ["CelUserTestTemplate.java"],
39+
tags = [
40+
],
41+
deps = [
42+
":cel_test_context",
43+
":cel_test_suite",
44+
":test_runner_library",
45+
"@maven//:junit_junit",
46+
],
47+
)
48+
49+
java_library(
50+
name = "test_runner_library",
51+
srcs = ["TestRunnerLibrary.java"],
52+
tags = [
53+
],
54+
deps = [
55+
":cel_test_context",
56+
":cel_test_suite",
57+
":registry_utils",
58+
":result_matcher",
59+
"//:auto_value",
60+
"//bundle:cel",
61+
"//bundle:environment",
62+
"//bundle:environment_exception",
63+
"//bundle:environment_yaml_parser",
64+
"//common:cel_ast",
65+
"//common:compiler_common",
66+
"//common:options",
67+
"//common:proto_ast",
68+
"//java/com/google/protobuf/contrib:util",
69+
"//policy",
70+
"//policy:compiler_factory",
71+
"//policy:parser",
72+
"//policy:parser_factory",
73+
"//policy:validation_exception",
74+
"//runtime",
75+
"//testing:expr_value_utils",
76+
"@cel_spec//proto/cel/expr:expr_java_proto",
77+
"@maven//:com_google_guava_guava",
78+
"@maven//:com_google_protobuf_protobuf_java",
79+
],
80+
)
81+
82+
java_library(
83+
name = "cel_test_suite",
84+
srcs = ["CelTestSuite.java"],
85+
tags = [
86+
],
87+
deps = [
88+
"//:auto_value",
89+
"//common:source",
90+
"@maven//:com_google_errorprone_error_prone_annotations",
91+
"@maven//:com_google_guava_guava",
92+
"@maven//:com_google_protobuf_protobuf_java",
93+
],
94+
)
95+
96+
java_library(
97+
name = "cel_test_suite_yaml_parser",
98+
srcs = ["CelTestSuiteYamlParser.java"],
99+
tags = [
100+
],
101+
deps = [
102+
":cel_test_suite",
103+
":cel_test_suite_exception",
104+
"//common:compiler_common",
105+
"//common/formats:file_source",
106+
"//common/formats:parser_context",
107+
"//common/formats:yaml_helper",
108+
"//common/formats:yaml_parser_context_impl",
109+
"//common/internal",
110+
"@maven//:com_google_guava_guava",
111+
"@maven//:org_yaml_snakeyaml",
112+
],
113+
)
114+
115+
java_library(
116+
name = "cel_test_suite_exception",
117+
srcs = ["CelTestSuiteException.java"],
118+
tags = [
119+
],
120+
deps = ["//common:cel_exception"],
121+
)
122+
123+
java_library(
124+
name = "cel_test_context",
125+
srcs = ["CelTestContext.java"],
126+
tags = [
127+
],
128+
deps = [
129+
":default_result_matcher",
130+
":result_matcher",
131+
"//:auto_value",
132+
"//bundle:cel",
133+
"//common:options",
134+
"//policy:parser",
135+
"//runtime",
136+
"@maven//:com_google_guava_guava",
137+
],
138+
)
139+
140+
java_library(
141+
name = "registry_utils",
142+
srcs = ["RegistryUtils.java"],
143+
deps = [
144+
"//common:cel_descriptors",
145+
"//common/internal:cel_descriptor_pools",
146+
"//common/internal:default_message_factory",
147+
"@maven//:com_google_guava_guava",
148+
"@maven//:com_google_protobuf_protobuf_java",
149+
],
150+
)
151+
152+
java_library(
153+
name = "result_matcher",
154+
srcs = ["ResultMatcher.java"],
155+
deps = [
156+
":cel_test_suite",
157+
"//:auto_value",
158+
"//bundle:cel",
159+
"//common/types:type_providers",
160+
"//runtime",
161+
"@cel_spec//proto/cel/expr:value_java_proto",
162+
],
163+
)
164+
165+
java_library(
166+
name = "default_result_matcher",
167+
srcs = ["DefaultResultMatcher.java"],
168+
deps = [
169+
":cel_test_suite",
170+
":registry_utils",
171+
":result_matcher",
172+
"//:java_truth",
173+
"//bundle:cel",
174+
"//common:cel_ast",
175+
"//runtime",
176+
"//testing:expr_value_utils",
177+
"@cel_spec//proto/cel/expr:value_java_proto",
178+
"@maven//:com_google_guava_guava",
179+
"@maven//:com_google_protobuf_protobuf_java",
180+
"@maven//:com_google_truth_extensions_truth_proto_extension",
181+
],
182+
)
183+
184+
java_library(
185+
name = "cel_test_suite_text_proto_parser",
186+
srcs = ["CelTestSuiteTextProtoParser.java"],
187+
tags = [
188+
],
189+
deps = [
190+
":cel_test_suite",
191+
":cel_test_suite_exception",
192+
":registry_utils",
193+
"//google/rpc:status_java_proto",
194+
"@cel_spec//proto/cel/expr/conformance/test:suite_java_proto",
195+
"@maven//:com_google_guava_guava",
196+
"@maven//:com_google_protobuf_protobuf_java",
197+
],
198+
)
199+
200+
filegroup(
201+
name = "test_runner_binary",
202+
srcs = [
203+
"TestRunnerBinary.java",
204+
],
205+
)
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
package dev.cel.testing.testrunner;
15+
16+
import com.google.auto.value.AutoValue;
17+
import com.google.common.collect.ImmutableMap;
18+
import dev.cel.bundle.Cel;
19+
import dev.cel.bundle.CelFactory;
20+
import dev.cel.common.CelOptions;
21+
import dev.cel.policy.CelPolicyParser;
22+
import dev.cel.runtime.CelLateFunctionBindings;
23+
import java.util.Map;
24+
import java.util.Optional;
25+
26+
/**
27+
* The context class for a CEL test, holding configurations needed to create environments and
28+
* evaluate CEL expressions and policies.
29+
*/
30+
@AutoValue
31+
public abstract class CelTestContext {
32+
33+
private static final Cel DEFAULT_CEL = CelFactory.standardCelBuilder().build();
34+
35+
/**
36+
* The CEL environment for the CEL test.
37+
*
38+
* <p>The CEL environment is created by extending the provided base CEL environment with the
39+
* config file if provided.
40+
*/
41+
public abstract Cel cel();
42+
43+
/**
44+
* The CEL policy parser for the CEL test.
45+
*
46+
* <p>A custom parser to be used for parsing CEL policies in scenarios where custom policy tags
47+
* are used. If not provided, the default CEL policy parser will be used.
48+
*/
49+
public abstract Optional<CelPolicyParser> celPolicyParser();
50+
51+
/**
52+
* The CEL options for the CEL test.
53+
*
54+
* <p>The CEL options are used to configure the {@link Cel} environment.
55+
*/
56+
public abstract CelOptions celOptions();
57+
58+
/**
59+
* The late function bindings for the CEL test.
60+
*
61+
* <p>These bindings are used to provide functions which are to be consumed during the eval phase
62+
* directly.
63+
*/
64+
public abstract Optional<CelLateFunctionBindings> celLateFunctionBindings();
65+
66+
/**
67+
* The variable bindings for the CEL test.
68+
*
69+
* <p>These bindings are used to provide values for variables for which it is difficult to provide
70+
* a value in the test suite file for example, using proto extensions or fetching the value from
71+
* some other source.
72+
*/
73+
public abstract ImmutableMap<String, Object> variableBindings();
74+
75+
/**
76+
* The result matcher for the CEL test.
77+
*
78+
* <p>This matcher is used to perform assertions on the result of a CEL test case.
79+
*/
80+
public abstract ResultMatcher resultMatcher();
81+
82+
/** Returns a builder for {@link CelTestContext} with the current instance's values. */
83+
public abstract Builder toBuilder();
84+
85+
/** Returns a new builder for {@link CelTestContext}. */
86+
public static CelTestContext.Builder newBuilder() {
87+
return new AutoValue_CelTestContext.Builder()
88+
.setCel(DEFAULT_CEL)
89+
.setCelOptions(CelOptions.DEFAULT)
90+
.setVariableBindings(ImmutableMap.of())
91+
.setResultMatcher(new DefaultResultMatcher());
92+
}
93+
94+
/** Builder for {@link CelTestContext}. */
95+
@AutoValue.Builder
96+
public abstract static class Builder {
97+
public abstract Builder setCel(Cel cel);
98+
99+
public abstract Builder setCelPolicyParser(CelPolicyParser celPolicyParser);
100+
101+
public abstract Builder setCelOptions(CelOptions celOptions);
102+
103+
public abstract Builder setCelLateFunctionBindings(
104+
CelLateFunctionBindings celLateFunctionBindings);
105+
106+
public abstract Builder setVariableBindings(Map<String, Object> variableBindings);
107+
108+
public abstract Builder setResultMatcher(ResultMatcher resultMatcher);
109+
110+
public abstract CelTestContext build();
111+
}
112+
}

0 commit comments

Comments
 (0)