use of org.finra.herd.model.jpa.AttributeValueListEntity in project herd by FINRAOS.
the class AttributeValueListServiceTest method testDeleteAttributeValueList.
@Test
public void testDeleteAttributeValueList() {
// Create an attribute value list key.
AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME);
// Create a namespace entity.
NamespaceEntity namespaceEntity = new NamespaceEntity();
namespaceEntity.setCode(ATTRIBUTE_VALUE_LIST_NAMESPACE);
// Create an attribute value list entity.
AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity();
attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID);
attributeValueListEntity.setNamespace(namespaceEntity);
attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME);
// Mock calls to external methods.
when(attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey)).thenReturn(attributeValueListEntity);
when(attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity)).thenCallRealMethod();
// Call the method under test.
AttributeValueList result = attributeValueListService.deleteAttributeValueList(attributeValueListKey);
// Verify the external calls.
verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey);
verify(attributeValueListDaoHelper).getAttributeValueListEntity(attributeValueListKey);
verify(attributeValueListDao).delete(attributeValueListEntity);
verify(attributeValueListDaoHelper).createAttributeValueListFromEntity(attributeValueListEntity);
verifyNoMoreInteractionsHelper();
// Validate the result.
assertEquals(new AttributeValueList(ATTRIBUTE_VALUE_LIST_ID, attributeValueListKey), result);
}
use of org.finra.herd.model.jpa.AttributeValueListEntity in project herd by FINRAOS.
the class AttributeValueListServiceTest method testGetAttributeValueList.
@Test
public void testGetAttributeValueList() {
// Create an attribute value list key.
AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME);
// Create a namespace entity.
NamespaceEntity namespaceEntity = new NamespaceEntity();
namespaceEntity.setCode(ATTRIBUTE_VALUE_LIST_NAMESPACE);
// Create an attribute value list entity.
AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity();
attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID);
attributeValueListEntity.setNamespace(namespaceEntity);
attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME);
// Mock calls to external methods.
when(attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey)).thenReturn(attributeValueListEntity);
when(attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity)).thenCallRealMethod();
// Call the method under test.
AttributeValueList result = attributeValueListService.getAttributeValueList(attributeValueListKey);
// Verify the external calls.
verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey);
verify(attributeValueListDaoHelper).getAttributeValueListEntity(attributeValueListKey);
verify(attributeValueListDaoHelper).createAttributeValueListFromEntity(attributeValueListEntity);
verifyNoMoreInteractionsHelper();
// Validate the result.
assertEquals(new AttributeValueList(ATTRIBUTE_VALUE_LIST_ID, attributeValueListKey), result);
}
use of org.finra.herd.model.jpa.AttributeValueListEntity in project herd by FINRAOS.
the class AttributeValueListServiceTest method createAttributeValueList.
@Test
public void createAttributeValueList() {
// Create an attribute value list key.
AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME);
// Create an attribute value list create request.
AttributeValueListCreateRequest request = new AttributeValueListCreateRequest(attributeValueListKey);
// Create a namespace entity.
NamespaceEntity namespaceEntity = new NamespaceEntity();
namespaceEntity.setCode(ATTRIBUTE_VALUE_LIST_NAMESPACE);
// Create an attribute value list entity.
AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity();
attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID);
attributeValueListEntity.setNamespace(namespaceEntity);
attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME);
// Mock calls to external methods.
when(namespaceDaoHelper.getNamespaceEntity(ATTRIBUTE_VALUE_LIST_NAMESPACE)).thenReturn(namespaceEntity);
when(attributeValueListDao.getAttributeValueListByKey(attributeValueListKey)).thenReturn(null);
when(attributeValueListDao.saveAndRefresh(any(AttributeValueListEntity.class))).thenReturn(attributeValueListEntity);
when(attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity)).thenCallRealMethod();
// Call the method under test.
AttributeValueList result = attributeValueListService.createAttributeValueList(request);
// Verify the external calls.
verify(attributeValueListHelper).validateAttributeValueListCreateRequest(request);
verify(namespaceDaoHelper).getNamespaceEntity(ATTRIBUTE_VALUE_LIST_NAMESPACE);
verify(attributeValueListDao).getAttributeValueListByKey(attributeValueListKey);
verify(attributeValueListDao).saveAndRefresh(any(AttributeValueListEntity.class));
verify(attributeValueListDaoHelper).createAttributeValueListFromEntity(attributeValueListEntity);
verifyNoMoreInteractionsHelper();
// Validate the result.
assertEquals(new AttributeValueList(ATTRIBUTE_VALUE_LIST_ID, attributeValueListKey), result);
}
use of org.finra.herd.model.jpa.AttributeValueListEntity in project herd by FINRAOS.
the class AttributeValueListDaoImpl method getAttributeValueListByKey.
@Override
public AttributeValueListEntity getAttributeValueListByKey(AttributeValueListKey attributeValueListKey) {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<AttributeValueListEntity> criteria = builder.createQuery(AttributeValueListEntity.class);
// The criteria root is the attribute value list.
Root<AttributeValueListEntity> attributeValueListEntityRoot = criteria.from(AttributeValueListEntity.class);
// Join to the other tables we can filter on.
Join<AttributeValueListEntity, NamespaceEntity> namespaceEntityJoin = attributeValueListEntityRoot.join(AttributeValueListEntity_.namespace);
// Create the standard restrictions (i.e. the standard where clauses).
List<Predicate> predicates = new ArrayList<>();
predicates.add(builder.equal(builder.upper(namespaceEntityJoin.get(NamespaceEntity_.code)), attributeValueListKey.getNamespace().toUpperCase()));
predicates.add(builder.equal(builder.upper(attributeValueListEntityRoot.get(AttributeValueListEntity_.name)), attributeValueListKey.getAttributeValueListName().toUpperCase()));
// Add all clauses to the query.
criteria.select(attributeValueListEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()])));
// Execute the query and return the results.
return executeSingleResultQuery(criteria, String.format("Found more than one attribute value list with parameters {namespace=\"%s\", attribute_value_name=\"%s\"}.", attributeValueListKey.getNamespace(), attributeValueListKey.getAttributeValueListName()));
}
use of org.finra.herd.model.jpa.AttributeValueListEntity in project herd by FINRAOS.
the class AttributeValueListDaoImpl method getAttributeValueLists.
@Override
public List<AttributeValueListKey> getAttributeValueLists(Collection<String> namespaces) {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<AttributeValueListEntity> criteria = builder.createQuery(AttributeValueListEntity.class);
// The criteria root is the attribute value list entity.
Root<AttributeValueListEntity> attributeValueListEntityRoot = criteria.from(AttributeValueListEntity.class);
// Join to the other tables we can filter on.
Join<AttributeValueListEntity, NamespaceEntity> namespaceEntityJoin = attributeValueListEntityRoot.join(AttributeValueListEntity_.namespace);
// Create the standard restrictions (i.e. the standard where clauses).
List<Predicate> predicates = new ArrayList<>();
if (CollectionUtils.isNotEmpty(namespaces)) {
predicates.add(namespaceEntityJoin.get(NamespaceEntity_.code).in(namespaces));
}
// Order the results by namespace and job name.
List<Order> orderBy = new ArrayList<>();
orderBy.add(builder.asc(namespaceEntityJoin.get(NamespaceEntity_.code)));
orderBy.add(builder.asc(attributeValueListEntityRoot.get(AttributeValueListEntity_.name)));
// Add all clauses to the query.
criteria.select(attributeValueListEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(orderBy);
// Execute the query and build a list of keys.
List<AttributeValueListKey> attributeValueListKeys = new ArrayList<>();
for (AttributeValueListEntity attributeValueListEntity : entityManager.createQuery(criteria).getResultList()) {
attributeValueListKeys.add(new AttributeValueListKey(attributeValueListEntity.getNamespace().getCode(), attributeValueListEntity.getName()));
}
return attributeValueListKeys;
}
Aggregations