ZMSFileChangeLogStore implements ChangeLogStore { @Override public SignedDomain getServerSignedDomain(String domainName) { try (ZMSClient zmsClient = getZMSClient()) { return changeLogStoreCommon.getServerSignedDomain(zmsClient, domainName); } catch (ZMSClientException ex) { LOGGER.error("Error when fetching {} data from ZMS: {}", domainName, ex.getMessage()); return null; } } ZMSFileChangeLogStore(String rootDirectory, PrivateKey privateKey, String privateKeyId); @Override boolean supportsFullRefresh(); @Override SignedDomain getLocalSignedDomain(String domainName); @Override SignedDomain getServerSignedDomain(String domainName); @Override void removeLocalDomain(String domainName); @Override void saveLocalDomain(String domainName, SignedDomain signedDomain); @Override List<String> getLocalDomainList(); ZMSClient getZMSClient(); @Override Set<String> getServerDomainList(); @Override SignedDomains getServerDomainModifiedList(); @Override void setLastModificationTimestamp(String newLastModTime); @Override SignedDomains getUpdatedSignedDomains(StringBuilder lastModTimeBuffer); void setChangeLogStoreCommon(ZMSFileChangeLogStoreCommon changeLogStoreCommon);  }
@Test public void testGetServerSignedDomain() { MockZMSFileChangeLogStore fstore = new MockZMSFileChangeLogStore(FSTORE_PATH, null, null); ZMSClient zmsClient = Mockito.mock(ZMSClient.class); fstore.setZMSClient(zmsClient); List<SignedDomain> domains = new ArrayList<>(); DomainData domData = new DomainData().setName("athenz"); SignedDomain domain = new SignedDomain().setDomain(domData); domains.add(domain); SignedDomains domainList = new SignedDomains().setDomains(domains); Mockito.when(zmsClient.getSignedDomains("athenz", null, null, null)).thenReturn(domainList); SignedDomain signedDomain = fstore.getServerSignedDomain("athenz"); assertNotNull(signedDomain); assertEquals(signedDomain.getDomain().getName(), "athenz"); assertNull(fstore.getServerSignedDomain("coretech")); }
@Test public void testGetServerSignedDomainInvalidMultiple() { MockZMSFileChangeLogStore fstore = new MockZMSFileChangeLogStore(FSTORE_PATH, null, null); ZMSClient zmsClient = Mockito.mock(ZMSClient.class); fstore.setZMSClient(zmsClient); List<SignedDomain> domains = new ArrayList<>(); DomainData domData1 = new DomainData().setName("athenz"); SignedDomain domain1 = new SignedDomain().setDomain(domData1); DomainData domData2 = new DomainData().setName("coretech"); SignedDomain domain2 = new SignedDomain().setDomain(domData2); domains.add(domain1); domains.add(domain2); SignedDomains domainList = new SignedDomains().setDomains(domains); Mockito.when(zmsClient.getSignedDomains("athenz", null, null, null)).thenReturn(domainList); assertNull(fstore.getServerSignedDomain("athenz")); }
@Test public void testGetServerSignedDomainException() { MockZMSFileChangeLogStore fstore = new MockZMSFileChangeLogStore(FSTORE_PATH, null, null); ZMSClient zmsClient = Mockito.mock(ZMSClient.class); fstore.setZMSClient(zmsClient); Mockito.when(zmsClient.getSignedDomains("athenz", null, null, null)) .thenThrow(new ZMSClientException(500, "invalid server error:")); assertNull(fstore.getServerSignedDomain("athenz")); }