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());
}
}
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());
}
}
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);
}
}
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()));
}
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());
}
}
Aggregations