Search in sources :

Example 6 with NamespaceEntity

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

the class AllowedAttributeValueServiceTest method testDeleteAllowedAttributeValuesNoExists.

@Test
public void testDeleteAllowedAttributeValuesNoExists() {
    // Create attribute value list key.
    AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME);
    // Create namespace entity.
    NamespaceEntity namespaceEntity = new NamespaceEntity();
    namespaceEntity.setCode(ATTRIBUTE_VALUE_LIST_NAMESPACE);
    // Create attribute value list entity.
    AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity();
    attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID);
    attributeValueListEntity.setNamespace(namespaceEntity);
    attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME);
    attributeValueListEntity.setAllowedAttributeValues(new ArrayList<>());
    // Create allowed attribute value entity.
    AllowedAttributeValueEntity allowedAttributeValueEntity = new AllowedAttributeValueEntity();
    allowedAttributeValueEntity.setAllowedAttributeValue(ALLOWED_ATTRIBUTE_VALUE);
    allowedAttributeValueEntity.setAttributeValueList(attributeValueListEntity);
    // Mock calls to external method.
    when(attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey)).thenReturn(attributeValueListEntity);
    when(alternateKeyHelper.validateStringParameter("An", "allowed attribute value", ALLOWED_ATTRIBUTE_VALUE)).thenReturn(ALLOWED_ATTRIBUTE_VALUE);
    // Try to call method under test.
    try {
        allowedAttributeValueService.deleteAllowedAttributeValues(new AllowedAttributeValuesDeleteRequest(attributeValueListKey, Arrays.asList(ALLOWED_ATTRIBUTE_VALUE)));
        fail();
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Allowed attribute value \"%s\" doesn't exist in \"%s\" attribute value list.", ALLOWED_ATTRIBUTE_VALUE, attributeValueListEntity.getName()), e.getMessage());
    }
    // Verify the external calls.
    verify(attributeValueListDaoHelper).getAttributeValueListEntity(attributeValueListKey);
    verify(alternateKeyHelper).validateStringParameter("An", "allowed attribute value", ALLOWED_ATTRIBUTE_VALUE);
    verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey);
    verifyNoMoreInteractionsHelper();
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AllowedAttributeValuesDeleteRequest(org.finra.herd.model.api.xml.AllowedAttributeValuesDeleteRequest) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) AllowedAttributeValueEntity(org.finra.herd.model.jpa.AllowedAttributeValueEntity) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey) Test(org.junit.Test)

Example 7 with NamespaceEntity

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

the class AllowedAttributeValueServiceTest method testGetAllowedAttributeValues.

@Test
public void testGetAllowedAttributeValues() {
    // Create attribute value list key.
    AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME);
    // Create namespace entity.
    NamespaceEntity namespaceEntity = new NamespaceEntity();
    namespaceEntity.setCode(ATTRIBUTE_VALUE_LIST_NAMESPACE);
    // Create attribute value list entity.
    AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity();
    attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID);
    attributeValueListEntity.setNamespace(namespaceEntity);
    attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME);
    attributeValueListEntity.setAllowedAttributeValues(new ArrayList<>());
    // Create allowed attribute value entity.
    AllowedAttributeValueEntity allowedAttributeValueEntity = new AllowedAttributeValueEntity();
    allowedAttributeValueEntity.setAllowedAttributeValue(ALLOWED_ATTRIBUTE_VALUE);
    allowedAttributeValueEntity.setAttributeValueList(attributeValueListEntity);
    // Create a list of allowed attribute value entities.
    List<AllowedAttributeValueEntity> allowedAttributeValueEntities = new ArrayList<>();
    allowedAttributeValueEntities.add(allowedAttributeValueEntity);
    // Mock calls to external method.
    when(attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey)).thenReturn(attributeValueListEntity);
    when(allowedAttributeValueDao.getAllowedAttributeValuesByAttributeValueListKey(attributeValueListKey)).thenReturn(allowedAttributeValueEntities);
    // Call method under test.
    AllowedAttributeValuesInformation response = allowedAttributeValueService.getAllowedAttributeValues(attributeValueListKey);
    // Verify the external calls.
    verify(attributeValueListDaoHelper).getAttributeValueListEntity(attributeValueListKey);
    verify(allowedAttributeValueDao).getAllowedAttributeValuesByAttributeValueListKey(attributeValueListKey);
    verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey);
    verifyNoMoreInteractionsHelper();
    // Validate the response.
    assertEquals(attributeValueListKey, response.getAttributeValueListKey());
    assertEquals(Arrays.asList(ALLOWED_ATTRIBUTE_VALUE), response.getAllowedAttributeValues());
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) ArrayList(java.util.ArrayList) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) AllowedAttributeValueEntity(org.finra.herd.model.jpa.AllowedAttributeValueEntity) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey) AllowedAttributeValuesInformation(org.finra.herd.model.api.xml.AllowedAttributeValuesInformation) Test(org.junit.Test)

