Example usage for java.lang IllegalStateException getMessage

List of usage examples for java.lang IllegalStateException getMessage

Introduction

In this page you can find the example usage for java.lang IllegalStateException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java

public void test_Registration16() throws Exception {
    Filter initError = new Filter() {

        @Override/*w ww.j a v a 2s  .co  m*/
        public void init(FilterConfig filterConfig) throws ServletException {
            throw new IllegalStateException("Init error.");
        }

        @Override
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
                throws IOException, ServletException {
            // nothing
        }

        @Override
        public void destroy() {
            // nothing
        }
    };
    ExtendedHttpService extendedHttpService = (ExtendedHttpService) getHttpService();
    try {
        extendedHttpService.registerFilter("/foo", initError, null, null);
        fail("Expected an init failure.");
    } catch (IllegalStateException e) {
        //expected
        assertEquals("Wrong exception message.", "Init error.", e.getMessage());
    }
}

From source file:org.finra.herd.dao.S3DaoTest.java

@Test
public void testValidateGlacierS3FilesRestoredAmazonServiceException() {
    // Build a mock file path that triggers an Amazon service exception when we request S3 metadata for the object.
    String testKey = String.format("%s/%s", TEST_S3_KEY_PREFIX,
            MockS3OperationsImpl.MOCK_S3_FILE_NAME_SERVICE_EXCEPTION);

    // Put a 1 byte Glacier storage class file in S3.
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setHeader(Headers.STORAGE_CLASS, StorageClass.Glacier);
    metadata.setOngoingRestore(false);/*from   w w  w .jav  a2 s  .  c om*/
    s3Operations.putObject(new PutObjectRequest(storageDaoTestHelper.getS3ManagedBucketName(), testKey,
            new ByteArrayInputStream(new byte[1]), metadata), null);

    // Try to validate if the Glacier S3 file is already restored for a mocked S3 file
    // that triggers an Amazon service exception when we request S3 metadata for the object.
    try {
        S3FileTransferRequestParamsDto params = new S3FileTransferRequestParamsDto();
        params.setS3BucketName(storageDaoTestHelper.getS3ManagedBucketName());
        params.setFiles(Arrays.asList(new File(testKey)));
        s3Dao.validateGlacierS3FilesRestored(params);
        fail("Should throw an IllegalStateException when Glacier S3 object validation fails due to an Amazon service exception.");
    } catch (IllegalStateException e) {
        assertEquals(String.format("Fail to check restore status for \"%s\" key in \"%s\" bucket. "
                + "Reason: InternalError (Service: null; Status Code: 0; Error Code: InternalError; Request ID: null)",
                testKey, storageDaoTestHelper.getS3ManagedBucketName()), e.getMessage());
    }
}

From source file:org.finra.herd.dao.S3DaoTest.java

@Test
public void testRestoreObjectsAmazonServiceException() {
    // Build a mock file path that triggers an Amazon service exception when we request to restore an object.
    String testKey = String.format("%s/%s", TEST_S3_KEY_PREFIX,
            MockS3OperationsImpl.MOCK_S3_FILE_NAME_SERVICE_EXCEPTION);

    // Put a 1 byte Glacier storage class file in S3.
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setHeader(Headers.STORAGE_CLASS, StorageClass.Glacier);
    metadata.setOngoingRestore(false);/*  www. jav a2  s. co  m*/
    s3Operations.putObject(new PutObjectRequest(storageDaoTestHelper.getS3ManagedBucketName(), testKey,
            new ByteArrayInputStream(new byte[1]), metadata), null);

    // Try to initiate a restore request for a mocked S3 file that would trigger an Amazon service exception when we request to restore an object.
    try {
        S3FileTransferRequestParamsDto params = new S3FileTransferRequestParamsDto();
        params.setS3BucketName(storageDaoTestHelper.getS3ManagedBucketName());
        params.setFiles(Arrays.asList(new File(testKey)));
        s3Dao.restoreObjects(params, S3_RESTORE_OBJECT_EXPIRATION_IN_DAYS, ARCHIVE_RETRIEVAL_OPTION);
        fail("Should throw an IllegalStateException when an S3 restore object operation fails.");
    } catch (IllegalStateException e) {
        assertEquals(String.format("Failed to initiate a restore request for \"%s\" key in \"%s\" bucket. "
                + "Reason: InternalError (Service: null; Status Code: 0; Error Code: InternalError; Request ID: null)",
                testKey, storageDaoTestHelper.getS3ManagedBucketName()), e.getMessage());
    }
}

