Search in sources :

Example 1 with StaffPerson

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

the class StaffPersonServiceTest method findReturnsCorrectStaffPersonWhenFound.

@SuppressWarnings("javadoc")
@Test
public void findReturnsCorrectStaffPersonWhenFound() throws Exception {
    String id = "ABC";
    StaffPerson expected = 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, expected, "2017-01-07");
    when(staffPersonDao.find(id)).thenReturn(staffPerson);
    StaffPerson found = staffPersonService.find(id);
    assertThat(found, 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 2 with StaffPerson

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

the class StaffPersonServiceTest method createReturnsPostedStaffPersonClass.

@SuppressWarnings("javadoc")
@Test
public void createReturnsPostedStaffPersonClass() 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);
    Response response = staffPersonService.create(request);
    assertThat(response.getClass(), is(PostedStaffPerson.class));
}
Also used : Response(gov.ca.cwds.rest.api.Response) 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 3 with StaffPerson

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

the class StaffPersonServiceTest method updateReturnsStaffPersonResponseOnSuccess.

@SuppressWarnings("javadoc")
@Test
public void updateReturnsStaffPersonResponseOnSuccess() throws Exception {
    String id = "ABC";
    StaffPerson expected = 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, expected, "2017-01-07");
    when(staffPersonDao.find(id)).thenReturn(staffPerson);
    when(staffPersonDao.update(any())).thenReturn(staffPerson);
    Object retval = staffPersonService.update(id, expected);
    assertThat(retval.getClass(), is(StaffPerson.class));
}
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 4 with StaffPerson

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

the class StaffPersonServiceTest method failsWhenPostedStaffPersonIdBlank.

@SuppressWarnings("javadoc")
@Test
public void failsWhenPostedStaffPersonIdBlank() 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("   ", 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 5 with StaffPerson

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

the class StaffPersonServiceTest method failsWhenPostedStaffPersonIdEmmpty.

@SuppressWarnings("javadoc")
@Test
public void failsWhenPostedStaffPersonIdEmmpty() 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("", 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)

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