Search in sources :

Example 1 with PostedAllegationPerpetratorHistory

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));
}
Also used : PostedAllegationPerpetratorHistory(gov.ca.cwds.rest.api.domain.cms.PostedAllegationPerpetratorHistory) PostedAllegationPerpetratorHistory(gov.ca.cwds.rest.api.domain.cms.PostedAllegationPerpetratorHistory) AllegationPerpetratorHistory(gov.ca.cwds.rest.api.domain.cms.AllegationPerpetratorHistory) Test(org.junit.Test)

Example 2 with PostedAllegationPerpetratorHistory

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());
    }
}
Also used : PostedAllegationPerpetratorHistory(gov.ca.cwds.rest.api.domain.cms.PostedAllegationPerpetratorHistory) ServiceException(gov.ca.cwds.rest.services.ServiceException) PostedAllegationPerpetratorHistory(gov.ca.cwds.rest.api.domain.cms.PostedAllegationPerpetratorHistory) AllegationPerpetratorHistory(gov.ca.cwds.rest.api.domain.cms.AllegationPerpetratorHistory) Test(org.junit.Test)

Example 3 with PostedAllegationPerpetratorHistory

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);
    }
}
Also used : PostedAllegationPerpetratorHistory(gov.ca.cwds.rest.api.domain.cms.PostedAllegationPerpetratorHistory) AllegationPerpetratorHistory(gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory) PostedAllegationPerpetratorHistory(gov.ca.cwds.rest.api.domain.cms.PostedAllegationPerpetratorHistory) EntityExistsException(javax.persistence.EntityExistsException) ServiceException(gov.ca.cwds.rest.services.ServiceException)

Example 4 with PostedAllegationPerpetratorHistory

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()));
}
Also used : PostedAllegationPerpetratorHistory(gov.ca.cwds.rest.api.domain.cms.PostedAllegationPerpetratorHistory) PostedAllegationPerpetratorHistory(gov.ca.cwds.rest.api.domain.cms.PostedAllegationPerpetratorHistory) AllegationPerpetratorHistory(gov.ca.cwds.rest.api.domain.cms.AllegationPerpetratorHistory) Test(org.junit.Test)

Example 5 with PostedAllegationPerpetratorHistory

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());
}
Also used : PostedAllegationPerpetratorHistory(gov.ca.cwds.rest.api.domain.cms.PostedAllegationPerpetratorHistory) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PostedAllegationPerpetratorHistory(gov.ca.cwds.rest.api.domain.cms.PostedAllegationPerpetratorHistory) AllegationPerpetratorHistory(gov.ca.cwds.rest.api.domain.cms.AllegationPerpetratorHistory) Test(org.junit.Test)

Aggregations

PostedAllegationPerpetratorHistory (gov.ca.cwds.rest.api.domain.cms.PostedAllegationPerpetratorHistory)6 AllegationPerpetratorHistory (gov.ca.cwds.rest.api.domain.cms.AllegationPerpetratorHistory)5 Test (org.junit.Test)5 ServiceException (gov.ca.cwds.rest.services.ServiceException)3 AllegationPerpetratorHistory (gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory)1 EntityExistsException (javax.persistence.EntityExistsException)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1