Example 8 with NamespaceEntity

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

the class AllowedAttributeValueServiceTest method testDeleteAllowedAttributeValues.

@Test
public void testDeleteAllowedAttributeValues() {
    // Create attribute value list key.
    AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME);
    // Create namespace entity.
    NamespaceEntity namespaceEntity = new NamespaceEntity();
    namespaceEntity.setCode(ATTRIBUTE_VALUE_LIST_NAMESPACE);
    // Create attribute value list entity.
    Collection<AllowedAttributeValueEntity> allowedAttributeValueEntities = new ArrayList<>();
    AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity();
    attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID);
    attributeValueListEntity.setNamespace(namespaceEntity);
    attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME);
    attributeValueListEntity.setAllowedAttributeValues(allowedAttributeValueEntities);
    // Create allowed attribute value entity.
    AllowedAttributeValueEntity allowedAttributeValueEntity = new AllowedAttributeValueEntity();
    allowedAttributeValueEntity.setAllowedAttributeValue(ALLOWED_ATTRIBUTE_VALUE);
    allowedAttributeValueEntity.setAttributeValueList(attributeValueListEntity);
    allowedAttributeValueEntities.add(allowedAttributeValueEntity);
    // Mock calls to external method.
    when(attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey)).thenReturn(attributeValueListEntity);
    when(allowedAttributeValueDao.saveAndRefresh(any(AllowedAttributeValueEntity.class))).thenReturn(allowedAttributeValueEntity);
    when(alternateKeyHelper.validateStringParameter("An", "allowed attribute value", ALLOWED_ATTRIBUTE_VALUE)).thenReturn(ALLOWED_ATTRIBUTE_VALUE);
    // Call method under test.
    AllowedAttributeValuesInformation response = allowedAttributeValueService.deleteAllowedAttributeValues(new AllowedAttributeValuesDeleteRequest(attributeValueListKey, Arrays.asList(ALLOWED_ATTRIBUTE_VALUE)));
    // Verify the external calls.
    verify(attributeValueListDaoHelper).getAttributeValueListEntity(attributeValueListKey);
    verify(allowedAttributeValueDao).saveAndRefresh(any(AttributeValueListEntity.class));
    verify(alternateKeyHelper).validateStringParameter("An", "allowed attribute value", ALLOWED_ATTRIBUTE_VALUE);
    verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey);
    verifyNoMoreInteractionsHelper();
    // Validate the response.
    assertEquals(attributeValueListKey, response.getAttributeValueListKey());
    assertEquals(Arrays.asList(ALLOWED_ATTRIBUTE_VALUE), response.getAllowedAttributeValues());
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AllowedAttributeValuesDeleteRequest(org.finra.herd.model.api.xml.AllowedAttributeValuesDeleteRequest) ArrayList(java.util.ArrayList) AllowedAttributeValueEntity(org.finra.herd.model.jpa.AllowedAttributeValueEntity) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey) AllowedAttributeValuesInformation(org.finra.herd.model.api.xml.AllowedAttributeValuesInformation) Test(org.junit.Test)

Example 9 with NamespaceEntity

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

the class AllowedAttributeValueServiceTest method testCreateAllowedAttributeValues.

@Test
public void testCreateAllowedAttributeValues() {
    // Create attribute value list key.
    AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME);
    // Create namespace entity.
    NamespaceEntity namespaceEntity = new NamespaceEntity();
    namespaceEntity.setCode(ATTRIBUTE_VALUE_LIST_NAMESPACE);
    // Create attribute value list entity.
    AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity();
    attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID);
    attributeValueListEntity.setNamespace(namespaceEntity);
    attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME);
    attributeValueListEntity.setAllowedAttributeValues(new ArrayList<>());
    // Create allowed attribute value entity.
    AllowedAttributeValueEntity allowedAttributeValueEntity = new AllowedAttributeValueEntity();
    allowedAttributeValueEntity.setAllowedAttributeValue(ALLOWED_ATTRIBUTE_VALUE);
    allowedAttributeValueEntity.setAttributeValueList(attributeValueListEntity);
    // Mock calls to external method.
    when(attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey)).thenReturn(attributeValueListEntity);
    when(allowedAttributeValueDao.saveAndRefresh(any(AllowedAttributeValueEntity.class))).thenReturn(allowedAttributeValueEntity);
    when(alternateKeyHelper.validateStringParameter("An", "allowed attribute value", ALLOWED_ATTRIBUTE_VALUE)).thenReturn(ALLOWED_ATTRIBUTE_VALUE);
    // Call method under test.
    AllowedAttributeValuesInformation response = allowedAttributeValueService.createAllowedAttributeValues(new AllowedAttributeValuesCreateRequest(attributeValueListKey, Arrays.asList(ALLOWED_ATTRIBUTE_VALUE)));
    // Verify the external calls.
    verify(attributeValueListDaoHelper).getAttributeValueListEntity(attributeValueListKey);
    verify(allowedAttributeValueDao, times(1)).saveAndRefresh(any(AllowedAttributeValueEntity.class));
    verify(allowedAttributeValueDao, times(1)).saveAndRefresh(any(AttributeValueListEntity.class));
    verify(alternateKeyHelper).validateStringParameter("An", "allowed attribute value", ALLOWED_ATTRIBUTE_VALUE);
    verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey);
    verifyNoMoreInteractionsHelper();
    // Validate the response.
    assertEquals(attributeValueListKey, response.getAttributeValueListKey());
    assertEquals(Arrays.asList(ALLOWED_ATTRIBUTE_VALUE), response.getAllowedAttributeValues());
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AllowedAttributeValuesCreateRequest(org.finra.herd.model.api.xml.AllowedAttributeValuesCreateRequest) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) AllowedAttributeValueEntity(org.finra.herd.model.jpa.AllowedAttributeValueEntity) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey) AllowedAttributeValuesInformation(org.finra.herd.model.api.xml.AllowedAttributeValuesInformation) Test(org.junit.Test)

