Search in sources :

Example 1 with JavaPropertiesHelper

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);
    }
}
Also used : JavaPropertiesHelper(org.finra.herd.dao.helper.JavaPropertiesHelper) S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) S3Object(com.amazonaws.services.s3.model.S3Object) MultiObjectDeleteException(com.amazonaws.services.s3.model.MultiObjectDeleteException) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonClientException(com.amazonaws.AmazonClientException) AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with JavaPropertiesHelper

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);
    }
}
Also used : JavaPropertiesHelper(org.finra.herd.dao.helper.JavaPropertiesHelper) S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) S3Object(com.amazonaws.services.s3.model.S3Object) MultiObjectDeleteException(com.amazonaws.services.s3.model.MultiObjectDeleteException) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonClientException(com.amazonaws.AmazonClientException) AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

AmazonClientException (com.amazonaws.AmazonClientException)2 AmazonServiceException (com.amazonaws.AmazonServiceException)2 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)2 MultiObjectDeleteException (com.amazonaws.services.s3.model.MultiObjectDeleteException)2 S3Object (com.amazonaws.services.s3.model.S3Object)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 JavaPropertiesHelper (org.finra.herd.dao.helper.JavaPropertiesHelper)2 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)2 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)2 Test (org.junit.Test)2