mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
- c, cpp - csharp - ffi - go - Java - Python - WASM `arc` feature is turned on for all bindings Use pretty string instead of colored string. Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
37 lines
1.0 KiB
Java
37 lines
1.0 KiB
Java
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT License.
|
|
|
|
import com.microsoft.regorus.Engine;
|
|
|
|
public class Test {
|
|
public static void main(String[] args) {
|
|
try (Engine engine = new Engine()) {
|
|
String pkg = engine.addPolicy(
|
|
"hello.rego",
|
|
"package test\nx=1\nmessage = concat(\", \", [input.message, data.message])"
|
|
);
|
|
System.out.println("Loaded package " + pkg);
|
|
|
|
|
|
engine.addDataJson("{\"message\":\"World!\"}");
|
|
engine.setInputJson("{\"message\":\"Hello\"}");
|
|
|
|
// Evaluate query.
|
|
String resJson = engine.evalQuery("data.test.message");
|
|
System.out.println(resJson);
|
|
|
|
// Enable coverage.
|
|
engine.setEnableCoverage(true);
|
|
|
|
// Evaluate rule.
|
|
String valueJson = engine.evalRule("data.test.message");
|
|
System.out.println(valueJson);
|
|
|
|
String coverageJson = engine.getCoverageReport();
|
|
System.out.println(coverageJson);
|
|
|
|
System.out.println(engine.getCoverageReportPretty());
|
|
}
|
|
}
|
|
}
|