GMAuditMetadataLogEntity extends AuditMetadataLogEntity { @Override public String toJsonFormatLog() throws Exception { StringWriter stringWriter = new StringWriter(); JsonGenerator json = null; try { json = factory.createJsonGenerator(stringWriter); json.writeStartObject(); json.writeStringField(Constants.LOG_FIELD_SERVICE_NAME, serviceName); json.writeStringField(Constants.LOG_FIELD_USER_NAME, userName); json.writeStringField(Constants.LOG_FIELD_IMPERSONATOR, impersonator); json.writeStringField(Constants.LOG_FIELD_IP_ADDRESS, ipAddress); json.writeStringField(Constants.LOG_FIELD_OPERATION, operation); json.writeStringField(Constants.LOG_FIELD_EVENT_TIME, eventTime); json.writeStringField(Constants.LOG_FIELD_OPERATION_TEXT, operationText); json.writeStringField(Constants.LOG_FIELD_ALLOWED, allowed); for (Map.Entry<String, String> entry : privilegesMap.entrySet()) { json.writeStringField(entry.getKey(), entry.getValue()); } json.writeStringField(Constants.LOG_FIELD_OBJECT_TYPE, objectType); json.writeStringField(Constants.LOG_FIELD_COMPONENT, component); json.writeEndObject(); json.flush(); } catch (IOException e) { String msg = "Error creating audit log in json format: " + e.getMessage(); LOGGER.error(msg, e); throw e; } finally { try { if (json != null) { json.close(); } } catch (IOException e) { throw e; } } return stringWriter.toString(); } GMAuditMetadataLogEntity();  GMAuditMetadataLogEntity(String serviceName, String userName, String impersonator,
      String ipAddress, String operation, String eventTime, String operationText, String allowed,
      String objectType, String component, Map<String, String> privilegesMap); @Override String toJsonFormatLog(); Map<String, String> getPrivilegesMap(); void setPrivilegesMap(Map<String, String> privilegesMap);  }
@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"); }