S3ChangeLogStore implements ChangeLogStore { SignedDomain getSignedDomain(AmazonS3 s3, String domainName) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("getSignedDomain with S3: {}", domainName); } SignedDomain signedDomain = null; try { S3Object object = s3.getObject(s3BucketName, domainName); try (S3ObjectInputStream s3is = object.getObjectContent()) { signedDomain = jsonMapper.readValue(s3is, SignedDomain.class); } } catch (Exception ex) { LOGGER.error("AWSS3ChangeLog: getSignedDomain - unable to get domain {} error: {}", domainName, ex.getMessage()); } return signedDomain; } S3ChangeLogStore();  S3ChangeLogStore(String awsRegion); @Override boolean supportsFullRefresh(); @Override SignedDomain getLocalSignedDomain(String domainName); @SuppressWarnings("EmptyMethod") @Override void removeLocalDomain(String domainName); @SuppressWarnings("EmptyMethod") @Override void saveLocalDomain(String domainName, SignedDomain signedDomain); @Override List<String> getLocalDomainList(); boolean getAllSignedDomains(List<String> domains); @Override Set<String> getServerDomainList(); @Override SignedDomains getServerDomainModifiedList(); @Override SignedDomain getServerSignedDomain(String domainName); @Override SignedDomains getUpdatedSignedDomains(StringBuilder lastModTimeBuffer); @Override void setLastModificationTimestamp(String newLastModTime); ExecutorService getExecutorService();  }
@Test public void testGetSignedDomainNotFound() { MockS3ChangeLogStore store = new MockS3ChangeLogStore(); when(store.awsS3Client.getObject(any(GetObjectRequest.class))).thenReturn(null); assertNull(store.getSignedDomain(store.awsS3Client, "iaas")); }
@Test public void testGetSignedDomainClientException() { MockS3ChangeLogStore store = new MockS3ChangeLogStore(); when(store.awsS3Client.getObject(any(GetObjectRequest.class))).thenThrow(new AmazonClientException("failed client operation")); assertNull(store.getSignedDomain(store.awsS3Client, "iaas")); }
@Test public void testGetSignedDomainServiceException() { MockS3ChangeLogStore store = new MockS3ChangeLogStore(); when(store.awsS3Client.getObject(any(GetObjectRequest.class))).thenThrow(new AmazonServiceException("failed server operation")); assertNull(store.getSignedDomain(store.awsS3Client, "iaas")); }
@Test public void testGetSignedDomainInternal() throws IOException { MockS3ChangeLogStore store = new MockS3ChangeLogStore(); InputStream is = new FileInputStream("src/test/resources/iaas.json"); MockS3ObjectInputStream s3Is = new MockS3ObjectInputStream(is, null); S3Object object = mock(S3Object.class); when(object.getObjectContent()).thenReturn(s3Is); when(store.awsS3Client.getObject("s3-unit-test-bucket-name", "iaas")).thenReturn(object); SignedDomain signedDomain = store.getSignedDomain(store.awsS3Client, "iaas"); assertNotNull(signedDomain); DomainData domainData = signedDomain.getDomain(); assertNotNull(domainData); assertEquals(domainData.getName(), "iaas"); is.close(); }
@Test public void testGetSignedDomain() throws IOException { MockS3ChangeLogStore store = new MockS3ChangeLogStore(); InputStream is1 = new FileInputStream("src/test/resources/iaas.json"); MockS3ObjectInputStream s3Is1 = new MockS3ObjectInputStream(is1, null); InputStream is2 = new FileInputStream("src/test/resources/iaas.json"); MockS3ObjectInputStream s3Is2 = new MockS3ObjectInputStream(is2, null); S3Object object = mock(S3Object.class); when(object.getObjectContent()).thenReturn(s3Is1).thenReturn(s3Is2); store.resetAWSS3Client(); SignedDomain signedDomain = store.getLocalSignedDomain("iaas"); assertNull(signedDomain); when(store.awsS3Client.getObject("s3-unit-test-bucket-name", "iaas")).thenReturn(object); signedDomain = store.getLocalSignedDomain("iaas"); assertNotNull(signedDomain); DomainData domainData = signedDomain.getDomain(); assertNotNull(domainData); assertEquals(domainData.getName(), "iaas"); signedDomain = store.getLocalSignedDomain("iaas"); assertNotNull(signedDomain); is1.close(); is2.close(); }