ZMSFileChangeLogStoreCommon { byte[] jsonValueAsBytes(Object obj, Class<?> cls) { try { return jsonMapper.writerWithView(cls).writeValueAsBytes(obj); } catch (Exception ex) { LOGGER.error("Unable to serialize json object: {}", ex.getMessage()); return null; } } ZMSFileChangeLogStoreCommon(final String rootDirectory); boolean supportsFullRefresh(); SignedDomain getLocalSignedDomain(final String domainName); SignedDomain getServerSignedDomain(ZMSClient zmsClient, final String domainName); void removeLocalDomain(String domainName); void saveLocalDomain(String domainName, SignedDomain signedDomain); synchronized T get(String name, Class<T> classType); synchronized void put(String name, byte[] data); synchronized void delete(String name); List<String> getLocalDomainList(); Set<String> getServerDomainList(ZMSClient zmsClient); SignedDomains getServerDomainModifiedList(ZMSClient zmsClient); String retrieveLastModificationTime(); void setLastModificationTimestamp(String newLastModTime); String retrieveTagHeader(Map<String, List<String>> responseHeaders); SignedDomains getUpdatedSignedDomains(ZMSClient zmsClient, StringBuilder lastModTimeBuffer); public String lastModTime; }
@Test public void testJsonValueAsBytes() { ZMSFileChangeLogStoreCommon fstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH); ObjectMapper mapper = Mockito.mock(ObjectMapper.class); Mockito.when(mapper.writerWithView(Struct.class)).thenThrow(new RuntimeException("invalid class")); fstore.jsonMapper = mapper; Struct testStruct = new Struct(); testStruct.putIfAbsent("key", "value"); assertNull(fstore.jsonValueAsBytes(testStruct, Struct.class)); }