Search in sources :

Example 1 with PostedStaffPerson

use of gov.ca.cwds.rest.api.domain.cms.PostedStaffPerson 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 2 with PostedStaffPerson

use of gov.ca.cwds.rest.api.domain.cms.PostedStaffPerson 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 3 with PostedStaffPerson

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

the class StaffPersonService method create.

/**
   * {@inheritDoc}
   * 
   * @see gov.ca.cwds.rest.services.CrudsService#create(gov.ca.cwds.rest.api.Request)
   */
@Override
public PostedStaffPerson create(Request request) {
    assert request instanceof gov.ca.cwds.rest.api.domain.cms.StaffPerson;
    StaffPerson staffPerson = (StaffPerson) request;
    try {
        String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
        gov.ca.cwds.data.persistence.cms.StaffPerson managed = new gov.ca.cwds.data.persistence.cms.StaffPerson(IdGenerator.randomString(3), staffPerson, lastUpdatedId);
        managed = staffPersonDao.create(managed);
        return new PostedStaffPerson(managed);
    } catch (EntityExistsException e) {
        LOGGER.info("StaffPerson already exists : {}", staffPerson);
        throw new ServiceException(e);
    }
}
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) EntityExistsException(javax.persistence.EntityExistsException) ServiceException(gov.ca.cwds.rest.services.ServiceException)

Example 4 with PostedStaffPerson

use of gov.ca.cwds.rest.api.domain.cms.PostedStaffPerson 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 5 with PostedStaffPerson

use of gov.ca.cwds.rest.api.domain.cms.PostedStaffPerson 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)

Aggregations

PostedStaffPerson (gov.ca.cwds.rest.api.domain.cms.PostedStaffPerson)6 StaffPerson (gov.ca.cwds.rest.api.domain.cms.StaffPerson)6 Test (org.junit.Test)5 ServiceException (gov.ca.cwds.rest.services.ServiceException)4 EntityExistsException (javax.persistence.EntityExistsException)1