Example 10 with NamespaceEntity

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

the class AllowedAttributeValueServiceTest method testCreateAllowedAttributeValuesAlreadyExists.

@Test
public void testCreateAllowedAttributeValuesAlreadyExists() {
    // Create attribute value list key.
    AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME);
    // Create namespace entity.
    NamespaceEntity namespaceEntity = new NamespaceEntity();
    namespaceEntity.setCode(ATTRIBUTE_VALUE_LIST_NAMESPACE);
    // Create attribute value list entity.
    Collection<AllowedAttributeValueEntity> allowedAttributeValueEntities = new ArrayList<>();
    AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity();
    attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID);
    attributeValueListEntity.setNamespace(namespaceEntity);
    attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME);
    attributeValueListEntity.setAllowedAttributeValues(allowedAttributeValueEntities);
    // Create allowed attribute value entity.
    AllowedAttributeValueEntity allowedAttributeValueEntity = new AllowedAttributeValueEntity();
    allowedAttributeValueEntity.setAllowedAttributeValue(ALLOWED_ATTRIBUTE_VALUE);
    allowedAttributeValueEntity.setAttributeValueList(attributeValueListEntity);
    allowedAttributeValueEntities.add(allowedAttributeValueEntity);
    // Mock calls to external method.
    when(attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey)).thenReturn(attributeValueListEntity);
    when(alternateKeyHelper.validateStringParameter("An", "allowed attribute value", ALLOWED_ATTRIBUTE_VALUE)).thenReturn(ALLOWED_ATTRIBUTE_VALUE);
    // Try to call method under test.
    try {
        allowedAttributeValueService.createAllowedAttributeValues(new AllowedAttributeValuesCreateRequest(attributeValueListKey, Arrays.asList(ALLOWED_ATTRIBUTE_VALUE)));
        fail();
    } catch (AlreadyExistsException e) {
        assertEquals(String.format("Allowed attribute value \"%s\" already exists in \"%s\" attribute value list.", ALLOWED_ATTRIBUTE_VALUE, attributeValueListEntity.getName()), e.getMessage());
    }
    // Verify the external calls.
    verify(attributeValueListDaoHelper).getAttributeValueListEntity(attributeValueListKey);
    verify(alternateKeyHelper).validateStringParameter("An", "allowed attribute value", ALLOWED_ATTRIBUTE_VALUE);
    verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey);
    verifyNoMoreInteractionsHelper();
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AllowedAttributeValuesCreateRequest(org.finra.herd.model.api.xml.AllowedAttributeValuesCreateRequest) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) ArrayList(java.util.ArrayList) AllowedAttributeValueEntity(org.finra.herd.model.jpa.AllowedAttributeValueEntity) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey) Test(org.junit.Test)

Aggregations

NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)225 Test (org.junit.Test)139 ArrayList (java.util.ArrayList)63 EmrClusterCreateRequest (org.finra.herd.model.api.xml.EmrClusterCreateRequest)59 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)43 EmrClusterDefinition (org.finra.herd.model.api.xml.EmrClusterDefinition)40 Predicate (javax.persistence.criteria.Predicate)39 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)38 EmrCluster (org.finra.herd.model.api.xml.EmrCluster)32 FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)25 EmrClusterDefinitionEntity (org.finra.herd.model.jpa.EmrClusterDefinitionEntity)24 NamespaceIamRoleAuthorizationEntity (org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity)24 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)18 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)16 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)14 EmrClusterDefinitionKey (org.finra.herd.model.api.xml.EmrClusterDefinitionKey)13 AttributeValueListEntity (org.finra.herd.model.jpa.AttributeValueListEntity)13 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)13 StorageEntity (org.finra.herd.model.jpa.StorageEntity)13 EmrClusterDefinitionInformation (org.finra.herd.model.api.xml.EmrClusterDefinitionInformation)12