From source file:org.finra.herd.dao.S3DaoTest.java

@Test
public void testRestoreObjectsNonGlacierObject() {
    // Put a 1 byte non-Glacier storage class file in S3.
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setHeader(Headers.STORAGE_CLASS, StorageClass.Standard);
    metadata.setOngoingRestore(false);/*  w  w  w .j av  a 2 s.c  o m*/
    s3Operations.putObject(new PutObjectRequest(storageDaoTestHelper.getS3ManagedBucketName(), TARGET_S3_KEY,
            new ByteArrayInputStream(new byte[1]), metadata), null);

    // Try to initiate a restore request for a non-Glacier file.
    try {
        S3FileTransferRequestParamsDto params = new S3FileTransferRequestParamsDto();
        params.setS3BucketName(storageDaoTestHelper.getS3ManagedBucketName());
        params.setFiles(Arrays.asList(new File(TARGET_S3_KEY)));
        s3Dao.restoreObjects(params, S3_RESTORE_OBJECT_EXPIRATION_IN_DAYS, ARCHIVE_RETRIEVAL_OPTION);
        fail("Should throw an IllegalStateException when file has a non-Glacier storage class.");
    } catch (IllegalStateException e) {
        assertEquals(String.format("Failed to initiate a restore request for \"%s\" key in \"%s\" bucket. "
                + "Reason: object is not in Glacier (Service: null; Status Code: 0; Error Code: null; Request ID: null)",
                TARGET_S3_KEY, storageDaoTestHelper.getS3ManagedBucketName()), e.getMessage());
    }
}

From source file:org.finra.herd.dao.S3DaoTest.java

/**
 * Test "access denied" scenario for the getObjectMetadata S3Dao operation.
 *///from   w  w  w.  j a  v a  2  s.  co m
@Test
public void testGetObjectMetadataAccessDenied() {
    S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = s3DaoTestHelper
            .getTestS3FileTransferRequestParamsDto();

    // Try to retrieve S3 object metadata when S3 access is denied.
    try {
        s3FileTransferRequestParamsDto.setS3BucketName(MockS3OperationsImpl.MOCK_S3_BUCKET_NAME_ACCESS_DENIED);
        s3FileTransferRequestParamsDto.setS3KeyPrefix(TARGET_S3_KEY);
        s3Dao.getObjectMetadata(s3FileTransferRequestParamsDto);
        fail("Should throw an ObjectNotFoundException when S3 access is denied.");
    } catch (IllegalStateException e) {
        assertEquals(String.format("Failed to get S3 metadata for object key \"%s\" from bucket \"%s\". "
                + "Reason: AccessDenied (Service: null; Status Code: 403; Error Code: AccessDenied; Request ID: null)",
                TARGET_S3_KEY, MockS3OperationsImpl.MOCK_S3_BUCKET_NAME_ACCESS_DENIED), e.getMessage());
    }
}

From source file:org.finra.herd.dao.S3DaoTest.java

/**
 * Get ObjectMetadata with a socket timeout setting.
 *///from   w  w w.  jav  a  2  s .c  om
@Test
public void testGetObjectMetadataWithSocketTimeout() {
    S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = s3DaoTestHelper
            .getTestS3FileTransferRequestParamsDto();
    s3FileTransferRequestParamsDto.setSocketTimeout(10000);

    // Try to retrieve S3 object metadata when S3 access is denied.
    try {
        s3FileTransferRequestParamsDto.setS3BucketName(MockS3OperationsImpl.MOCK_S3_BUCKET_NAME_ACCESS_DENIED);
        s3FileTransferRequestParamsDto.setS3KeyPrefix(TARGET_S3_KEY);
        s3Dao.getObjectMetadata(s3FileTransferRequestParamsDto);
        fail("Should throw an ObjectNotFoundException when S3 access is denied.");
    } catch (IllegalStateException e) {
        assertEquals(String.format("Failed to get S3 metadata for object key \"%s\" from bucket \"%s\". "
                + "Reason: AccessDenied (Service: null; Status Code: 403; Error Code: AccessDenied; Request ID: null)",
                TARGET_S3_KEY, MockS3OperationsImpl.MOCK_S3_BUCKET_NAME_ACCESS_DENIED), e.getMessage());
    }
}

From source file:org.finra.herd.dao.S3DaoTest.java

/**
 * Test S3 file copy with an invalid KMS Id that will result in a cancelled transfer.
 *///w ww  .j  a v  a2  s  .  co  m
