use of com.google.api.expr.v1alpha1.CheckResponse in project cel-java by projectnessie.
the class ConformanceServerTest method fullPipeline.
/**
* fullPipeline parses, checks, and evaluates the CEL expression in source and returns the result
* from the Eval call.
*/
FullPipelineResult fullPipeline(String source) {
// Parse
ParseRequest preq = ParseRequest.newBuilder().setCelSource(source).build();
ParseResponse pres = stub.parse(preq);
assertThat(pres.isInitialized()).isTrue();
ParsedExpr parsedExpr = pres.getParsedExpr();
assertThat(parsedExpr.isInitialized()).isTrue();
assertThat(parsedExpr.getExpr().isInitialized()).isTrue();
// Check
CheckRequest creq = CheckRequest.newBuilder().setParsedExpr(parsedExpr).build();
CheckResponse cres = stub.check(creq);
assertThat(cres.isInitialized()).isTrue();
CheckedExpr checkedExpr = cres.getCheckedExpr();
assertThat(checkedExpr.isInitialized()).isTrue();
// Eval
EvalRequest ereq = EvalRequest.newBuilder().setCheckedExpr(checkedExpr).build();
EvalResponse eres = stub.eval(ereq);
assertThat(eres.isInitialized()).isTrue();
assertThat(eres.getResult().isInitialized()).isTrue();
return new FullPipelineResult(pres, cres, eres);
}
use of com.google.api.expr.v1alpha1.CheckResponse in project cel-java by projectnessie.
the class ConformanceServiceImpl method check.
@Override
public void check(CheckRequest request, io.grpc.stub.StreamObserver<CheckResponse> responseObserver) {
try {
// Build the environment.
List<EnvOption> checkOptions = new ArrayList<>();
if (!request.getNoStdEnv()) {
checkOptions.add(StdLib());
}
checkOptions.add(container(request.getContainer()));
checkOptions.add(declarations(request.getTypeEnvList()));
checkOptions.add(types(com.google.api.expr.test.v1.proto2.TestAllTypesProto.TestAllTypes.getDefaultInstance(), com.google.api.expr.test.v1.proto3.TestAllTypesProto.TestAllTypes.getDefaultInstance()));
Env env = newCustomEnv(checkOptions.toArray(new EnvOption[0]));
// Check the expression.
AstIssuesTuple astIss = env.check(parsedExprToAst(request.getParsedExpr()));
CheckResponse.Builder resp = CheckResponse.newBuilder();
if (!astIss.hasIssues()) {
// Success
resp.setCheckedExpr(astToCheckedExpr(astIss.getAst()));
} else {
// Failure
appendErrors(astIss.getIssues().getErrors(), resp::addIssuesBuilder);
}
responseObserver.onNext(resp.build());
responseObserver.onCompleted();
} catch (Exception e) {
responseObserver.onError(io.grpc.Status.fromCode(io.grpc.Status.Code.UNKNOWN).withDescription(stacktrace(e)).asException());
}
}
use of com.google.api.expr.v1alpha1.CheckResponse in project cel-java by projectnessie.
the class ConformanceServerTest method Check.
/**
* TestCheck tests the Check method.
*/
@Test
void Check() {
// If TestParse() passes, it validates a good chunk
// of the server mechanisms for data conversion, so we
// won't be as fussy here..
CheckRequest req = CheckRequest.newBuilder().setParsedExpr(parsed).build();
CheckResponse res = stub.check(req);
assertThat(res.isInitialized()).isTrue();
assertThat(res.getCheckedExpr().isInitialized()).isTrue();
Type tp = res.getCheckedExpr().getTypeMapMap().get(1L);
assertThat(tp).isNotNull();
assertThat(tp.getTypeKindCase()).isSameAs(TypeKindCase.PRIMITIVE);
assertThat(tp.getPrimitive()).isSameAs(PrimitiveType.INT64);
}
use of com.google.api.expr.v1alpha1.CheckResponse in project cel-java by projectnessie.
the class ConformanceServerTest method FullUp.
/**
* TestFullUp tests Parse, Check, and Eval back-to-back.
*/
@Test
void FullUp() {
ParseRequest preq = ParseRequest.newBuilder().setCelSource("x + y").build();
ParseResponse pres = stub.parse(preq);
assertThat(pres.isInitialized()).isTrue();
ParsedExpr parsedExpr = pres.getParsedExpr();
assertThat(parsedExpr.isInitialized()).isTrue();
CheckRequest creq = CheckRequest.newBuilder().setParsedExpr(parsedExpr).addTypeEnv(Decls.newVar("x", Decls.Int)).addTypeEnv(Decls.newVar("y", Decls.Int)).build();
CheckResponse cres = stub.check(creq);
assertThat(cres.isInitialized()).isTrue();
CheckedExpr checkedExpr = cres.getCheckedExpr();
assertThat(checkedExpr.isInitialized()).isTrue();
Type tp = checkedExpr.getTypeMapMap().get(1L);
assertThat(tp).isNotNull();
assertThat(tp.getTypeKindCase()).isSameAs(TypeKindCase.PRIMITIVE);
assertThat(tp.getPrimitive()).isSameAs(PrimitiveType.INT64);
EvalRequest ereq = EvalRequest.newBuilder().setCheckedExpr(checkedExpr).putBindings("x", exprValueInt64(1)).putBindings("y", exprValueInt64(2)).build();
EvalResponse eres = stub.eval(ereq);
assertThat(eres.isInitialized()).isTrue();
assertThat(eres.getResult().isInitialized()).isTrue();
assertThat(eres.getResult().getKindCase()).isSameAs(KindCase.VALUE);
assertThat(eres.getResult().getValue().getKindCase()).isSameAs(Value.KindCase.INT64_VALUE);
assertThat(eres.getResult().getValue().getInt64Value()).isEqualTo(3L);
}
Aggregations