Search in sources :

Example 1 with PrimaryKeyResponse

use of gov.ca.cwds.rest.api.PrimaryKeyResponse in project api-core by ca-cwds.

the class ServiceBackedResourceDelegateTest method setup.

@Before
public void setup() throws Exception {
    nonUniqueDomainObject = new ResourceDelegateTestDomainObject(ID_FOUND);
    uniqueDomainObject = new ResourceDelegateTestDomainObject(ID_NOT_FOUND);
    unexpectedExceptionDomainObject = new ResourceDelegateTestDomainObject(new Long(13));
    validationErrorMessageDomainObject = new ResourceDelegateTestDomainObject(new Long(15));
    ArrayList messages = new ArrayList<>();
    validationErrorMessageDomainObject.setMessages(messages);
    when(crudsService.find(ID_NOT_FOUND)).thenReturn(null);
    when(crudsService.find(ID_FOUND)).thenReturn(nonUniqueDomainObject);
    when(crudsService.delete(ID_NOT_FOUND)).thenReturn(null);
    when(crudsService.delete(ID_FOUND)).thenReturn(nonUniqueDomainObject);
    when(crudsService.create(eq(uniqueDomainObject))).thenReturn(new PrimaryKeyResponse(nonUniqueDomainObject.getId()));
    when(crudsService.create(eq(nonUniqueDomainObject))).thenThrow(new ServiceException(new EntityExistsException()));
    when(crudsService.create(eq(unexpectedExceptionDomainObject))).thenThrow(new ServiceException(new RuntimeException()));
    when(crudsService.create(eq(validationErrorMessageDomainObject))).thenReturn(validationErrorMessageDomainObject);
    when(crudsService.update(eq(1L), eq(unexpectedExceptionDomainObject))).thenThrow(new ServiceException(new RuntimeException()));
    when(crudsService.update(eq(-1L), eq(uniqueDomainObject))).thenThrow(new ServiceException(new EntityNotFoundException()));
    when(crudsService.update(eq(1L), eq(nonUniqueDomainObject))).thenReturn(new PrimaryKeyResponse(nonUniqueDomainObject.getId()));
}
Also used : ServiceException(gov.ca.cwds.rest.services.ServiceException) PrimaryKeyResponse(gov.ca.cwds.rest.api.PrimaryKeyResponse) ArrayList(java.util.ArrayList) EntityNotFoundException(javax.persistence.EntityNotFoundException) EntityExistsException(javax.persistence.EntityExistsException) Before(org.junit.Before)

Aggregations

PrimaryKeyResponse (gov.ca.cwds.rest.api.PrimaryKeyResponse)1 ServiceException (gov.ca.cwds.rest.services.ServiceException)1 ArrayList (java.util.ArrayList)1 EntityExistsException (javax.persistence.EntityExistsException)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1 Before (org.junit.Before)1