Search in sources :

Example 1 with ScreeningReference

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

the class ScreeningService method create.

/**
   * {@inheritDoc}
   * 
   * @see gov.ca.cwds.rest.services.CrudsService#create(gov.ca.cwds.rest.api.Request)
   */
@Override
public PostedScreening create(Request request) {
    assert request instanceof ScreeningReference;
    ScreeningReference screeningReference = (ScreeningReference) request;
    gov.ca.cwds.data.persistence.ns.Screening managed = new gov.ca.cwds.data.persistence.ns.Screening(screeningReference.getReference());
    managed = screeningDao.create(managed);
    return new PostedScreening(managed.getId(), managed.getReference());
}
Also used : PostedScreening(gov.ca.cwds.rest.api.domain.PostedScreening) Screening(gov.ca.cwds.rest.api.domain.Screening) Restrictions(org.hibernate.criterion.Restrictions) ScreeningReference(gov.ca.cwds.rest.api.domain.ScreeningReference) PostedScreening(gov.ca.cwds.rest.api.domain.PostedScreening)

Example 2 with ScreeningReference

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

the class ScreeningServiceTest method createReturnsNonNull.

@Test
public void createReturnsNonNull() throws Exception {
    Screening screeningMock = mock(Screening.class);
    when(screeningMock.getReference()).thenReturn("some_reference");
    when(screeningMock.getId()).thenReturn(1L);
    ScreeningReference request = new ScreeningReference("some_reference");
    when(screeningDao.create(any(gov.ca.cwds.data.persistence.ns.Screening.class))).thenReturn(screeningMock);
    PostedScreening postedScreening = screeningService.create(request);
    assertThat(postedScreening, is(notNullValue()));
}
Also used : PostedScreening(gov.ca.cwds.rest.api.domain.PostedScreening) Screening(gov.ca.cwds.data.persistence.ns.Screening) ScreeningReference(gov.ca.cwds.rest.api.domain.ScreeningReference) PostedScreening(gov.ca.cwds.rest.api.domain.PostedScreening) Test(org.junit.Test)

Example 3 with ScreeningReference

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

the class ScreeningServiceTest method createReturnsReturnsCorrectPostedScreening.

@Test
public void createReturnsReturnsCorrectPostedScreening() throws Exception {
    Screening screeningMock = mock(Screening.class);
    when(screeningMock.getReference()).thenReturn("some_reference");
    when(screeningMock.getId()).thenReturn(1L);
    ScreeningReference request = new ScreeningReference("some_reference");
    when(screeningDao.create(any(gov.ca.cwds.data.persistence.ns.Screening.class))).thenReturn(screeningMock);
    PostedScreening expected = new PostedScreening(1L, "some_reference");
    PostedScreening returned = screeningService.create(request);
    assertThat(returned, is(expected));
}
Also used : PostedScreening(gov.ca.cwds.rest.api.domain.PostedScreening) Screening(gov.ca.cwds.data.persistence.ns.Screening) ScreeningReference(gov.ca.cwds.rest.api.domain.ScreeningReference) PostedScreening(gov.ca.cwds.rest.api.domain.PostedScreening) Test(org.junit.Test)

Example 4 with ScreeningReference

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

the class ScreeningResourceTest method createDelegatesToResourceDelegate.

/*
   * Create Tests
   */
@Test
public void createDelegatesToResourceDelegate() throws Exception {
    ScreeningReference screeningReference = new ScreeningReference("reference");
    inMemoryResource.client().target(ROOT_RESOURCE).request().accept(MediaType.APPLICATION_JSON).post(Entity.entity(screeningReference, MediaType.APPLICATION_JSON));
    verify(resourceDelegate).create(eq(screeningReference));
}
Also used : ScreeningReference(gov.ca.cwds.rest.api.domain.ScreeningReference) Test(org.junit.Test)

Example 5 with ScreeningReference

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

the class ScreeningServiceTest method createReturnsPostedScreeningClass.

@Test
public void createReturnsPostedScreeningClass() throws Exception {
    Screening screeningMock = mock(Screening.class);
    when(screeningMock.getReference()).thenReturn("some_reference");
    when(screeningMock.getId()).thenReturn(1L);
    ScreeningReference request = new ScreeningReference("some_reference");
    when(screeningDao.create(any(gov.ca.cwds.data.persistence.ns.Screening.class))).thenReturn(screeningMock);
    PostedScreening postedScreening = screeningService.create(request);
    assertThat(postedScreening.getClass(), is(PostedScreening.class));
}
Also used : PostedScreening(gov.ca.cwds.rest.api.domain.PostedScreening) Screening(gov.ca.cwds.data.persistence.ns.Screening) ScreeningReference(gov.ca.cwds.rest.api.domain.ScreeningReference) PostedScreening(gov.ca.cwds.rest.api.domain.PostedScreening) Test(org.junit.Test)

Aggregations

ScreeningReference (gov.ca.cwds.rest.api.domain.ScreeningReference)5 PostedScreening (gov.ca.cwds.rest.api.domain.PostedScreening)4 Test (org.junit.Test)4 Screening (gov.ca.cwds.data.persistence.ns.Screening)3 Screening (gov.ca.cwds.rest.api.domain.Screening)1 Restrictions (org.hibernate.criterion.Restrictions)1