org.codehaus.jackson.node.ContainerNode Java Examples
The following examples show how to use
org.codehaus.jackson.node.ContainerNode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestDbAuditMetadataLogEntity.java From incubator-sentry with Apache License 2.0 | 6 votes |
@Test public void testToJsonFormatLog() throws Throwable { DBAuditMetadataLogEntity amle = new DBAuditMetadataLogEntity("serviceName", "userName", "impersonator", "ipAddress", "operation", "eventTime", "operationText", "allowed", "objectType", "component", "databaseName", "tableName", "columnName", "resourcePath"); String jsonAuditLog = amle.toJsonFormatLog(); ContainerNode rootNode = AuditMetadataLogEntity.parse(jsonAuditLog); assertEntryEquals(rootNode, Constants.LOG_FIELD_SERVICE_NAME, "serviceName"); assertEntryEquals(rootNode, Constants.LOG_FIELD_USER_NAME, "userName"); assertEntryEquals(rootNode, Constants.LOG_FIELD_IMPERSONATOR, "impersonator"); assertEntryEquals(rootNode, Constants.LOG_FIELD_IP_ADDRESS, "ipAddress"); assertEntryEquals(rootNode, Constants.LOG_FIELD_OPERATION, "operation"); assertEntryEquals(rootNode, Constants.LOG_FIELD_EVENT_TIME, "eventTime"); assertEntryEquals(rootNode, Constants.LOG_FIELD_OPERATION_TEXT, "operationText"); assertEntryEquals(rootNode, Constants.LOG_FIELD_ALLOWED, "allowed"); assertEntryEquals(rootNode, Constants.LOG_FIELD_DATABASE_NAME, "databaseName"); assertEntryEquals(rootNode, Constants.LOG_FIELD_TABLE_NAME, "tableName"); assertEntryEquals(rootNode, Constants.LOG_FIELD_COLUMN_NAME, "columnName"); assertEntryEquals(rootNode, Constants.LOG_FIELD_RESOURCE_PATH, "resourcePath"); assertEntryEquals(rootNode, Constants.LOG_FIELD_OBJECT_TYPE, "objectType"); }
Example #2
Source File: TestLog4Json.java From big-c with Apache License 2.0 | 5 votes |
private JsonNode assertNodeContains(ContainerNode rootNode, String key) { JsonNode node = rootNode.get(key); if (node == null) { fail("No entry of name \"" + key + "\" found in " + rootNode.toString()); } return node; }
Example #3
Source File: TestGMAuditMetadataLogEntity.java From incubator-sentry with Apache License 2.0 | 5 votes |
private JsonNode assertNodeContains(ContainerNode rootNode, String key) { JsonNode node = rootNode.get(key); if (node == null) { fail("No entry of name \"" + key + "\" found in " + rootNode.toString()); } return node; }
Example #4
Source File: TestGMAuditMetadataLogEntity.java From incubator-sentry with Apache License 2.0 | 5 votes |
@Test public void testToJsonFormatLog() throws Throwable { Map<String, String> privilegesMap = new HashMap<String, String>(); privilegesMap.put("resourceType1", "resourceName1"); privilegesMap.put("resourceType2", "resourceName2"); privilegesMap.put("resourceType3", "resourceName3"); privilegesMap.put("resourceType4", "resourceName4"); GMAuditMetadataLogEntity gmamle = new GMAuditMetadataLogEntity("serviceName", "userName", "impersonator", "ipAddress", "operation", "eventTime", "operationText", "allowed", "objectType", "component", privilegesMap); String jsonAuditLog = gmamle.toJsonFormatLog(); ContainerNode rootNode = AuditMetadataLogEntity.parse(jsonAuditLog); assertEntryEquals(rootNode, Constants.LOG_FIELD_SERVICE_NAME, "serviceName"); assertEntryEquals(rootNode, Constants.LOG_FIELD_USER_NAME, "userName"); assertEntryEquals(rootNode, Constants.LOG_FIELD_IMPERSONATOR, "impersonator"); assertEntryEquals(rootNode, Constants.LOG_FIELD_IP_ADDRESS, "ipAddress"); assertEntryEquals(rootNode, Constants.LOG_FIELD_OPERATION, "operation"); assertEntryEquals(rootNode, Constants.LOG_FIELD_EVENT_TIME, "eventTime"); assertEntryEquals(rootNode, Constants.LOG_FIELD_OPERATION_TEXT, "operationText"); assertEntryEquals(rootNode, Constants.LOG_FIELD_ALLOWED, "allowed"); assertEntryEquals(rootNode, Constants.LOG_FIELD_OBJECT_TYPE, "objectType"); assertEntryEquals(rootNode, Constants.LOG_FIELD_COMPONENT, "component"); assertEntryEquals(rootNode, "resourceType1", "resourceName1"); assertEntryEquals(rootNode, "resourceType2", "resourceName2"); assertEntryEquals(rootNode, "resourceType3", "resourceName3"); assertEntryEquals(rootNode, "resourceType4", "resourceName4"); }
Example #5
Source File: TestDbAuditMetadataLogEntity.java From incubator-sentry with Apache License 2.0 | 5 votes |
private JsonNode assertNodeContains(ContainerNode rootNode, String key) { JsonNode node = rootNode.get(key); if (node == null) { fail("No entry of name \"" + key + "\" found in " + rootNode.toString()); } return node; }
Example #6
Source File: Log4Json.java From hadoop with Apache License 2.0 | 5 votes |
/** * For use in tests * * @param json incoming JSON to parse * @return a node tree * @throws IOException on any parsing problems */ public static ContainerNode parse(String json) throws IOException { ObjectMapper mapper = new ObjectMapper(factory); JsonNode jsonNode = mapper.readTree(json); if (!(jsonNode instanceof ContainerNode)) { throw new IOException("Wrong JSON data: " + json); } return (ContainerNode) jsonNode; }
Example #7
Source File: TestLog4Json.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testNestedException() throws Throwable { Exception e = new NoRouteToHostException("that box caught fire 3 years ago"); Exception ioe = new IOException("Datacenter problems", e); ThrowableInformation ti = new ThrowableInformation(ioe); Log4Json l4j = new Log4Json(); long timeStamp = Time.now(); String outcome = l4j.toJson(new StringWriter(), "testNestedException", timeStamp, "INFO", "quoted\"", "new line\n and {}", ti) .toString(); println("testNestedException", outcome); ContainerNode rootNode = Log4Json.parse(outcome); assertEntryEquals(rootNode, Log4Json.LEVEL, "INFO"); assertEntryEquals(rootNode, Log4Json.NAME, "testNestedException"); assertEntryEquals(rootNode, Log4Json.TIME, timeStamp); assertEntryEquals(rootNode, Log4Json.EXCEPTION_CLASS, ioe.getClass().getName()); JsonNode node = assertNodeContains(rootNode, Log4Json.STACK); assertTrue("Not an array: " + node, node.isArray()); node = assertNodeContains(rootNode, Log4Json.DATE); assertTrue("Not a string: " + node, node.isTextual()); //rather than try and make assertions about the format of the text //message equalling another ISO date, this test asserts that the hypen //and colon characters are in the string. String dateText = node.getTextValue(); assertTrue("No '-' in " + dateText, dateText.contains("-")); assertTrue("No '-' in " + dateText, dateText.contains(":")); }
Example #8
Source File: Log4Json.java From big-c with Apache License 2.0 | 5 votes |
/** * For use in tests * * @param json incoming JSON to parse * @return a node tree * @throws IOException on any parsing problems */ public static ContainerNode parse(String json) throws IOException { ObjectMapper mapper = new ObjectMapper(factory); JsonNode jsonNode = mapper.readTree(json); if (!(jsonNode instanceof ContainerNode)) { throw new IOException("Wrong JSON data: " + json); } return (ContainerNode) jsonNode; }
Example #9
Source File: TestLog4Json.java From hadoop with Apache License 2.0 | 5 votes |
private JsonNode assertNodeContains(ContainerNode rootNode, String key) { JsonNode node = rootNode.get(key); if (node == null) { fail("No entry of name \"" + key + "\" found in " + rootNode.toString()); } return node; }
Example #10
Source File: TestLog4Json.java From hadoop with Apache License 2.0 | 5 votes |
@Test public void testNestedException() throws Throwable { Exception e = new NoRouteToHostException("that box caught fire 3 years ago"); Exception ioe = new IOException("Datacenter problems", e); ThrowableInformation ti = new ThrowableInformation(ioe); Log4Json l4j = new Log4Json(); long timeStamp = Time.now(); String outcome = l4j.toJson(new StringWriter(), "testNestedException", timeStamp, "INFO", "quoted\"", "new line\n and {}", ti) .toString(); println("testNestedException", outcome); ContainerNode rootNode = Log4Json.parse(outcome); assertEntryEquals(rootNode, Log4Json.LEVEL, "INFO"); assertEntryEquals(rootNode, Log4Json.NAME, "testNestedException"); assertEntryEquals(rootNode, Log4Json.TIME, timeStamp); assertEntryEquals(rootNode, Log4Json.EXCEPTION_CLASS, ioe.getClass().getName()); JsonNode node = assertNodeContains(rootNode, Log4Json.STACK); assertTrue("Not an array: " + node, node.isArray()); node = assertNodeContains(rootNode, Log4Json.DATE); assertTrue("Not a string: " + node, node.isTextual()); //rather than try and make assertions about the format of the text //message equalling another ISO date, this test asserts that the hypen //and colon characters are in the string. String dateText = node.getTextValue(); assertTrue("No '-' in " + dateText, dateText.contains("-")); assertTrue("No '-' in " + dateText, dateText.contains(":")); }
Example #11
Source File: TestLog4Json.java From big-c with Apache License 2.0 | 4 votes |
void assertEntryEquals(ContainerNode rootNode, String key, String value) { JsonNode node = assertNodeContains(rootNode, key); assertEquals(value, node.getTextValue()); }
Example #12
Source File: TestLog4Json.java From big-c with Apache License 2.0 | 4 votes |
void assertEntryEquals(ContainerNode rootNode, String key, long value) { JsonNode node = assertNodeContains(rootNode, key); assertEquals(value, node.getNumberValue()); }
Example #13
Source File: TestLog4Json.java From hadoop with Apache License 2.0 | 4 votes |
void assertEntryEquals(ContainerNode rootNode, String key, long value) { JsonNode node = assertNodeContains(rootNode, key); assertEquals(value, node.getNumberValue()); }
Example #14
Source File: TestDbAuditMetadataLogEntity.java From incubator-sentry with Apache License 2.0 | 4 votes |
void assertEntryEquals(ContainerNode rootNode, String key, String value) { JsonNode node = assertNodeContains(rootNode, key); assertEquals(value, node.getTextValue()); }
Example #15
Source File: TestLog4Json.java From hadoop with Apache License 2.0 | 4 votes |
void assertEntryEquals(ContainerNode rootNode, String key, String value) { JsonNode node = assertNodeContains(rootNode, key); assertEquals(value, node.getTextValue()); }
Example #16
Source File: TestGMAuditMetadataLogEntity.java From incubator-sentry with Apache License 2.0 | 4 votes |
void assertEntryEquals(ContainerNode rootNode, String key, String value) { JsonNode node = assertNodeContains(rootNode, key); assertEquals(value, node.getTextValue()); }
Example #17
Source File: AuditMetadataLogEntity.java From incubator-sentry with Apache License 2.0 | 3 votes |
/** * For use in tests * * @param json * incoming JSON to parse * @return a node tree * @throws IOException * on any parsing problems */ public static ContainerNode parse(String json) throws IOException { ObjectMapper mapper = new ObjectMapper(factory); JsonNode jsonNode = mapper.readTree(json); if (!(jsonNode instanceof ContainerNode)) { throw new IOException("Wrong JSON data: " + json); } return (ContainerNode) jsonNode; }