use of org.finra.herd.dao.helper.JavaPropertiesHelper in project herd by FINRAOS.
the class S3DaoTest method testGetPropertiesHandleGenericException.
@Test
public void testGetPropertiesHandleGenericException() throws Exception {
S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations");
S3Operations mockS3Operations = mock(S3Operations.class);
ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations);
JavaPropertiesHelper originalJavaPropertiesHelper = (JavaPropertiesHelper) ReflectionTestUtils.getField(s3Dao, "javaPropertiesHelper");
JavaPropertiesHelper mockJavaPropertiesHelper = mock(JavaPropertiesHelper.class);
ReflectionTestUtils.setField(s3Dao, "javaPropertiesHelper", mockJavaPropertiesHelper);
try {
String bucketName = "bucketName";
String key = "key";
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
S3Object s3Object = new S3Object();
s3Object.setObjectContent(new ByteArrayInputStream(new byte[] { 0 }));
when(mockS3Operations.getS3Object(any(), any())).thenReturn(s3Object);
when(mockJavaPropertiesHelper.getProperties(any(InputStream.class))).thenThrow(new RuntimeException("message"));
try {
s3Dao.getProperties(bucketName, key, s3FileTransferRequestParamsDto);
fail();
} catch (Exception e) {
assertEquals(RuntimeException.class, e.getClass());
assertEquals("message", e.getMessage());
}
} finally {
ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations);
ReflectionTestUtils.setField(s3Dao, "javaPropertiesHelper", originalJavaPropertiesHelper);
}
}
use of org.finra.herd.dao.helper.JavaPropertiesHelper in project herd by FINRAOS.
the class S3DaoTest method testGetPropertiesHandleIllegalArgumentException.
@Test
public void testGetPropertiesHandleIllegalArgumentException() throws Exception {
S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations");
S3Operations mockS3Operations = mock(S3Operations.class);
ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations);
JavaPropertiesHelper originalJavaPropertiesHelper = (JavaPropertiesHelper) ReflectionTestUtils.getField(s3Dao, "javaPropertiesHelper");
JavaPropertiesHelper mockJavaPropertiesHelper = mock(JavaPropertiesHelper.class);
ReflectionTestUtils.setField(s3Dao, "javaPropertiesHelper", mockJavaPropertiesHelper);
try {
String bucketName = "bucketName";
String key = "key";
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
S3Object s3Object = new S3Object();
s3Object.setObjectContent(new ByteArrayInputStream(new byte[] { 0 }));
when(mockS3Operations.getS3Object(any(), any())).thenReturn(s3Object);
when(mockJavaPropertiesHelper.getProperties(any(InputStream.class))).thenThrow(new IllegalArgumentException("message"));
try {
s3Dao.getProperties(bucketName, key, s3FileTransferRequestParamsDto);
fail();
} catch (Exception e) {
assertEquals(IllegalArgumentException.class, e.getClass());
assertEquals("The properties file in S3 bucket 'bucketName' and key 'key' is invalid.", e.getMessage());
}
} finally {
ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations);
ReflectionTestUtils.setField(s3Dao, "javaPropertiesHelper", originalJavaPropertiesHelper);
}
}
Aggregations