use of org.finra.herd.model.api.xml.AllowedAttributeValuesInformation 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());
}
use of org.finra.herd.model.api.xml.AllowedAttributeValuesInformation 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());
}
use of org.finra.herd.model.api.xml.AllowedAttributeValuesInformation 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());
}
use of org.finra.herd.model.api.xml.AllowedAttributeValuesInformation in project herd by FINRAOS.
the class AllowedAttributeValueServiceImpl method createAllowedAttributeValuesInformationFromEntities.
/**
* Creates the allowed attribute values information from the persisted entities.
*
* @param attributeValueListEntity the attribute value list entity
* @param allowedAttributeValueEntities the list of allowed attribute value entities
*
* @return the allowed attribute values information
*/
private AllowedAttributeValuesInformation createAllowedAttributeValuesInformationFromEntities(AttributeValueListEntity attributeValueListEntity, Collection<AllowedAttributeValueEntity> allowedAttributeValueEntities) {
// Create an allowed attribute values information instance.
AllowedAttributeValuesInformation allowedAttributeValuesInformation = new AllowedAttributeValuesInformation();
// Add the attribute value list key.
AttributeValueListKey attributeValueListKey = new AttributeValueListKey();
allowedAttributeValuesInformation.setAttributeValueListKey(attributeValueListKey);
attributeValueListKey.setNamespace(attributeValueListEntity.getNamespace().getCode());
attributeValueListKey.setAttributeValueListName(attributeValueListEntity.getName());
// Add the allowed attribute values.
List<String> allowedAttributeValues = new ArrayList<>();
allowedAttributeValuesInformation.setAllowedAttributeValues(allowedAttributeValues);
allowedAttributeValueEntities.forEach(allowedAttributeValueEntity -> {
allowedAttributeValues.add(allowedAttributeValueEntity.getAllowedAttributeValue());
});
return allowedAttributeValuesInformation;
}
use of org.finra.herd.model.api.xml.AllowedAttributeValuesInformation in project herd by FINRAOS.
the class AllowedAttributeValueRestControllerTest method testCreateAllowedAttributeValue.
@Test
public void testCreateAllowedAttributeValue() {
// Create attribute value list key.
AttributeValueListKey attributeValueListKey = new AttributeValueListKey(NAMESPACE_CODE, ATTRIBUTE_VALUE_LIST_NAME);
AllowedAttributeValuesCreateRequest request = new AllowedAttributeValuesCreateRequest(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.createAllowedAttributeValues(request)).thenReturn(allowedAttributeValuesInformation);
// Call the method under test.
AllowedAttributeValuesInformation response = allowedAttributeValueRestController.createAllowedAttributeValues(request);
// Verify the external calls.
verify(allowedAttributeValueService).createAllowedAttributeValues(request);
verifyNoMoreInteractions(allowedAttributeValueService);
// Validate the response.
assertEquals(allowedAttributeValuesInformation, response);
}
Aggregations