Search in sources :

Example 11 with AttributeValueListKey

use of org.finra.herd.model.api.xml.AttributeValueListKey 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);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AttributeValueList(org.finra.herd.model.api.xml.AttributeValueList) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey) Test(org.junit.Test)

Example 12 with AttributeValueListKey

use of org.finra.herd.model.api.xml.AttributeValueListKey in project herd by FINRAOS.

the class AttributeValueListServiceTest method testGetAttributeValueLists.

@Test
public void testGetAttributeValueLists() {
    // Create a set of authorized namespaces.
    Set<String> authorizedNamespaces = new HashSet<>();
    authorizedNamespaces.add(NAMESPACE);
    // Create an attribute value list key.
    List<AttributeValueListKey> attributeValueListKeys = Arrays.asList(new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME));
    // Mock calls to external methods.
    when(namespaceSecurityHelper.getAuthorizedNamespaces(NamespacePermissionEnum.READ)).thenReturn(authorizedNamespaces);
    when(attributeValueListDao.getAttributeValueLists(authorizedNamespaces)).thenReturn(attributeValueListKeys);
    // Call the method under test.
    AttributeValueListKeys result = attributeValueListService.getAttributeValueLists();
    // Verify the external calls.
    verify(namespaceSecurityHelper).getAuthorizedNamespaces(NamespacePermissionEnum.READ);
    verify(attributeValueListDao).getAttributeValueLists(authorizedNamespaces);
    verifyNoMoreInteractionsHelper();
    // Validate the result.
    assertEquals(new AttributeValueListKeys(attributeValueListKeys), result);
}
Also used : AttributeValueListKeys(org.finra.herd.model.api.xml.AttributeValueListKeys) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with AttributeValueListKey

use of org.finra.herd.model.api.xml.AttributeValueListKey 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);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AttributeValueList(org.finra.herd.model.api.xml.AttributeValueList) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey) Test(org.junit.Test)

Example 14 with AttributeValueListKey

use of org.finra.herd.model.api.xml.AttributeValueListKey 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);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AttributeValueList(org.finra.herd.model.api.xml.AttributeValueList) AttributeValueListCreateRequest(org.finra.herd.model.api.xml.AttributeValueListCreateRequest) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey) Test(org.junit.Test)

Example 15 with AttributeValueListKey

use of org.finra.herd.model.api.xml.AttributeValueListKey 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;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey)

Aggregations

AttributeValueListKey (org.finra.herd.model.api.xml.AttributeValueListKey)32 Test (org.junit.Test)27 AttributeValueListEntity (org.finra.herd.model.jpa.AttributeValueListEntity)14 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)11 AllowedAttributeValuesInformation (org.finra.herd.model.api.xml.AllowedAttributeValuesInformation)7 AttributeValueList (org.finra.herd.model.api.xml.AttributeValueList)7 AllowedAttributeValueEntity (org.finra.herd.model.jpa.AllowedAttributeValueEntity)7 ArrayList (java.util.ArrayList)6 AllowedAttributeValuesDeleteRequest (org.finra.herd.model.api.xml.AllowedAttributeValuesDeleteRequest)5 AllowedAttributeValuesCreateRequest (org.finra.herd.model.api.xml.AllowedAttributeValuesCreateRequest)4 AttributeValueListCreateRequest (org.finra.herd.model.api.xml.AttributeValueListCreateRequest)4 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)4 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)3 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)2 AttributeValueListKeys (org.finra.herd.model.api.xml.AttributeValueListKeys)2 HashSet (java.util.HashSet)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Order (javax.persistence.criteria.Order)1 Predicate (javax.persistence.criteria.Predicate)1 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)1