use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceTest method testGetUserNamespaceAuthorizationUpperCaseParameters.
@Test
public void testGetUserNamespaceAuthorizationUpperCaseParameters() {
// Create a user namespace authorization key.
UserNamespaceAuthorizationKey key = new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE);
// Create and persist the relative database entities.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(key.getNamespace());
UserNamespaceAuthorizationEntity userNamespaceAuthorizationEntity = userNamespaceAuthorizationDaoTestHelper.createUserNamespaceAuthorizationEntity(key, SUPPORTED_NAMESPACE_PERMISSIONS);
// Get a user namespace authorization using uppercase input parameters.
UserNamespaceAuthorization resultUserNamespaceAuthorization = userNamespaceAuthorizationService.getUserNamespaceAuthorization(new UserNamespaceAuthorizationKey(key.getUserId().toUpperCase(), key.getNamespace().toUpperCase()));
// Validate the returned object.
assertEquals(new UserNamespaceAuthorization(userNamespaceAuthorizationEntity.getId(), key, SUPPORTED_NAMESPACE_PERMISSIONS), resultUserNamespaceAuthorization);
}
use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceTest method testGetUserNamespaceAuthorizationLowerCaseParameters.
@Test
public void testGetUserNamespaceAuthorizationLowerCaseParameters() {
// Create a user namespace authorization key.
UserNamespaceAuthorizationKey key = new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE);
// Create and persist the relative database entities.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(key.getNamespace());
UserNamespaceAuthorizationEntity userNamespaceAuthorizationEntity = userNamespaceAuthorizationDaoTestHelper.createUserNamespaceAuthorizationEntity(key, SUPPORTED_NAMESPACE_PERMISSIONS);
// Get a user namespace authorization using lowercase input parameters.
UserNamespaceAuthorization resultUserNamespaceAuthorization = userNamespaceAuthorizationService.getUserNamespaceAuthorization(new UserNamespaceAuthorizationKey(key.getUserId().toLowerCase(), key.getNamespace().toLowerCase()));
// Validate the returned object.
assertEquals(new UserNamespaceAuthorization(userNamespaceAuthorizationEntity.getId(), key, SUPPORTED_NAMESPACE_PERMISSIONS), resultUserNamespaceAuthorization);
}
use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.
the class AddEmrMasterSecurityGroupTest method testAddEmrMasterSecurityGroup.
@Test
public void testAddEmrMasterSecurityGroup() throws Exception {
// Create a pipe-separated list of security group IDs.
final String securityGroupIds = EC2_SECURITY_GROUP_1 + "|" + EC2_SECURITY_GROUP_2;
// Create EC2 on-demand pricing entities required for testing.
ec2OnDemandPricingDaoTestHelper.createEc2OnDemandPricingEntities();
// Create the namespace entity.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
// Create a trusting AWS account.
trustingAccountDaoTestHelper.createTrustingAccountEntity(AWS_ACCOUNT_ID, AWS_ROLE_ARN);
// Create an EMR cluster definition.
emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream()));
// Create an EMR cluster definition override with an AWS account ID.
EmrClusterDefinition emrClusterDefinitionOverride = new EmrClusterDefinition();
emrClusterDefinitionOverride.setAccountId(AWS_ACCOUNT_ID);
// Create an EMR cluster.
emrService.createCluster(new EmrClusterCreateRequest(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME, NO_DRY_RUN, emrClusterDefinitionOverride));
List<FieldExtension> fieldExtensionList = new ArrayList<>();
fieldExtensionList.add(buildFieldExtension("namespace", "${namespace}"));
fieldExtensionList.add(buildFieldExtension("emrClusterDefinitionName", "${emrClusterDefinitionName}"));
fieldExtensionList.add(buildFieldExtension("emrClusterName", "${emrClusterName}"));
fieldExtensionList.add(buildFieldExtension("securityGroupIds", "${securityGroupIds}"));
fieldExtensionList.add(buildFieldExtension("accountId", "${accountId}"));
List<Parameter> parameters = new ArrayList<>();
parameters.add(buildParameter("namespace", NAMESPACE));
parameters.add(buildParameter("emrClusterDefinitionName", EMR_CLUSTER_DEFINITION_NAME));
parameters.add(buildParameter("emrClusterName", EMR_CLUSTER_NAME));
parameters.add(buildParameter("securityGroupIds", securityGroupIds));
parameters.add(buildParameter("accountId", AWS_ACCOUNT_ID));
Map<String, Object> variableValuesToValidate = new HashMap<>();
variableValuesToValidate.put(AddEmrMasterSecurityGroup.VARIABLE_EMR_MASTER_SECURITY_GROUPS, securityGroupIds);
testActivitiServiceTaskSuccess(AddEmrMasterSecurityGroup.class.getCanonicalName(), fieldExtensionList, parameters, variableValuesToValidate);
}
use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.
the class NamespaceIamRoleAuthorizationServiceTest method updateNamespaceIamRoleAuthorizationAssertErrorWhenDaoReturnsEmpty.
@Test
public void updateNamespaceIamRoleAuthorizationAssertErrorWhenDaoReturnsEmpty() {
String expectedNamespace = "namespace";
List<IamRole> iamRoles = new ArrayList<>();
IamRole iamRole1 = new IamRole("iamRoleName1", "iamRoleDescription1");
iamRoles.add(iamRole1);
IamRole iamRole2 = new IamRole("iamRoleName2", " ");
iamRoles.add(iamRole2);
NamespaceIamRoleAuthorizationUpdateRequest expectedNamespaceIamRoleAuthorizationUpdateRequest = new NamespaceIamRoleAuthorizationUpdateRequest(iamRoles);
NamespaceEntity expectedNamespaceEntity = new NamespaceEntity();
expectedNamespaceEntity.setCode("NAMESPACE");
when(namespaceDaoHelper.getNamespaceEntity(any())).thenReturn(expectedNamespaceEntity);
when(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(any())).thenReturn(Collections.emptyList());
try {
namespaceIamRoleAuthorizationServiceImpl.updateNamespaceIamRoleAuthorization(expectedNamespace, expectedNamespaceIamRoleAuthorizationUpdateRequest);
fail();
} catch (Exception e) {
assertEquals(ObjectNotFoundException.class, e.getClass());
assertEquals(String.format("Namespace IAM role authorizations for namespace \"%s\" do not exist", expectedNamespaceEntity.getCode()), e.getMessage());
}
verify(namespaceDaoHelper).getNamespaceEntity(expectedNamespace);
verify(namespaceIamRoleAuthorizationDao).getNamespaceIamRoleAuthorizations(expectedNamespaceEntity);
verifyNoMoreInteractions(namespaceDaoHelper, namespaceIamRoleAuthorizationDao);
}
use of org.finra.herd.model.jpa.NamespaceEntity 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));
}
}
}
Aggregations