Search in sources :

Example 1 with GlobalAttributeDefinitionEntity

use of org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity in project herd by FINRAOS.

the class GlobalAttributeDefinitionServiceImpl method createGlobalAttributeDefinitionEntity.

/**
 * Creates and persists a new global Attribute Definition entity.
 *
 * @param globalAttributeDefinitionKey the global Attribute Definition key
 * @param globalAttributeDefinitionLevelEntity the global attribute definition level entity
 * @param attributeValueListEntity the attribute list entity (optional)
 *
 * @return the newly created global Attribute Definition entity
 */
private GlobalAttributeDefinitionEntity createGlobalAttributeDefinitionEntity(GlobalAttributeDefinitionKey globalAttributeDefinitionKey, GlobalAttributeDefinitionLevelEntity globalAttributeDefinitionLevelEntity, AttributeValueListEntity attributeValueListEntity) {
    GlobalAttributeDefinitionEntity globalAttributeDefinitionEntity = new GlobalAttributeDefinitionEntity();
    globalAttributeDefinitionEntity.setGlobalAttributeDefinitionLevel(globalAttributeDefinitionLevelEntity);
    globalAttributeDefinitionEntity.setGlobalAttributeDefinitionName(globalAttributeDefinitionKey.getGlobalAttributeDefinitionName());
    globalAttributeDefinitionEntity.setAttributeValueList(attributeValueListEntity);
    return globalAttributeDefinitionDao.saveAndRefresh(globalAttributeDefinitionEntity);
}
Also used : GlobalAttributeDefinitionEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity)

Example 2 with GlobalAttributeDefinitionEntity

use of org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity in project herd by FINRAOS.

the class BusinessObjectFormatServiceTest method testCreateBusinessObjectFormatWithGlobalAttributesAndAllowedAttributeValuesNegative2.

@Test
public void testCreateBusinessObjectFormatWithGlobalAttributesAndAllowedAttributeValuesNegative2() {
    GlobalAttributeDefinitionEntity globalAttributeDefinitionEntity = createGlobalAttributeDefinitionEntityWithAllowedAttributeValues();
    String invalidAttributeValue = ALLOWED_ATTRIBUTE_VALUE.toLowerCase();
    List<Attribute> attributes = businessObjectDefinitionServiceTestHelper.getNewAttributes();
    attributes.add(new Attribute(GLOBAL_ATTRIBUTE_DEFINITON_NAME, invalidAttributeValue));
    attributes = businessObjectDefinitionServiceTestHelper.getNewAttributes();
    attributes.add(new Attribute(GLOBAL_ATTRIBUTE_DEFINITON_NAME, invalidAttributeValue));
    // attribute value should be case sensitive
    try {
        // Create an initial version of a business object format.
        BusinessObjectFormat businessObjectFormat = businessObjectFormatServiceTestHelper.createTestBusinessObjectFormat(attributes);
        fail("Should throw exception before");
    } catch (IllegalArgumentException ex) {
        assertEquals(String.format("The business object format attribute \"%s\" value \"%s\" is not from allowed attribute values.", GLOBAL_ATTRIBUTE_DEFINITON_NAME, ALLOWED_ATTRIBUTE_VALUE.toLowerCase()), ex.getMessage());
    }
}
Also used : GlobalAttributeDefinitionEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity) Attribute(org.finra.herd.model.api.xml.Attribute) DescriptiveBusinessObjectFormat(org.finra.herd.model.api.xml.DescriptiveBusinessObjectFormat) BusinessObjectFormat(org.finra.herd.model.api.xml.BusinessObjectFormat) Test(org.junit.Test)

Example 3 with GlobalAttributeDefinitionEntity

use of org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity in project herd by FINRAOS.

the class GlobalAttributeDefinitionServiceTest method testDeleteGlobalAttributeDefinition.

