Skip to content

Commit 06e27f7

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

32 files changed

+4128
-0
lines changed
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
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+
"@maven//:com_google_guava_guava",
23+
"@maven//:junit_junit",
24+
],
25+
)
26+
27+
java_library(
28+
name = "junit_xml_reporter",
29+
srcs = ["JUnitXmlReporter.java"],
30+
tags = [
31+
],
32+
deps = ["@maven//:com_google_guava_guava"],
33+
)
34+
35+
java_library(
36+
name = "cel_user_test_template",
37+
srcs = ["CelUserTestTemplate.java"],
38+
tags = [
39+
],
40+
deps = [
41+
":cel_test_context",
42+
":cel_test_suite",
43+
":test_runner_library",
44+
"@maven//:junit_junit",
45+
],
46+
)
47+
48+
java_library(
49+
name = "test_runner_library",
50+
srcs = ["TestRunnerLibrary.java"],
51+
tags = [
52+
],
53+
deps = [
54+
":cel_test_context",
55+
":cel_test_suite",
56+
":registry_utils",
57+
":result_matcher",
58+
"//:auto_value",
59+
"//bundle:cel",
60+
"//bundle:environment",
61+
"//bundle:environment_exception",
62+
"//bundle:environment_yaml_parser",
63+
"//common:cel_ast",
64+
"//common:compiler_common",
65+
"//common:options",
66+
"//common:proto_ast",
67+
"//policy",
68+
"//policy:compiler_factory",
69+
"//policy:parser",
70+
"//policy:parser_factory",
71+
"//policy:validation_exception",
72+
"//runtime",
73+
"//testing:expr_value_utils",
74+
"@cel_spec//proto/cel/expr:expr_java_proto",
75+
"@maven//:com_google_guava_guava",
76+
"@maven//:com_google_protobuf_protobuf_java",
77+
"@maven//:com_google_protobuf_protobuf_java_contrib",
78+
],
79+
)
80+
81+
java_library(
82+
name = "cel_test_suite",
83+
srcs = ["CelTestSuite.java"],
84+
tags = [
85+
],
86+
deps = [
87+
"//:auto_value",
88+
"//common:source",
89+
"@maven//:com_google_errorprone_error_prone_annotations",
90+
"@maven//:com_google_guava_guava",
91+
"@maven//:com_google_protobuf_protobuf_java",
92+
],
93+
)
94+
95+
java_library(
96+
name = "cel_test_suite_yaml_parser",
97+
srcs = ["CelTestSuiteYamlParser.java"],
98+
tags = [
99+
],
100+
deps = [
101+
":cel_test_suite",
102+
":cel_test_suite_exception",
103+
"//common:compiler_common",
104+
"//common/formats:file_source",
105+
"//common/formats:parser_context",
106+
"//common/formats:yaml_helper",
107+
"//common/formats:yaml_parser_context_impl",
108+
"//common/internal",
109+
"@maven//:com_google_guava_guava",
110+
"@maven//:org_yaml_snakeyaml",
111+
],
112+
)
113+
114+
java_library(
115+
name = "cel_test_suite_exception",
116+
srcs = ["CelTestSuiteException.java"],
117+
tags = [
118+
],
119+
deps = ["//common:cel_exception"],
120+
)
121+
122+
java_library(
123+
name = "cel_test_context",
124+
srcs = ["CelTestContext.java"],
125+
tags = [
126+
],
127+
deps = [
128+
":default_result_matcher",
129+
":result_matcher",
130+
"//:auto_value",
131+
"//bundle:cel",
132+
"//common:options",
133+
"//policy:parser",
134+
"//runtime",
135+
"@maven//:com_google_guava_guava",
136+
],
137+
)
138+
139+
java_library(
140+
name = "registry_utils",
141+
srcs = ["RegistryUtils.java"],
142+
deps = [
143+
"//common:cel_descriptors",
144+
"//common/internal:cel_descriptor_pools",
145+
"//common/internal:default_message_factory",
146+
"@maven//:com_google_guava_guava",
147+
"@maven//:com_google_protobuf_protobuf_java",
148+
],
149+
)
150+
151+
java_library(
152+
name = "result_matcher",
153+
srcs = ["ResultMatcher.java"],
154+
deps = [
155+
":cel_test_suite",
156+
"//:auto_value",
157+
"//bundle:cel",
158+
"//common/types:type_providers",
159+
"//runtime",
160+
"@cel_spec//proto/cel/expr:value_java_proto",
161+
],
162+
)
163+
164+
java_library(
165+
name = "default_result_matcher",
166+
srcs = ["DefaultResultMatcher.java"],
167+
deps = [
168+
":cel_test_suite",
169+
":registry_utils",
170+
":result_matcher",
171+
"//:java_truth",
172+
"//bundle:cel",
173+
"//common:cel_ast",
174+
"//runtime",
175+
"//testing:expr_value_utils",
176+
"@cel_spec//proto/cel/expr:value_java_proto",
177+
"@maven//:com_google_guava_guava",
178+
"@maven//:com_google_protobuf_protobuf_java",
179+
"@maven//:com_google_truth_extensions_truth_proto_extension",
180+
],
181+
)
182+
183+
java_library(
184+
name = "cel_test_suite_text_proto_parser",
185+
srcs = ["CelTestSuiteTextProtoParser.java"],
186+
tags = [
187+
],
188+
deps = [
189+
":cel_test_suite",
190+
":cel_test_suite_exception",
191+
":registry_utils",
192+
"@cel_spec//proto/cel/expr/conformance/test:suite_java_proto",
193+
"@maven//:com_google_api_grpc_proto_google_common_protos",
194+
"@maven//:com_google_guava_guava",
195+
"@maven//:com_google_protobuf_protobuf_java",
196+
],
197+
)
198+
199+
filegroup(
200+
name = "test_runner_binary",
201+
srcs = [
202+
"TestRunnerBinary.java",
203+
],
204+
)
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)