use of org.finra.herd.model.api.xml.AttributeValueListCreateRequest in project herd by FINRAOS.
the class AttributeValueListServiceTest method createAttributeValueListAlreadyExists.
@Test
public void createAttributeValueListAlreadyExists() {
// 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);
// Mock calls to external methods.
when(namespaceDaoHelper.getNamespaceEntity(ATTRIBUTE_VALUE_LIST_NAMESPACE)).thenReturn(new NamespaceEntity());
when(attributeValueListDao.getAttributeValueListByKey(attributeValueListKey)).thenReturn(new AttributeValueListEntity());
// Try to call the method under test.
try {
attributeValueListService.createAttributeValueList(request);
fail();
} catch (AlreadyExistsException e) {
assertEquals(String.format("Unable to create attribute value list with name \"%s\" because it already exists for namespace \"%s\".", ATTRIBUTE_VALUE_LIST_NAME, ATTRIBUTE_VALUE_LIST_NAMESPACE), e.getMessage());
}
// Verify the external calls.
verify(attributeValueListHelper).validateAttributeValueListCreateRequest(request);
verify(namespaceDaoHelper).getNamespaceEntity(ATTRIBUTE_VALUE_LIST_NAMESPACE);
verify(attributeValueListDao).getAttributeValueListByKey(attributeValueListKey);
verifyNoMoreInteractionsHelper();
}
use of org.finra.herd.model.api.xml.AttributeValueListCreateRequest 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.api.xml.AttributeValueListCreateRequest in project herd by FINRAOS.
the class AttributeValueListRestControllerTest method testCreateAttributeValueList.
@Test
public void testCreateAttributeValueList() {
// Create an attribute value list key.
AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME);
// Create an attribute value list.
AttributeValueList attributeValueList = new AttributeValueList(ATTRIBUTE_VALUE_LIST_ID, attributeValueListKey);
// Create an attribute value list create request.
AttributeValueListCreateRequest request = new AttributeValueListCreateRequest(attributeValueListKey);
// Mock calls to external methods.
when(attributeValueListService.createAttributeValueList(request)).thenReturn(attributeValueList);
// Call the method under test.
AttributeValueList result = attributeValueListRestController.createAttributeValueList(request);
// Verify the external calls.
verify(attributeValueListService).createAttributeValueList(request);
verifyNoMoreInteractions(attributeValueListService);
// Validate the result.
assertEquals(attributeValueList, result);
}
use of org.finra.herd.model.api.xml.AttributeValueListCreateRequest in project herd by FINRAOS.
the class AttributeValueListHelperTest method createValidateAttributeValueListCreateRequest.
@Test
public void createValidateAttributeValueListCreateRequest() {
// 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);
// Mock calls to external methods.
when(alternateKeyHelper.validateStringParameter("namespace", ATTRIBUTE_VALUE_LIST_NAMESPACE)).thenReturn(ATTRIBUTE_VALUE_LIST_NAMESPACE);
when(alternateKeyHelper.validateStringParameter("An", "attribute value list name", ATTRIBUTE_VALUE_LIST_NAME)).thenReturn(ATTRIBUTE_VALUE_LIST_NAME);
// Call the method under test.
attributeValueListHelper.validateAttributeValueListCreateRequest(request);
// Verify the external calls.
verify(alternateKeyHelper).validateStringParameter("namespace", ATTRIBUTE_VALUE_LIST_NAMESPACE);
verify(alternateKeyHelper).validateStringParameter("An", "attribute value list name", ATTRIBUTE_VALUE_LIST_NAME);
verifyNoMoreInteractions(alternateKeyHelper);
// Validate the result.
assertEquals(new AttributeValueListCreateRequest(attributeValueListKey), request);
}
Aggregations