Search in sources :

Example 6 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 7 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 8 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)

Example 9 with StaffPerson

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

the class StaffPersonResourceTest method createDelegatesToResourceDelegate.

/**
   * Create Tests
   * 
   * @throws Exception required for test compilation
   */
@Test
public void createDelegatesToResourceDelegate() throws Exception {
    StaffPerson staffperson = new StaffPerson("1969-01-01", "Bart", "Student", "Simpson", "Q", "", new BigDecimal(9165551212L), 124, "1969-01-01", "", true, "abcdefghij", "description", "id", "03", false, "1234567890", "emailaddy");
    final Response resp = inMemoryResource.client().target(ROOT_RESOURCE).request().accept(MediaType.APPLICATION_JSON).post(Entity.entity(staffperson, MediaType.APPLICATION_JSON));
    ValidationErrorMessage msg = resp.readEntity(ValidationErrorMessage.class);
    if (msg != null) {
        final List<String> errors = msg.getErrors();
        if (errors != null && errors.size() > 0) {
            for (String err : errors) {
                System.out.println("ERROR: " + err);
            }
        }
    }
    verify(resourceDelegate).create(eq(staffperson));
}
Also used : Response(javax.ws.rs.core.Response) StaffPerson(gov.ca.cwds.rest.api.domain.cms.StaffPerson) ValidationErrorMessage(io.dropwizard.jersey.validation.ValidationErrorMessage) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 10 with StaffPerson

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

the class StaffPersonResourceTest method updateValidatesEntity.

@Test
public void updateValidatesEntity() throws Exception {
    StaffPerson staffperson = new StaffPerson("1969-01-01", "Bart", "Student", "Simpson", "Q", "", new BigDecimal(9165551212L), 124, "1969-01-01", "", true, "abcdefghij", "description", "id", "WILL_NOT_VALIDATE", false, "1234567890", "emailaddy");
    int status = inMemoryResource.client().target(FOUND_RESOURCE).request().accept(MediaType.APPLICATION_JSON).put(Entity.entity(staffperson, MediaType.APPLICATION_JSON)).getStatus();
    assertThat(status, is(422));
}
Also used : StaffPerson(gov.ca.cwds.rest.api.domain.cms.StaffPerson) BigDecimal(java.math.BigDecimal) 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