@Test
public void testDeleteGlobalAttributeDefinition() {
    // Create a global attribute definition key.
    GlobalAttributeDefinitionKey globalAttributeDefinitionKey = new GlobalAttributeDefinitionKey(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL, GLOBAL_ATTRIBUTE_DEFINITON_NAME);
    // Create a global attribute definition entity.
    GlobalAttributeDefinitionEntity globalAttributeDefinitionEntity = globalAttributeDefinitionDaoTestHelper.createGlobalAttributeDefinitionEntity(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL, GLOBAL_ATTRIBUTE_DEFINITON_NAME);
    // Mock calls to external methods.
    when(globalAttributeDefinitionDaoHelper.getGlobalAttributeDefinitionEntity(globalAttributeDefinitionKey)).thenReturn(globalAttributeDefinitionEntity);
    // Call the method under test.
    GlobalAttributeDefinition response = globalAttributeDefinitionService.deleteGlobalAttributeDefinition(globalAttributeDefinitionKey);
    // Verify the external calls.
    verify(globalAttributeDefinitionHelper).validateGlobalAttributeDefinitionKey(globalAttributeDefinitionKey);
    verify(globalAttributeDefinitionDaoHelper).getGlobalAttributeDefinitionEntity(globalAttributeDefinitionKey);
    verify(globalAttributeDefinitionDao).delete(globalAttributeDefinitionEntity);
    verifyNoMoreInteractionsHelper();
    // Validate.
    assertEquals(new GlobalAttributeDefinition(response.getId(), globalAttributeDefinitionKey, attributeValueListNull), response);
}
Also used : GlobalAttributeDefinitionEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity) GlobalAttributeDefinitionKey(org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey) GlobalAttributeDefinition(org.finra.herd.model.api.xml.GlobalAttributeDefinition) Test(org.junit.Test)

Example 4 with GlobalAttributeDefinitionEntity

use of org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity in project herd by FINRAOS.

the class GlobalAttributeDefinitionServiceTest method testCreateGlobalAttributeDefinition.

@Test
public void testCreateGlobalAttributeDefinition() {
    // Create a global attribute definition key.
    GlobalAttributeDefinitionKey globalAttributeDefinitionKey = new GlobalAttributeDefinitionKey(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL, GLOBAL_ATTRIBUTE_DEFINITON_NAME);
    // Create a global attribute definition create request.
    GlobalAttributeDefinitionCreateRequest request = new GlobalAttributeDefinitionCreateRequest(globalAttributeDefinitionKey, attributeValueListKeyNull);
    // Create a global attribute definition level entity.
    GlobalAttributeDefinitionLevelEntity globalAttributeDefinitionLevelEntity = new GlobalAttributeDefinitionLevelEntity();
    globalAttributeDefinitionLevelEntity.setGlobalAttributeDefinitionLevel(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL);
    // Create a global attribute definition entity.
    GlobalAttributeDefinitionEntity globalAttributeDefinitionEntity = new GlobalAttributeDefinitionEntity();
    globalAttributeDefinitionEntity.setId(GLOBAL_ATTRIBUTE_DEFINITON_ID);
    globalAttributeDefinitionEntity.setGlobalAttributeDefinitionLevel(globalAttributeDefinitionLevelEntity);
    globalAttributeDefinitionEntity.setGlobalAttributeDefinitionName(GLOBAL_ATTRIBUTE_DEFINITON_NAME);
    // Mock calls to external methods.
    when(globalAttributeDefinitionLevelDao.getGlobalAttributeDefinitionLevel(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL)).thenReturn(globalAttributeDefinitionLevelEntity);
    when(globalAttributeDefinitionDao.saveAndRefresh(any(GlobalAttributeDefinitionEntity.class))).thenReturn(globalAttributeDefinitionEntity);
    // Call the method under test.
    GlobalAttributeDefinition response = globalAttributeDefinitionService.createGlobalAttributeDefinition(request);
    // Verify the external calls.
    verify(globalAttributeDefinitionHelper).validateGlobalAttributeDefinitionKey(globalAttributeDefinitionKey);
    verify(globalAttributeDefinitionDaoHelper).validateGlobalAttributeDefinitionNoExists(globalAttributeDefinitionKey);
    verify(globalAttributeDefinitionLevelDao).getGlobalAttributeDefinitionLevel(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL);
    verify(globalAttributeDefinitionDao).saveAndRefresh(any(GlobalAttributeDefinitionEntity.class));
    verifyNoMoreInteractionsHelper();
    // Validate the response.
    assertEquals(new GlobalAttributeDefinition(GLOBAL_ATTRIBUTE_DEFINITON_ID, globalAttributeDefinitionKey, attributeValueListNull), response);
}
Also used : GlobalAttributeDefinitionEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity) GlobalAttributeDefinitionLevelEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity) GlobalAttributeDefinitionKey(org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey) GlobalAttributeDefinitionCreateRequest(org.finra.herd.model.api.xml.GlobalAttributeDefinitionCreateRequest) GlobalAttributeDefinition(org.finra.herd.model.api.xml.GlobalAttributeDefinition) Test(org.junit.Test)

