MCPcopy Create free account
hub / github.com/cedar-policy/cedar-java / get_json_schema_internal_valid

Function get_json_schema_internal_valid

CedarJavaFFI/src/interface.rs:1875–1925  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1873
1874 #[test]
1875 fn get_json_schema_internal_valid() {
1876 let mut env = JVM.attach_current_thread().unwrap();
1877 let cedar_input = r#"
1878 namespace schema {
1879 entity File;
1880
1881 entity Group;
1882
1883 entity User in [Group];
1884
1885 action "read" appliesTo {
1886 principal: [User],
1887 resource: [File],
1888 context: {}
1889 };
1890 }
1891 "#;
1892
1893 let jstr = env.new_string(cedar_input).unwrap();
1894 let result = get_json_schema_internal(&mut env, jstr);
1895 assert!(result.is_ok(), "Expected JSON conversion to succeed");
1896
1897 let json_jval = result.unwrap();
1898 let json_jstr = JString::cast(&mut env, json_jval.l().unwrap()).unwrap();
1899 let json_str = String::from(env.get_string(&json_jstr).unwrap());
1900 let actual_json: serde_json::Value = serde_json::from_str(&json_str).unwrap();
1901 let expected_json = serde_json::json!({
1902 "schema": {
1903 "entityTypes": {
1904 "File": {},
1905 "Group": {},
1906 "User": {
1907 "memberOfTypes": ["Group"]
1908 }
1909 },
1910 "actions": {
1911 "read": {
1912 "appliesTo": {
1913 "principalTypes": ["User"],
1914 "resourceTypes": ["File"]
1915 }
1916 }
1917 }
1918 }
1919 });
1920
1921 assert_eq!(
1922 actual_json, expected_json,
1923 "JSON schema doesn't match expected structure"
1924 );
1925 }
1926
1927 #[test]
1928 fn get_json_schema_internal_null() {

Callers

nothing calls this directly

Calls 1

get_json_schema_internalFunction · 0.85

Tested by

no test coverage detected