use of org.finra.herd.model.api.xml.JobAction in project herd by FINRAOS.
the class BusinessObjectDataNotificationRegistrationRestControllerTest method testGetBusinessObjectDataNotificationRegistration.
@Test
public void testGetBusinessObjectDataNotificationRegistration() {
// Create a notification registration key.
NotificationRegistrationKey businessObjectDataNotificationRegistrationKey = new NotificationRegistrationKey(NAMESPACE, NOTIFICATION_NAME);
// Create a business object data notification filter.
BusinessObjectDataNotificationFilter businessObjectDataNotificationFilter = new BusinessObjectDataNotificationFilter(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, STORAGE_NAME, BDATA_STATUS, BDATA_STATUS_2);
// Create a list of job actions.
List<JobAction> jobActions = Arrays.asList(new JobAction(JOB_NAMESPACE, JOB_NAME, CORRELATION_DATA));
// Create a business object data notification registration.
BusinessObjectDataNotificationRegistration businessObjectDataNotificationRegistration = new BusinessObjectDataNotificationRegistration(ID, businessObjectDataNotificationRegistrationKey, NOTIFICATION_EVENT_TYPE, businessObjectDataNotificationFilter, jobActions, NOTIFICATION_REGISTRATION_STATUS);
// Mock the external calls.
when(businessObjectDataNotificationRegistrationService.getBusinessObjectDataNotificationRegistration(businessObjectDataNotificationRegistrationKey)).thenReturn(businessObjectDataNotificationRegistration);
// Call the method under test.
BusinessObjectDataNotificationRegistration result = businessObjectDataNotificationRegistrationRestController.getBusinessObjectDataNotificationRegistration(NAMESPACE, NOTIFICATION_NAME);
// Verify the external calls.
verify(businessObjectDataNotificationRegistrationService).getBusinessObjectDataNotificationRegistration(businessObjectDataNotificationRegistrationKey);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(businessObjectDataNotificationRegistration, result);
}
use of org.finra.herd.model.api.xml.JobAction in project herd by FINRAOS.
the class NotificationEventServiceTest method testProcessBusinessObjectDataRegistrationNotificationEventSyncAssertFireEnabledOnly.
@Test
public void testProcessBusinessObjectDataRegistrationNotificationEventSyncAssertFireEnabledOnly() throws Exception {
// Create job definition
JobDefinition jobDefinition = jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_LOG_VARIABLES_NO_REGEX_WITH_CLASSPATH);
List<JobAction> jobActions1 = Arrays.asList(new JobAction(jobDefinition.getNamespace(), jobDefinition.getJobName(), CORRELATION_DATA));
List<JobAction> jobActions2 = Arrays.asList(new JobAction(jobDefinition.getNamespace(), jobDefinition.getJobName(), CORRELATION_DATA_2));
// Create a business object format with a schema.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, FORMAT_DESCRIPTION, LATEST_VERSION_FLAG_SET, FIRST_PARTITION_COLUMN_NAME, NO_PARTITION_KEY_GROUP, NO_ATTRIBUTES, SCHEMA_DELIMITER_PIPE, SCHEMA_ESCAPE_CHARACTER_BACKSLASH, SCHEMA_NULL_VALUE_BACKSLASH_N, schemaColumnDaoTestHelper.getTestSchemaColumns(), schemaColumnDaoTestHelper.getTestPartitionColumns());
// Create business object data with storage units.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(businessObjectFormatEntity, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, true, BDATA_STATUS);
StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(STORAGE_NAME, StoragePlatformEntity.S3);
storageUnitDaoTestHelper.createStorageUnitEntity(storageEntity, businessObjectDataEntity, StorageUnitStatusEntity.ENABLED, NO_STORAGE_DIRECTORY_PATH);
// Create and persist a business object data notification registration entity that is enabled.
notificationRegistrationDaoTestHelper.createBusinessObjectDataNotificationRegistrationEntity(new NotificationRegistrationKey(NAMESPACE, NOTIFICATION_NAME), NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_RGSTN.name(), BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, STORAGE_NAME, BDATA_STATUS, null, jobActions1, NotificationRegistrationStatusEntity.ENABLED);
// Create and persist a business object data notification registration entity that is disabled.
notificationRegistrationDaoTestHelper.createBusinessObjectDataNotificationRegistrationEntity(new NotificationRegistrationKey(NAMESPACE, NOTIFICATION_NAME_2), NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_RGSTN.name(), BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, STORAGE_NAME_2, BDATA_STATUS, null, jobActions2, NotificationRegistrationStatusEntity.DISABLED);
// Trigger the notification
List<Object> notificationActions = notificationEventService.processBusinessObjectDataNotificationEventSync(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_RGSTN, new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION), BDATA_STATUS, null);
assertEquals(1, notificationActions.size());
assertEquals(Job.class, notificationActions.get(0).getClass());
Job job = (Job) notificationActions.get(0);
List<Parameter> parameters = job.getParameters();
boolean found = false;
for (Parameter parameter : parameters) {
String name = parameter.getName();
if ("notification_correlationData".equals(name)) {
assertEquals(CORRELATION_DATA, parameter.getValue());
found = true;
break;
}
}
assertTrue(found);
}
use of org.finra.herd.model.api.xml.JobAction in project herd by FINRAOS.
the class NotificationEventServiceTest method runProcessStorageUnitStatusChangeNotificationEventSyncTest.
private void runProcessStorageUnitStatusChangeNotificationEventSyncTest() throws Exception {
// Create a job definition.
JobDefinition jobDefinition = jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_LOG_VARIABLES_NO_REGEX_WITH_CLASSPATH);
// Create a job action.
List<JobAction> jobActions = new ArrayList<>();
jobActions.add(new JobAction(jobDefinition.getNamespace(), jobDefinition.getJobName(), CORRELATION_DATA));
// Create a business object format with a schema.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, FORMAT_DESCRIPTION, LATEST_VERSION_FLAG_SET, FIRST_PARTITION_COLUMN_NAME, NO_PARTITION_KEY_GROUP, NO_ATTRIBUTES, SCHEMA_DELIMITER_PIPE, SCHEMA_ESCAPE_CHARACTER_BACKSLASH, SCHEMA_NULL_VALUE_BACKSLASH_N, schemaColumnDaoTestHelper.getTestSchemaColumns(), schemaColumnDaoTestHelper.getTestPartitionColumns());
// Create a business object data with a storage unit having a DISABLED status.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(businessObjectFormatEntity, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.VALID);
StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(STORAGE_NAME, StoragePlatformEntity.S3);
storageUnitDaoTestHelper.createStorageUnitEntity(storageEntity, businessObjectDataEntity, StorageUnitStatusEntity.DISABLED, NO_STORAGE_DIRECTORY_PATH);
// Create and persist a storage unit notification registration entity.
notificationRegistrationDaoTestHelper.createStorageUnitNotificationRegistrationEntity(new NotificationRegistrationKey(NAMESPACE, NOTIFICATION_NAME), NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG.name(), BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, STORAGE_NAME, StorageUnitStatusEntity.ENABLED, StorageUnitStatusEntity.DISABLED, jobActions, NotificationRegistrationStatusEntity.ENABLED);
// Trigger the notification.
List<Object> notificationActions = notificationEventService.processStorageUnitNotificationEventSync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION), STORAGE_NAME, StorageUnitStatusEntity.ENABLED, StorageUnitStatusEntity.DISABLED);
// Validate the result job.
Job job = (Job) notificationActions.get(0);
assertEquals(new Job(job.getId(), null, TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, null, null, null, null, Arrays.asList(new Parameter("notification_businessObjectDefinitionName", BDEF_NAME), new Parameter("notification_partitionValues", PARTITION_VALUE + "|" + StringUtils.join(SUBPARTITION_VALUES, "|")), new Parameter("notification_namespace", NAMESPACE), new Parameter("notification_businessObjectData", jsonHelper.objectToJson(businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataEntity))), new Parameter("notification_businessObjectFormatUsage", FORMAT_USAGE_CODE), new Parameter(HERD_WORKFLOW_ENVIRONMENT, configurationHelper.getProperty(ConfigurationValue.HERD_ENVIRONMENT)), new Parameter("notification_businessObjectDefinitionNamespace", BDEF_NAMESPACE), new Parameter(ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_VALUE_1), new Parameter("notification_storageUnitEventType", NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG.name()), new Parameter("notification_oldStorageUnitStatus", StorageUnitStatusEntity.DISABLED), new Parameter("notification_businessObjectDataVersion", DATA_VERSION.toString()), new Parameter("notification_name", NOTIFICATION_NAME), new Parameter("notification_partitionColumnNames", "PRTN_CLMN001|PRTN_CLMN002|PRTN_CLMN003|PRTN_CLMN004|PRTN_CLMN005"), new Parameter("notification_businessObjectFormatVersion", FORMAT_VERSION.toString()), new Parameter("notification_businessObjectFormatFileType", FORMAT_FILE_TYPE_CODE), new Parameter("notification_storageName", STORAGE_NAME), new Parameter("notification_newStorageUnitStatus", StorageUnitStatusEntity.ENABLED), new Parameter("notification_correlationData", CORRELATION_DATA)), null, null, null), job);
}
use of org.finra.herd.model.api.xml.JobAction in project herd by FINRAOS.
the class NotificationRegistrationServiceTestHelper method createDatabaseEntitiesForBusinessObjectDataNotificationRegistrationTesting.
/**
* Create and persist database entities required for testing.
*
* @param namespace the namespace of the business object data notification registration
* @param notificationEventTypes the list of notification event types
* @param businessObjectDefinitionNamespace the namespace of the business object definition
* @param businessObjectDefinitionName the name of the business object definition
* @param fileTypes the list of file types
* @param storageNames the list of storage names
* @param businessObjectDataStatuses the list of business object data statuses
* @param jobActions the list of job actions
*/
public void createDatabaseEntitiesForBusinessObjectDataNotificationRegistrationTesting(String namespace, List<String> notificationEventTypes, String businessObjectDefinitionNamespace, String businessObjectDefinitionName, List<String> fileTypes, List<String> storageNames, List<String> businessObjectDataStatuses, List<JobAction> jobActions) {
// Create a namespace entity, if not exists.
NamespaceEntity namespaceEntity = namespaceDao.getNamespaceByCd(namespace);
if (namespaceEntity == null) {
namespaceDaoTestHelper.createNamespaceEntity(namespace);
}
// Create specified notification event types, if not exist.
if (!CollectionUtils.isEmpty(notificationEventTypes)) {
for (String notificationEventType : notificationEventTypes) {
NotificationEventTypeEntity notificationEventTypeEntity = notificationEventTypeDao.getNotificationEventTypeByCode(notificationEventType);
if (notificationEventTypeEntity == null) {
notificationRegistrationDaoTestHelper.createNotificationEventTypeEntity(notificationEventType);
}
}
}
// Create specified business object definition, if not exists.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDao.getBusinessObjectDefinitionByKey(new BusinessObjectDefinitionKey(businessObjectDefinitionNamespace, businessObjectDefinitionName));
if (businessObjectDefinitionEntity == null) {
// Create and persist a business object definition entity.
businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(businessObjectDefinitionNamespace, businessObjectDefinitionName, AbstractServiceTest.DATA_PROVIDER_NAME, AbstractServiceTest.BDEF_DESCRIPTION);
}
// Create specified file type entities, if not exist.
if (!CollectionUtils.isEmpty(fileTypes)) {
for (String businessObjectFormatFileType : fileTypes) {
fileTypeDaoTestHelper.createFileTypeEntity(businessObjectFormatFileType);
}
}
// Create specified storage entities, if not exist.
if (!CollectionUtils.isEmpty(storageNames)) {
for (String storageName : storageNames) {
storageDaoTestHelper.createStorageEntity(storageName, StoragePlatformEntity.S3);
}
}
// Create specified business object data status entities, if not exist.
if (!CollectionUtils.isEmpty(businessObjectDataStatuses)) {
for (String businessObjectDataStatus : businessObjectDataStatuses) {
BusinessObjectDataStatusEntity businessObjectDataStatusEntity = businessObjectDataStatusDao.getBusinessObjectDataStatusByCode(businessObjectDataStatus);
if (businessObjectDataStatusEntity == null) {
businessObjectDataStatusDaoTestHelper.createBusinessObjectDataStatusEntity(businessObjectDataStatus);
}
}
}
// Create specified job definition entities.
if (!CollectionUtils.isEmpty(jobActions)) {
for (JobAction jobAction : jobActions) {
jobDefinitionDaoTestHelper.createJobDefinitionEntity(jobAction.getNamespace(), jobAction.getJobName(), String.format("Description of \"%s.%s\" job definition.", jobAction.getNamespace(), jobAction.getJobName()), String.format("%s.%s.%s", jobAction.getNamespace(), jobAction.getJobName(), AbstractServiceTest.ACTIVITI_ID));
}
}
}
use of org.finra.herd.model.api.xml.JobAction in project herd by FINRAOS.
the class NamespaceSecurityAdviceTest method checkPermissionAssertAccessDeniedWhenComplexCaseAndUserHasWrongPermission.
@Test
public void checkPermissionAssertAccessDeniedWhenComplexCaseAndUserHasWrongPermission() throws Exception {
// Mock a join point of the method call
// mockMethod(request);
JoinPoint joinPoint = mock(JoinPoint.class);
MethodSignature methodSignature = mock(MethodSignature.class);
Method method = NamespaceSecurityAdviceTest.class.getDeclaredMethod("mockMethod", BusinessObjectDataNotificationRegistrationCreateRequest.class);
when(methodSignature.getParameterNames()).thenReturn(new String[] { "request" });
when(methodSignature.getMethod()).thenReturn(method);
when(joinPoint.getSignature()).thenReturn(methodSignature);
BusinessObjectDataNotificationRegistrationCreateRequest request = new BusinessObjectDataNotificationRegistrationCreateRequest();
request.setBusinessObjectDataNotificationRegistrationKey(new NotificationRegistrationKey("ns1", null));
request.setBusinessObjectDataNotificationFilter(new BusinessObjectDataNotificationFilter("ns2", null, null, null, null, null, null, null));
request.setJobActions(Arrays.asList(new JobAction("ns3", null, null), new JobAction("ns4", null, null)));
when(joinPoint.getArgs()).thenReturn(new Object[] { request });
String userId = "userId";
ApplicationUser applicationUser = new ApplicationUser(getClass());
applicationUser.setUserId(userId);
applicationUser.setNamespaceAuthorizations(new HashSet<>());
applicationUser.getNamespaceAuthorizations().add(new NamespaceAuthorization("ns1", Arrays.asList(NamespacePermissionEnum.WRITE)));
applicationUser.getNamespaceAuthorizations().add(new NamespaceAuthorization("ns2", Arrays.asList(NamespacePermissionEnum.READ)));
applicationUser.getNamespaceAuthorizations().add(new NamespaceAuthorization("ns3", Arrays.asList(NamespacePermissionEnum.EXECUTE)));
// User does not have the expected EXECUTE permission on ns4
applicationUser.getNamespaceAuthorizations().add(new NamespaceAuthorization("ns4", Arrays.asList(NamespacePermissionEnum.READ)));
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(new SecurityUserWrapper(userId, "", false, false, false, false, Arrays.asList(), applicationUser), null));
try {
namespaceSecurityAdvice.checkPermission(joinPoint);
fail();
} catch (Exception e) {
assertEquals(AccessDeniedException.class, e.getClass());
assertEquals(String.format("User \"%s\" does not have \"[EXECUTE]\" permission(s) to the namespace \"ns4\"", userId), e.getMessage());
}
}
Aggregations