Search in sources :

Example 1 with AllowedAttributeValuesDeleteRequest

use of org.finra.herd.model.api.xml.AllowedAttributeValuesDeleteRequest 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 2 with AllowedAttributeValuesDeleteRequest

use of org.finra.herd.model.api.xml.AllowedAttributeValuesDeleteRequest 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 3 with AllowedAttributeValuesDeleteRequest

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

the class AllowedAttributeValueRestControllerTest method testDeleteAllowedAttributeValue.

@Test
public void testDeleteAllowedAttributeValue() {
    // Create attribute value list key.
    AttributeValueListKey attributeValueListKey = new AttributeValueListKey(NAMESPACE_CODE, ATTRIBUTE_VALUE_LIST_NAME);
    AllowedAttributeValuesDeleteRequest request = new AllowedAttributeValuesDeleteRequest(attributeValueListKey, Arrays.asList(ALLOWED_ATTRIBUTE_VALUE));
    // Create the allowed attribute values information.
    AllowedAttributeValuesInformation allowedAttributeValuesInformation = new AllowedAttributeValuesInformation();
    allowedAttributeValuesInformation.setAttributeValueListKey(attributeValueListKey);
    allowedAttributeValuesInformation.setAllowedAttributeValues(Arrays.asList(ALLOWED_ATTRIBUTE_VALUE));
    // Mock calls to external method.
    when(allowedAttributeValueService.deleteAllowedAttributeValues(request)).thenReturn(allowedAttributeValuesInformation);
    // Call the method under test.
    AllowedAttributeValuesInformation response = allowedAttributeValueRestController.deleteAllowedAttributeValues(request);
    // Verify the external calls.
    verify(allowedAttributeValueService).deleteAllowedAttributeValues(request);
    verifyNoMoreInteractions(allowedAttributeValueService);
    // Validate the response.
    assertEquals(allowedAttributeValuesInformation, response);
}
Also used : AllowedAttributeValuesDeleteRequest(org.finra.herd.model.api.xml.AllowedAttributeValuesDeleteRequest) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey) AllowedAttributeValuesInformation(org.finra.herd.model.api.xml.AllowedAttributeValuesInformation) Test(org.junit.Test)

Example 4 with AllowedAttributeValuesDeleteRequest

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

the class AllowedAttributeValueServiceTest method testDeleteAllowedAttributeValuesDuplicateAttributeValues.

@Test
public void testDeleteAllowedAttributeValuesDuplicateAttributeValues() {
    // Create attribute value list key.
    AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME);
    // Create the allowed attribute values delete request.
    AllowedAttributeValuesDeleteRequest request = new AllowedAttributeValuesDeleteRequest(attributeValueListKey, Arrays.asList(ALLOWED_ATTRIBUTE_VALUE, ALLOWED_ATTRIBUTE_VALUE));
    // Mock calls to external methods.
    when(alternateKeyHelper.validateStringParameter("An", "allowed attribute value", ALLOWED_ATTRIBUTE_VALUE)).thenReturn(ALLOWED_ATTRIBUTE_VALUE);
    // Try to call method under test.
    try {
        allowedAttributeValueService.deleteAllowedAttributeValues(request);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Duplicate allowed attribute value \"%s\" found.", ALLOWED_ATTRIBUTE_VALUE), e.getMessage());
    }
    // Verify the external calls.
    verify(alternateKeyHelper, times(2)).validateStringParameter("An", "allowed attribute value", ALLOWED_ATTRIBUTE_VALUE);
    verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey);
    verifyNoMoreInteractionsHelper();
}
Also used : AllowedAttributeValuesDeleteRequest(org.finra.herd.model.api.xml.AllowedAttributeValuesDeleteRequest) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey) Test(org.junit.Test)

Example 5 with AllowedAttributeValuesDeleteRequest

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

the class AllowedAttributeValueServiceTest method testDeleteAllowedAttributeValuesMissingAllowedAttributeValue.

@Test
public void testDeleteAllowedAttributeValuesMissingAllowedAttributeValue() {
    // Create attribute value list key.
    AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME);
    // Create a delete request without allowed attribute value.
    AllowedAttributeValuesDeleteRequest request = new AllowedAttributeValuesDeleteRequest(attributeValueListKey, NO_ALLOWED_ATTRIBUTE_VALUES);
    // Try to call method under test.
    try {
        allowedAttributeValueService.deleteAllowedAttributeValues(request);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("At least one allowed attribute value must be specified.", e.getMessage());
    }
    // Verify the external calls.
    verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey);
    verifyNoMoreInteractionsHelper();
}
Also used : AllowedAttributeValuesDeleteRequest(org.finra.herd.model.api.xml.AllowedAttributeValuesDeleteRequest) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey) Test(org.junit.Test)

Aggregations

AllowedAttributeValuesDeleteRequest (org.finra.herd.model.api.xml.AllowedAttributeValuesDeleteRequest)5 AttributeValueListKey (org.finra.herd.model.api.xml.AttributeValueListKey)5 Test (org.junit.Test)5 AllowedAttributeValuesInformation (org.finra.herd.model.api.xml.AllowedAttributeValuesInformation)2 AllowedAttributeValueEntity (org.finra.herd.model.jpa.AllowedAttributeValueEntity)2 AttributeValueListEntity (org.finra.herd.model.jpa.AttributeValueListEntity)2 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)2 ArrayList (java.util.ArrayList)1 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)1