@Test
public void testCopyFileInvalidKmsIdCancelled() throws InterruptedException {
    // Put a 1 byte file in S3.
    s3Operations.putObject(new PutObjectRequest(storageDaoTestHelper.getS3LoadingDockBucketName(),
            TARGET_S3_KEY, new ByteArrayInputStream(new byte[1]), null), null);

    try {
        S3FileCopyRequestParamsDto transferDto = new S3FileCopyRequestParamsDto();
        transferDto.setSourceBucketName(storageDaoTestHelper.getS3LoadingDockBucketName());
        transferDto.setTargetBucketName(storageDaoTestHelper.getS3ExternalBucketName());
        transferDto.setSourceObjectKey(TARGET_S3_KEY);
        transferDto.setTargetObjectKey(TARGET_S3_KEY);
        transferDto.setKmsKeyId(MockS3OperationsImpl.MOCK_KMS_ID_CANCELED_TRANSFER);
        s3Dao.copyFile(transferDto);
        fail("An IllegalStateException was expected but not thrown.");
    } catch (IllegalStateException ex) {
        assertEquals("Invalid IllegalStateException message returned.",
                "The transfer operation \"" + MockS3OperationsImpl.MOCK_TRANSFER_DESCRIPTION
                        + "\" did not complete successfully. " + "Current state: \""
                        + Transfer.TransferState.Canceled + "\".",
                ex.getMessage());
    }
}

From source file:org.finra.herd.dao.S3DaoTest.java

/**
 * Test S3 exception handling in the getObjectMetadata S3Dao operation.
 *///from  w w  w .j  a va2s.c o m
@Test
public void testGetObjectMetadataServiceException() {
    S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = s3DaoTestHelper
            .getTestS3FileTransferRequestParamsDto();

    // Validate that S3 service exception is handled correctly when retrieving S3 object metadata.
    try {
        s3FileTransferRequestParamsDto.setS3BucketName(MockS3OperationsImpl.MOCK_S3_BUCKET_NAME_INTERNAL_ERROR);
        s3FileTransferRequestParamsDto.setS3KeyPrefix(TARGET_S3_KEY);
        s3Dao.getObjectMetadata(s3FileTransferRequestParamsDto);
        fail("Should throw an IllegalStateException when Amazon service exception occurs.");
    } catch (IllegalStateException e) {
        assertEquals(String.format("Failed to get S3 metadata for object key \"%s\" from bucket \"%s\". "
                + "Reason: InternalError (Service: null; Status Code: 0; Error Code: InternalError; Request ID: null)",
                s3FileTransferRequestParamsDto.getS3KeyPrefix(),
                s3FileTransferRequestParamsDto.getS3BucketName()), e.getMessage());
    }
}

From source file:org.finra.herd.dao.S3DaoTest.java

@Test
public void testTagObjectsAmazonServiceException() {
    // Create an S3 file transfer request parameters DTO to access S3 objects with a mocked S3 bucket name that would trigger an AWS exception.
    S3FileTransferRequestParamsDto params = new S3FileTransferRequestParamsDto();
    params.setS3BucketName(MockS3OperationsImpl.MOCK_S3_BUCKET_NAME_INTERNAL_ERROR);

    // Create an S3 object summary.
    S3ObjectSummary s3ObjectSummary = new S3ObjectSummary();
    s3ObjectSummary.setKey(TARGET_S3_KEY);

    // Create an S3 object tag.
    Tag tag = new Tag(S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE);

    try {//from  w w w.ja v a2  s.  co  m
        s3Dao.tagObjects(params, new S3FileTransferRequestParamsDto(),
                Collections.singletonList(s3ObjectSummary), tag);
        fail();
    } catch (IllegalStateException e) {
        assertEquals(String.format(
                "Failed to tag S3 object with \"%s\" key and \"null\" version id in \"%s\" bucket. "
                        + "Reason: InternalError (Service: null; Status Code: 0; Error Code: InternalError; Request ID: null)",
                TARGET_S3_KEY, MockS3OperationsImpl.MOCK_S3_BUCKET_NAME_INTERNAL_ERROR), e.getMessage());
    }
}

From source file:io.realm.RealmTests.java

@Test
public void nestedTransaction() {
    realm.beginTransaction();//w w w. j  a  va  2  s  .  co  m
    try {
        realm.beginTransaction();
        fail();
    } catch (IllegalStateException e) {
        assertEquals(
                "Nested transactions are not allowed. Use commitTransaction() after each beginTransaction().",
                e.getMessage());
    }
    realm.commitTransaction();
}