Search in sources :

Example 1 with Command

use of org.finra.herd.core.Command in project herd by FINRAOS.

the class DownloaderWebClientTest method testGetS3KeyPrefix.

@Test
public void testGetS3KeyPrefix() throws Exception {
    // Upload and register business object data parents.
    uploadAndRegisterTestDataParents(downloaderWebClient);
    // Upload and register the initial version if of the test business object data.
    uploadTestDataFilesToS3(S3_TEST_PATH_V0);
    final UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto();
    executeWithoutLogging(DataBridgeWebClient.class, new Command() {

        @Override
        public void execute() throws Exception {
            BusinessObjectData businessObjectData = downloaderWebClient.preRegisterBusinessObjectData(uploaderInputManifestDto, StorageEntity.MANAGED_STORAGE, false);
            BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper.getBusinessObjectDataKey(businessObjectData);
            downloaderWebClient.addStorageFiles(businessObjectDataKey, uploaderInputManifestDto, getTestS3FileTransferRequestParamsDto(S3_TEST_PATH_V0 + "/"), StorageEntity.MANAGED_STORAGE);
            downloaderWebClient.updateBusinessObjectDataStatus(businessObjectDataKey, BusinessObjectDataStatusEntity.VALID);
        }
    });
    // Get S3 key prefix.
    BusinessObjectData businessObjectData = toBusinessObjectData(uploaderInputManifestDto);
    S3KeyPrefixInformation resultS3KeyPrefixInformation = downloaderWebClient.getS3KeyPrefix(businessObjectData);
    // Validate the results.
    assertNotNull(resultS3KeyPrefixInformation);
    assertEquals(S3_SIMPLE_TEST_PATH, resultS3KeyPrefixInformation.getS3KeyPrefix());
}
Also used : UploaderInputManifestDto(org.finra.herd.model.dto.UploaderInputManifestDto) Command(org.finra.herd.core.Command) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) S3KeyPrefixInformation(org.finra.herd.model.api.xml.S3KeyPrefixInformation) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with Command

use of org.finra.herd.core.Command in project herd by FINRAOS.

the class BusinessObjectFormatServiceTest method testCreateBusinessObjectFormatIncorrectLatestVersion.

@Test
public void testCreateBusinessObjectFormatIncorrectLatestVersion() throws Exception {
    // Create relative database entities.
    businessObjectFormatServiceTestHelper.createTestDatabaseEntitiesForBusinessObjectFormatTesting();
    // Create a first version of the format with the latest flag set to false.
    businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, FORMAT_DESCRIPTION, false, PARTITION_KEY);
    try {
        // Try to create a new format version for this format.
        final BusinessObjectFormatCreateRequest businessObjectFormatCreateRequest = businessObjectFormatServiceTestHelper.createBusinessObjectFormatCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, PARTITION_KEY, FORMAT_DESCRIPTION, businessObjectDefinitionServiceTestHelper.getNewAttributes(), businessObjectFormatServiceTestHelper.getTestAttributeDefinitions(), businessObjectFormatServiceTestHelper.getTestSchema());
        executeWithoutLogging(SqlExceptionHelper.class, new Command() {

            @Override
            public void execute() {
                businessObjectFormatService.createBusinessObjectFormat(businessObjectFormatCreateRequest);
                fail("Should throw a PersistenceException since the latest flag does not identify the maximum format version.");
            }
        });
    } catch (PersistenceException e) {
        assertTrue(e.getMessage().contains("ConstraintViolationException: could not execute statement"));
    }
}
Also used : BusinessObjectFormatCreateRequest(org.finra.herd.model.api.xml.BusinessObjectFormatCreateRequest) Command(org.finra.herd.core.Command) PersistenceException(javax.persistence.PersistenceException) Test(org.junit.Test)

Example 3 with Command

use of org.finra.herd.core.Command in project herd by FINRAOS.

the class HerdThreadHelperTest method testSleep.

/*
     * This test is to get the clover coverage for sleep() method on HerdHelper
     */
@Test
public void testSleep() throws Exception {
    // Sleep for 1 second
    herdThreadHelper.sleep(1 * 1000L);
    // Passing null should result in Exception that is eaten and logged
    executeWithoutLogging(HerdThreadHelper.class, new Command() {

        @Override
        public void execute() throws Exception {
            (new HerdThreadHelper()).sleep(null);
        }
    });
}
Also used : Command(org.finra.herd.core.Command) AbstractCoreTest(org.finra.herd.core.AbstractCoreTest) Test(org.junit.Test)

Example 4 with Command

use of org.finra.herd.core.Command in project herd by FINRAOS.

the class StopWatchAdviceTest method testLogMethodTimeTargetMethodIsInterface.

@Test
public void testLogMethodTimeTargetMethodIsInterface() throws Throwable {
    // Mock a join point of the method call.
    ProceedingJoinPoint joinPoint = getMockedProceedingJoinPoint(new Command() {

        @Override
        public void execute() throws Exception {
            return;
        }
    }, Command.class.getDeclaredMethod("execute"));
    // Call the method under test.
    stopWatchAdvice.logMethodTime(joinPoint);
}
Also used : Command(org.finra.herd.core.Command) MockProceedingJoinPoint(org.finra.herd.core.MockProceedingJoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 5 with Command

use of org.finra.herd.core.Command in project herd by FINRAOS.

the class StorageServiceTest method testDeleteStorageConstraintViolation.

/*
     * This test is ignored because the constraint validation is a DB dependent feature. This method had inconsistent behavior between Oracle and PostgreSQL.
     * Oracle was throwing the error after each statement, whereas PostgreSQL would not because it by default raises error only when transaction is committed.
     *
     * Besides, this test case is not valid as a use case as normal transactions wouldn't delete after insert within same transaction.
     */
@Ignore
@Test(expected = PersistenceException.class)
public void testDeleteStorageConstraintViolation() throws Exception {
    // Create a storage unit entity that refers to a newly created storage.
    final StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BDATA_STATUS, STORAGE_UNIT_STATUS, NO_STORAGE_DIRECTORY_PATH);
    executeWithoutLogging(SqlExceptionHelper.class, new Command() {

        @Override
        public void execute() {
            // Delete the storage which is invalid because there still exists a storage unit entity that references it.
            StorageKey alternateKey = new StorageKey(storageUnitEntity.getStorage().getName());
            storageService.deleteStorage(alternateKey);
        }
    });
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) Command(org.finra.herd.core.Command) StorageKey(org.finra.herd.model.api.xml.StorageKey) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Command (org.finra.herd.core.Command)7 Test (org.junit.Test)7 IOException (java.io.IOException)2 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)2 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)2 UploaderInputManifestDto (org.finra.herd.model.dto.UploaderInputManifestDto)2 PersistenceException (javax.persistence.PersistenceException)1 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)1 AbstractCoreTest (org.finra.herd.core.AbstractCoreTest)1 MockProceedingJoinPoint (org.finra.herd.core.MockProceedingJoinPoint)1 Attribute (org.finra.herd.model.api.xml.Attribute)1 BusinessObjectDataCreateRequest (org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest)1 BusinessObjectFormatCreateRequest (org.finra.herd.model.api.xml.BusinessObjectFormatCreateRequest)1 S3KeyPrefixInformation (org.finra.herd.model.api.xml.S3KeyPrefixInformation)1 StorageKey (org.finra.herd.model.api.xml.StorageKey)1 DownloaderInputManifestDto (org.finra.herd.model.dto.DownloaderInputManifestDto)1 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)1 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)1 Ignore (org.junit.Ignore)1