use of com.yahoo.athenz.zms.JWSDomain in project athenz by yahoo.
the class S3ChangeLogStoreTest method testGetJWSDomainException.
@Test
public void testGetJWSDomainException() throws IOException {
MockS3ChangeLogStore store = new MockS3ChangeLogStore();
InputStream is = new FileInputStream("src/test/resources/iaas.jws");
MockS3ObjectInputStream s3Is = new MockS3ObjectInputStream(is, null);
S3Object object = mock(S3Object.class);
when(object.getObjectContent()).thenReturn(s3Is);
// first call we return null, second call we return success
when(store.awsS3Client.getObject("s3-unit-test-bucket-name", "iaas")).thenThrow(new AmazonServiceException("test")).thenReturn(object);
JWSDomain jwsDomain = store.getLocalJWSDomain("iaas");
assertNotNull(jwsDomain);
is.close();
}
use of com.yahoo.athenz.zms.JWSDomain in project athenz by yahoo.
the class S3ChangeLogStoreTest method testGetLocalJWSDomainList.
@Test
public void testGetLocalJWSDomainList() throws IOException {
MockS3ChangeLogStore store = new MockS3ChangeLogStore(0);
store.setJWSDomainSupport(true);
InputStream is1 = new FileInputStream("src/test/resources/iaas.jws");
MockS3ObjectInputStream s3Is1 = new MockS3ObjectInputStream(is1, null);
InputStream is2 = new FileInputStream("src/test/resources/iaas.jws");
MockS3ObjectInputStream s3Is2 = new MockS3ObjectInputStream(is2, null);
S3Object object = mock(S3Object.class);
when(object.getObjectContent()).thenReturn(s3Is1).thenReturn(s3Is2);
when(store.awsS3Client.getObject("s3-unit-test-bucket-name", "iaas")).thenReturn(object);
ObjectListing mockObjectListing = mock(ObjectListing.class);
when(store.awsS3Client.listObjects(any(ListObjectsRequest.class))).thenReturn(mockObjectListing);
List<S3ObjectSummary> tempList = new ArrayList<>();
S3ObjectSummary s3ObjectSummary = mock(S3ObjectSummary.class);
when(s3ObjectSummary.getKey()).thenReturn("iaas");
tempList.add(s3ObjectSummary);
when(mockObjectListing.getObjectSummaries()).thenReturn(tempList);
List<String> temp = store.getLocalDomainList();
assertNotNull(temp);
JWSDomain jwsDomain = store.getLocalJWSDomain("iaas");
assertNotNull(jwsDomain);
is1.close();
is2.close();
}
use of com.yahoo.athenz.zms.JWSDomain in project athenz by yahoo.
the class S3ChangeLogStoreTest method testGetLocalJWSDomain.
@Test
public void testGetLocalJWSDomain() throws IOException {
MockS3ChangeLogStore store = new MockS3ChangeLogStore();
InputStream is1 = new FileInputStream("src/test/resources/iaas.jws");
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);
// first we'll return null from our s3 client
store.resetAWSS3Client();
JWSDomain jwsDomain = store.getLocalJWSDomain("iaas");
assertNull(jwsDomain);
// next setup our mock aws return object
when(store.awsS3Client.getObject("s3-unit-test-bucket-name", "iaas")).thenReturn(object);
jwsDomain = store.getLocalJWSDomain("iaas");
assertNotNull(jwsDomain);
jwsDomain = store.getLocalJWSDomain("iaas");
assertNotNull(jwsDomain);
is1.close();
is2.close();
}
use of com.yahoo.athenz.zms.JWSDomain in project athenz by yahoo.
the class S3ChangeLogStore method getLocalJWSDomain.
@Override
public JWSDomain getLocalJWSDomain(String domainName) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("getLocalJWSDomain: {}", domainName);
}
// clear the mapping if present and value is stored else null is returned
JWSDomain jwsDomain = tempJWSDomainMap.remove(domainName);
if (jwsDomain == null) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("getLocalJWSDomain: not present in cache, fetching from S3...");
}
if (awsS3Client == null) {
awsS3Client = getS3Client();
}
jwsDomain = getJWSDomain(awsS3Client, domainName);
if (jwsDomain == null) {
awsS3Client = getS3Client();
jwsDomain = getJWSDomain(awsS3Client, domainName);
}
}
return jwsDomain;
}
Aggregations