SystemFlagsDataArchive { static String normalizeJson(String json) { JsonNode root = uncheck(() -> mapper.readTree(json)); removeCommentsRecursively(root); verifyValues(root); return root.toString(); } private  SystemFlagsDataArchive(Map<FlagId, Map<String, FlagData>> files); static SystemFlagsDataArchive fromZip(InputStream rawIn); static SystemFlagsDataArchive fromDirectory(Path directory); void toZip(OutputStream out); Set<FlagData> flagData(FlagsTarget target); void validateAllFilesAreForTargets(SystemName currentSystem, Set<FlagsTarget> targets);  }
@Test public void remove_comments() { assertTrue(JSON.equals("{\n" + " \"a\": {\n" + " \"b\": 1\n" + " },\n" + " \"list\": [\n" + " {\n" + " \"c\": 2\n" + " },\n" + " {\n" + " }\n" + " ]\n" + "}", SystemFlagsDataArchive.normalizeJson("{\n" + " \"comment\": \"comment a\",\n" + " \"a\": {\n" + " \"comment\": \"comment b\",\n" + " \"b\": 1\n" + " },\n" + " \"list\": [\n" + " {\n" + " \"comment\": \"comment c\",\n" + " \"c\": 2\n" + " },\n" + " {\n" + " \"comment\": \"comment d\"\n" + " }\n" + " ]\n" + "}"))); }
@Test public void normalize_json_fail_on_invalid_application() { try { SystemFlagsDataArchive.normalizeJson("{\n" + " \"id\": \"foo\",\n" + " \"rules\": [\n" + " {\n" + " \"conditions\": [\n" + " {\n" + " \"type\": \"whitelist\",\n" + " \"dimension\": \"application\",\n" + " \"values\": [ \"a.b.c\" ]\n" + " }\n" + " ],\n" + " \"value\": true\n" + " }\n" + " ]\n" + "}\n"); fail(); } catch (IllegalArgumentException e) { assertEquals("Application ids must be on the form tenant:application:instance, but was a.b.c", e.getMessage()); } }
@Test public void normalize_json_fail_on_invalid_node_type() { try { SystemFlagsDataArchive.normalizeJson("{\n" + " \"id\": \"foo\",\n" + " \"rules\": [\n" + " {\n" + " \"conditions\": [\n" + " {\n" + " \"type\": \"whitelist\",\n" + " \"dimension\": \"node-type\",\n" + " \"values\": [ \"footype\" ]\n" + " }\n" + " ],\n" + " \"value\": true\n" + " }\n" + " ]\n" + "}\n"); fail(); } catch (IllegalArgumentException e) { assertEquals("No enum constant com.yahoo.config.provision.NodeType.footype", e.getMessage()); } }
@Test public void normalize_json_fail_on_invalid_email() { try { SystemFlagsDataArchive.normalizeJson("{\n" + " \"id\": \"foo\",\n" + " \"rules\": [\n" + " {\n" + " \"conditions\": [\n" + " {\n" + " \"type\": \"whitelist\",\n" + " \"dimension\": \"console-user-email\",\n" + " \"values\": [ 123 ]\n" + " }\n" + " ],\n" + " \"value\": true\n" + " }\n" + " ]\n" + "}\n"); fail(); } catch (IllegalArgumentException e) { assertEquals("Non-string email address: 123", e.getMessage()); } }