Search in sources :

Example 11 with StaffPerson

use of gov.ca.cwds.rest.api.domain.cms.StaffPerson in project API by ca-cwds.

the class StaffPersonServiceTest method createReturnsNonNull.

@SuppressWarnings("javadoc")
@Test
public void createReturnsNonNull() throws Exception {
    String id = "ABC";
    StaffPerson staffPersonDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/StaffPerson/valid/valid.json"), StaffPerson.class);
    gov.ca.cwds.data.persistence.cms.StaffPerson toCreate = new gov.ca.cwds.data.persistence.cms.StaffPerson(id, staffPersonDomain, "2017-01-07");
    StaffPerson request = new StaffPerson(toCreate);
    when(staffPersonDao.create(any(gov.ca.cwds.data.persistence.cms.StaffPerson.class))).thenReturn(toCreate);
    PostedStaffPerson postedStaffPerson = staffPersonService.create(request);
    assertThat(postedStaffPerson, is(notNullValue()));
}
Also used : PostedStaffPerson(gov.ca.cwds.rest.api.domain.cms.PostedStaffPerson) StaffPerson(gov.ca.cwds.rest.api.domain.cms.StaffPerson) PostedStaffPerson(gov.ca.cwds.rest.api.domain.cms.PostedStaffPerson) Test(org.junit.Test)

Example 12 with StaffPerson

use of gov.ca.cwds.rest.api.domain.cms.StaffPerson in project API by ca-cwds.

the class StaffPersonServiceTest method updateThrowsExceptionWhenStaffPersonNotFound.

@SuppressWarnings("javadoc")
@Test
public void updateThrowsExceptionWhenStaffPersonNotFound() throws Exception {
    try {
        String id = "ABC";
        StaffPerson staffPersonRequest = MAPPER.readValue(fixture("fixtures/domain/legacy/StaffPerson/valid/valid.json"), StaffPerson.class);
        when(staffPersonDao.update(any())).thenThrow(EntityNotFoundException.class);
        staffPersonService.update("ZZZ", staffPersonRequest);
        Assert.fail("Expected EntityNotFoundException was not thrown");
    } catch (Exception ex) {
        assertEquals(ex.getClass(), ServiceException.class);
    }
}
Also used : PostedStaffPerson(gov.ca.cwds.rest.api.domain.cms.PostedStaffPerson) StaffPerson(gov.ca.cwds.rest.api.domain.cms.StaffPerson) ServiceException(gov.ca.cwds.rest.services.ServiceException) EntityNotFoundException(javax.persistence.EntityNotFoundException) ServiceException(gov.ca.cwds.rest.services.ServiceException) ExpectedException(org.junit.rules.ExpectedException) Test(org.junit.Test)

Example 13 with StaffPerson

use of gov.ca.cwds.rest.api.domain.cms.StaffPerson in project API by ca-cwds.

the class StaffPersonServiceTest method updateReturnsCorrectStaffPersonOnSuccess.

@SuppressWarnings("javadoc")
@Test
public void updateReturnsCorrectStaffPersonOnSuccess() throws Exception {
    String id = "ABC";
    StaffPerson staffPersonRequest = MAPPER.readValue(fixture("fixtures/domain/legacy/StaffPerson/valid/valid.json"), StaffPerson.class);
    gov.ca.cwds.data.persistence.cms.StaffPerson staffPerson = new gov.ca.cwds.data.persistence.cms.StaffPerson(id, staffPersonRequest, "2017-01-07");
    when(staffPersonDao.find(id)).thenReturn(staffPerson);
    when(staffPersonDao.update(any())).thenReturn(staffPerson);
    StaffPerson expected = new StaffPerson(staffPerson);
    StaffPerson updated = staffPersonService.update(id, expected);
    assertThat(updated, is(expected));
}
Also used : PostedStaffPerson(gov.ca.cwds.rest.api.domain.cms.PostedStaffPerson) StaffPerson(gov.ca.cwds.rest.api.domain.cms.StaffPerson) Test(org.junit.Test)

Example 14 with StaffPerson

use of gov.ca.cwds.rest.api.domain.cms.StaffPerson in project API by ca-cwds.

the class StaffPersonServiceTest method failsWhenPostedStaffPersonIdNull.

@SuppressWarnings("javadoc")
@Test
public void failsWhenPostedStaffPersonIdNull() throws Exception {
    try {
        StaffPerson staffPersonDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/StaffPerson/valid/valid.json"), StaffPerson.class);
        gov.ca.cwds.data.persistence.cms.StaffPerson toCreate = new gov.ca.cwds.data.persistence.cms.StaffPerson(null, staffPersonDomain, "2017-01-07");
        when(staffPersonDao.create(any(gov.ca.cwds.data.persistence.cms.StaffPerson.class))).thenReturn(toCreate);
        PostedStaffPerson expected = new PostedStaffPerson(toCreate);
        Assert.fail("Expected AssertionError not thrown");
    } catch (ServiceException e) {
        assertEquals("StaffPerson ID cannot be empty", e.getMessage());
    }
}
Also used : PostedStaffPerson(gov.ca.cwds.rest.api.domain.cms.PostedStaffPerson) StaffPerson(gov.ca.cwds.rest.api.domain.cms.StaffPerson) PostedStaffPerson(gov.ca.cwds.rest.api.domain.cms.PostedStaffPerson) ServiceException(gov.ca.cwds.rest.services.ServiceException) Test(org.junit.Test)

Example 15 with StaffPerson

use of gov.ca.cwds.rest.api.domain.cms.StaffPerson in project API by ca-cwds.

the class StaffPersonServiceTest method createReturnsCorrectPostedPerson.

@SuppressWarnings("javadoc")
@Test
public void createReturnsCorrectPostedPerson() throws Exception {
    String id = "ABC";
    StaffPerson staffPersonDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/StaffPerson/valid/valid.json"), StaffPerson.class);
    gov.ca.cwds.data.persistence.cms.StaffPerson toCreate = new gov.ca.cwds.data.persistence.cms.StaffPerson(id, staffPersonDomain, "2017-01-07");
    StaffPerson request = new StaffPerson(toCreate);
    when(staffPersonDao.create(any(gov.ca.cwds.data.persistence.cms.StaffPerson.class))).thenReturn(toCreate);
    PostedStaffPerson expected = new PostedStaffPerson(toCreate);
    PostedStaffPerson returned = staffPersonService.create(request);
    assertThat(returned, is(expected));
}
Also used : PostedStaffPerson(gov.ca.cwds.rest.api.domain.cms.PostedStaffPerson) StaffPerson(gov.ca.cwds.rest.api.domain.cms.StaffPerson) PostedStaffPerson(gov.ca.cwds.rest.api.domain.cms.PostedStaffPerson) Test(org.junit.Test)

Aggregations

StaffPerson (gov.ca.cwds.rest.api.domain.cms.StaffPerson)16 Test (org.junit.Test)14 PostedStaffPerson (gov.ca.cwds.rest.api.domain.cms.PostedStaffPerson)12 ServiceException (gov.ca.cwds.rest.services.ServiceException)6 BigDecimal (java.math.BigDecimal)4 EntityNotFoundException (javax.persistence.EntityNotFoundException)2 Response (gov.ca.cwds.rest.api.Response)1 ValidationErrorMessage (io.dropwizard.jersey.validation.ValidationErrorMessage)1 EntityExistsException (javax.persistence.EntityExistsException)1 Response (javax.ws.rs.core.Response)1 ExpectedException (org.junit.rules.ExpectedException)1