Example 5 with GlobalAttributeDefinitionEntity

use of org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity in project herd by FINRAOS.

the class GlobalAttributeDefinitionDaoHelperTest method testValidateGlobalAttributeDefinitionNoExistsEntityExists.

@Test
public void testValidateGlobalAttributeDefinitionNoExistsEntityExists() {
    // Create a global attribute definition key.
    GlobalAttributeDefinitionKey globalAttributeDefinitionKey = new GlobalAttributeDefinitionKey(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL, GLOBAL_ATTRIBUTE_DEFINITON_NAME);
    // Create a global attribute definition entity.
    GlobalAttributeDefinitionEntity globalAttributeDefinitionEntity = new GlobalAttributeDefinitionEntity();
    // Mock calls to external methods.
    when(globalAttributeDefinitionDao.getGlobalAttributeDefinitionByKey(globalAttributeDefinitionKey)).thenReturn(globalAttributeDefinitionEntity);
    // Try to call the method under test.
    try {
        globalAttributeDefinitionDaoHelper.validateGlobalAttributeDefinitionNoExists(globalAttributeDefinitionKey);
        fail();
    } catch (AlreadyExistsException e) {
        assertEquals(String.format("Unable to create global attribute definition with global attribute definition level \"%s\" " + "and global attribute definition name \"%s\" because it already exists.", globalAttributeDefinitionKey.getGlobalAttributeDefinitionLevel(), globalAttributeDefinitionKey.getGlobalAttributeDefinitionName()), e.getMessage());
    }
    // Verify the external calls.
    verify(globalAttributeDefinitionDao).getGlobalAttributeDefinitionByKey(globalAttributeDefinitionKey);
    verifyNoMoreInteractions(globalAttributeDefinitionDao);
}
Also used : GlobalAttributeDefinitionEntity(org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) GlobalAttributeDefinitionKey(org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Aggregations

GlobalAttributeDefinitionEntity (org.finra.herd.model.jpa.GlobalAttributeDefinitionEntity)19 Test (org.junit.Test)10 GlobalAttributeDefinitionKey (org.finra.herd.model.api.xml.GlobalAttributeDefinitionKey)7 GlobalAttributeDefinitionLevelEntity (org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity)5 Attribute (org.finra.herd.model.api.xml.Attribute)4 BusinessObjectFormat (org.finra.herd.model.api.xml.BusinessObjectFormat)4 DescriptiveBusinessObjectFormat (org.finra.herd.model.api.xml.DescriptiveBusinessObjectFormat)4 GlobalAttributeDefinition (org.finra.herd.model.api.xml.GlobalAttributeDefinition)3 AttributeValueListEntity (org.finra.herd.model.jpa.AttributeValueListEntity)3 ArrayList (java.util.ArrayList)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 AllowedAttributeValueEntity (org.finra.herd.model.jpa.AllowedAttributeValueEntity)2 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)2 Tuple (javax.persistence.Tuple)1 Predicate (javax.persistence.criteria.Predicate)1 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)1 AttributeValueListKey (org.finra.herd.model.api.xml.AttributeValueListKey)1 GlobalAttributeDefinitionCreateRequest (org.finra.herd.model.api.xml.GlobalAttributeDefinitionCreateRequest)1