use of org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity in project herd by FINRAOS.
the class GlobalAttributeDefinitionLevelDaoTest method testGetGlobalAttributeDefinitionLevel.
@Test
public void testGetGlobalAttributeDefinitionLevel() {
// Create and persist a global attribute definition level entity.
GlobalAttributeDefinitionLevelEntity globalAttributeDefinitionLevelEntity = globalAttributeDefinitionLevelDaoTestHelper.createGlobalAttributeDefinitionLevelEntity(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL);
// Retrieve the global attribute definition level entity by its code.
assertEquals(globalAttributeDefinitionLevelEntity, globalAttributeDefinitionLevelDao.getGlobalAttributeDefinitionLevel(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL));
// Test case insensitivity.
assertEquals(globalAttributeDefinitionLevelEntity, globalAttributeDefinitionLevelDao.getGlobalAttributeDefinitionLevel(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL.toUpperCase()));
assertEquals(globalAttributeDefinitionLevelEntity, globalAttributeDefinitionLevelDao.getGlobalAttributeDefinitionLevel(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL.toLowerCase()));
// Confirm negative results when using invalid values.
assertNull(globalAttributeDefinitionLevelDao.getGlobalAttributeDefinitionLevel(I_DO_NOT_EXIST));
}
use of org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity 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);
}
use of org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity in project herd by FINRAOS.
the class GlobalAttributeDefinitionDaoTestHelper method createGlobalAttributeDefinitionEntity.
/**
* Creates and persists a new Global Attribute Definition entity.
*
* @param globalAttributeDefinitionLevel the level
* @param globalAttributeDefinitionName the name
*
* @return the newly created Global Attribute Definition entity.
*/
public GlobalAttributeDefinitionEntity createGlobalAttributeDefinitionEntity(String globalAttributeDefinitionLevel, String globalAttributeDefinitionName) {
GlobalAttributeDefinitionEntity globalAttributeDefinitionEntity = new GlobalAttributeDefinitionEntity();
GlobalAttributeDefinitionLevelEntity globalAttributeDefinitionLevelEntity = globalAttributeDefinitionLevelDao.getGlobalAttributeDefinitionLevel(globalAttributeDefinitionLevel);
if (globalAttributeDefinitionLevelEntity == null) {
globalAttributeDefinitionLevelEntity = globalAttributeDefinitionLevelDaoTestHelper.createGlobalAttributeDefinitionLevelEntity(globalAttributeDefinitionLevel);
}
globalAttributeDefinitionEntity.setGlobalAttributeDefinitionLevel(globalAttributeDefinitionLevelEntity);
globalAttributeDefinitionEntity.setGlobalAttributeDefinitionName(globalAttributeDefinitionName);
return globalAttributeDefinitionDao.saveAndRefresh(globalAttributeDefinitionEntity);
}
use of org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity in project herd by FINRAOS.
the class GlobalAttributeDefinitionLevelDaoTestHelper method createGlobalAttributeDefinitionLevelEntity.
/**
* Creates and persists a new global attribute definition level entity.
*
* @param globalAttributeDefinitionLevel the global attribute definition level code
*
* @return the newly created global attribute definition entity
*/
public GlobalAttributeDefinitionLevelEntity createGlobalAttributeDefinitionLevelEntity(String globalAttributeDefinitionLevel) {
GlobalAttributeDefinitionLevelEntity globalAttributeDefinitionLevelEntity = new GlobalAttributeDefinitionLevelEntity();
globalAttributeDefinitionLevelEntity.setGlobalAttributeDefinitionLevel(globalAttributeDefinitionLevel);
return globalAttributeDefinitionLevelDao.saveAndRefresh(globalAttributeDefinitionLevelEntity);
}
use of org.finra.herd.model.jpa.GlobalAttributeDefinitionLevelEntity in project herd by FINRAOS.
the class GlobalAttributeDefinitionDaoImpl method getAllGlobalAttributeDefinitionKeys.
@Override
public List<GlobalAttributeDefinitionKey> getAllGlobalAttributeDefinitionKeys() {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Tuple> criteria = builder.createTupleQuery();
// The criteria root is the global attribute definition.
Root<GlobalAttributeDefinitionEntity> globalAttributeDefinitionEntityRoot = criteria.from(GlobalAttributeDefinitionEntity.class);
// Join on the other tables that we filter on
Join<GlobalAttributeDefinitionEntity, GlobalAttributeDefinitionLevelEntity> globalAttributeDefinitionLevelEntityJoin = globalAttributeDefinitionEntityRoot.join(GlobalAttributeDefinitionEntity_.globalAttributeDefinitionLevel);
// Get the columns
Path<String> globalAttributeDefinitionLevel = globalAttributeDefinitionLevelEntityJoin.get(GlobalAttributeDefinitionLevelEntity_.globalAttributeDefinitionLevel);
Path<String> globalAttributeDefinitionName = globalAttributeDefinitionEntityRoot.get(GlobalAttributeDefinitionEntity_.globalAttributeDefinitionName);
// Add all clauses to the query
criteria.multiselect(globalAttributeDefinitionLevel, globalAttributeDefinitionName).orderBy(builder.asc(globalAttributeDefinitionLevel), builder.asc(globalAttributeDefinitionName));
// Populate the "keys" objects from the returned tuples
List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();
List<GlobalAttributeDefinitionKey> globalAttributeDefinitionKeys = new ArrayList<>();
for (Tuple tuple : tuples) {
globalAttributeDefinitionKeys.add(new GlobalAttributeDefinitionKey(tuple.get(globalAttributeDefinitionLevel), tuple.get(globalAttributeDefinitionName)));
}
return globalAttributeDefinitionKeys;
}
Aggregations