use of gov.ca.cwds.rest.api.domain.cms.PostedAllegationPerpetratorHistory in project API by ca-cwds.
the class AllegationPerpetratorHistoryServiceTest method testCreateReturnsCorrectEntity.
@Override
@Test
public void testCreateReturnsCorrectEntity() throws Exception {
String id = "AbjFyc80It";
AllegationPerpetratorHistory allegationPerpetratorHistoryDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/AllegationPerpetratorHistory/valid/valid.json"), AllegationPerpetratorHistory.class);
gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory toCreate = new gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory(id, allegationPerpetratorHistoryDomain, "ABC");
AllegationPerpetratorHistory request = new AllegationPerpetratorHistory(toCreate);
when(allegationPerpetratorHistoryDao.create(any(gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory.class))).thenReturn(toCreate);
PostedAllegationPerpetratorHistory expected = new PostedAllegationPerpetratorHistory(toCreate);
PostedAllegationPerpetratorHistory returned = allegationPerpetratorHistoryService.create(request);
assertThat(returned, is(expected));
}
use of gov.ca.cwds.rest.api.domain.cms.PostedAllegationPerpetratorHistory in project API by ca-cwds.
the class AllegationPerpetratorHistoryServiceTest method testCreateBlankIDError.
@Override
@Test
public void testCreateBlankIDError() throws Exception {
try {
AllegationPerpetratorHistory allegationPerpetratorHistoryDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/AllegationPerpetratorHistory/valid/valid.json"), AllegationPerpetratorHistory.class);
gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory toCreate = new gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory(" ", allegationPerpetratorHistoryDomain, "ABC");
when(allegationPerpetratorHistoryDao.create(any(gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory.class))).thenReturn(toCreate);
PostedAllegationPerpetratorHistory expected = new PostedAllegationPerpetratorHistory(toCreate);
} catch (ServiceException e) {
assertEquals("AllegationPerpetratorHistory ID cannot be blank", e.getMessage());
}
}
use of gov.ca.cwds.rest.api.domain.cms.PostedAllegationPerpetratorHistory in project API by ca-cwds.
the class AllegationPerpetratorHistoryService method create.
/**
* {@inheritDoc}
*
* @see gov.ca.cwds.rest.services.CrudsService#create(gov.ca.cwds.rest.api.Request)
*/
@Override
public PostedAllegationPerpetratorHistory create(Request request) {
assert request instanceof gov.ca.cwds.rest.api.domain.cms.AllegationPerpetratorHistory;
gov.ca.cwds.rest.api.domain.cms.AllegationPerpetratorHistory allegationPerpetratorHistory = (gov.ca.cwds.rest.api.domain.cms.AllegationPerpetratorHistory) request;
try {
String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
AllegationPerpetratorHistory managed = new AllegationPerpetratorHistory(CmsKeyIdGenerator.cmsIdGenertor(lastUpdatedId), allegationPerpetratorHistory, lastUpdatedId);
managed = allegationPerpetratorHistoryDao.create(managed);
return new PostedAllegationPerpetratorHistory(managed);
} catch (EntityExistsException e) {
LOGGER.info("AllegationPerpetratorHistory already exists : {}", allegationPerpetratorHistory);
throw new ServiceException(e);
}
}
use of gov.ca.cwds.rest.api.domain.cms.PostedAllegationPerpetratorHistory in project API by ca-cwds.
the class AllegationPerpetratorHistoryServiceTest method testCreateReturnsNonNull.
@SuppressWarnings("javadoc")
@Test
public void testCreateReturnsNonNull() throws Exception {
String id = "AbjFyc80It";
AllegationPerpetratorHistory allegationPerpetratorHistoryDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/AllegationPerpetratorHistory/valid/valid.json"), AllegationPerpetratorHistory.class);
gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory toCreate = new gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory(id, allegationPerpetratorHistoryDomain, "ABC");
AllegationPerpetratorHistory request = new AllegationPerpetratorHistory(toCreate);
when(allegationPerpetratorHistoryDao.create(any(gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory.class))).thenReturn(toCreate);
PostedAllegationPerpetratorHistory postedAllegationPerpetratorHistory = allegationPerpetratorHistoryService.create(request);
assertThat(postedAllegationPerpetratorHistory, is(notNullValue()));
}
use of gov.ca.cwds.rest.api.domain.cms.PostedAllegationPerpetratorHistory in project API by ca-cwds.
the class AllegationPerpetratorHistoryServiceTest method createReturnsGeneratedId.
/*
* Test for checking the new Allegation Id generated and lenght is 10
*/
@SuppressWarnings("javadoc")
@Test
public void createReturnsGeneratedId() throws Exception {
AllegationPerpetratorHistory allegationPerpetratorHistoryDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/AllegationPerpetratorHistory/valid/valid.json"), AllegationPerpetratorHistory.class);
when(allegationPerpetratorHistoryDao.create(any(gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory.class))).thenAnswer(new Answer<gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory>() {
@Override
public gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory answer(InvocationOnMock invocation) throws Throwable {
gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory allegationPerpetratorHistory = (gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory) invocation.getArguments()[0];
return allegationPerpetratorHistory;
}
});
PostedAllegationPerpetratorHistory returned = allegationPerpetratorHistoryService.create(allegationPerpetratorHistoryDomain);
assertEquals(returned.getId().length(), 10);
PostedAllegationPerpetratorHistory newReturned = allegationPerpetratorHistoryService.create(allegationPerpetratorHistoryDomain);
Assert.assertNotEquals(returned.getId(), newReturned.getId());
}
Aggregations