Search in sources :

Example 1 with AttributeValueListCreateRequest

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();
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) 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 2 with AttributeValueListCreateRequest

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);
}
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 3 with AttributeValueListCreateRequest

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

Example 4 with AttributeValueListCreateRequest

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);
}
Also used : AttributeValueListCreateRequest(org.finra.herd.model.api.xml.AttributeValueListCreateRequest) AttributeValueListKey(org.finra.herd.model.api.xml.AttributeValueListKey) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Aggregations

AttributeValueListCreateRequest (org.finra.herd.model.api.xml.AttributeValueListCreateRequest)4 AttributeValueListKey (org.finra.herd.model.api.xml.AttributeValueListKey)4 Test (org.junit.Test)4 AttributeValueList (org.finra.herd.model.api.xml.AttributeValueList)2 AttributeValueListEntity (org.finra.herd.model.jpa.AttributeValueListEntity)2 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)2 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)1 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)1