|
17 | 17 | import static com.google.common.truth.Truth.assertThat; |
18 | 18 |
|
19 | 19 | import dev.cel.expr.CheckedExpr; |
| 20 | +import com.google.api.expr.v1alpha1.Constant; |
| 21 | +import com.google.api.expr.v1alpha1.Expr; |
| 22 | +import com.google.api.expr.v1alpha1.Type.PrimitiveType; |
20 | 23 | import com.google.common.collect.ImmutableMap; |
21 | 24 | import com.google.protobuf.Any; |
22 | 25 | import com.google.protobuf.ByteString; |
23 | 26 | import com.google.protobuf.ExtensionRegistry; |
24 | 27 | import com.google.rpc.context.AttributeContext; |
25 | 28 | import dev.cel.common.CelOptions; |
26 | 29 | import dev.cel.common.CelProtoAbstractSyntaxTree; |
| 30 | +import dev.cel.common.CelProtoV1Alpha1AbstractSyntaxTree; |
| 31 | +import dev.cel.common.types.CelV1AlphaTypes; |
27 | 32 | import java.util.Base64; |
28 | 33 | import org.junit.Test; |
29 | 34 | import org.junit.runner.RunWith; |
@@ -74,4 +79,27 @@ public void evaluate_anyPackedEqualityUsingProtoDifferencer_success() throws Exc |
74 | 79 |
|
75 | 80 | assertThat(evaluatedResult).isEqualTo(true); |
76 | 81 | } |
| 82 | + |
| 83 | + @Test |
| 84 | + public void evaluate_v1alpha1CheckedExpr() throws Exception { |
| 85 | + // Note: v1alpha1 proto support exists only to help migrate existing consumers. |
| 86 | + // New users of CEL should use the canonical protos instead (I.E: dev.cel.expr) |
| 87 | + com.google.api.expr.v1alpha1.CheckedExpr checkedExpr = |
| 88 | + com.google.api.expr.v1alpha1.CheckedExpr.newBuilder() |
| 89 | + .setExpr( |
| 90 | + Expr.newBuilder() |
| 91 | + .setId(1) |
| 92 | + .setConstExpr(Constant.newBuilder().setStringValue("Hello world!").build()) |
| 93 | + .build()) |
| 94 | + .putTypeMap(1, CelV1AlphaTypes.create(PrimitiveType.STRING)) |
| 95 | + .build(); |
| 96 | + CelRuntime celRuntime = CelRuntimeFactory.standardCelRuntimeBuilder().build(); |
| 97 | + CelRuntime.Program program = |
| 98 | + celRuntime.createProgram( |
| 99 | + CelProtoV1Alpha1AbstractSyntaxTree.fromCheckedExpr(checkedExpr).getAst()); |
| 100 | + |
| 101 | + String evaluatedResult = (String) program.eval(); |
| 102 | + |
| 103 | + assertThat(evaluatedResult).isEqualTo("Hello world!"); |
| 104 | + } |
77 | 105 | } |
0 commit comments