Search in sources :

Example 1 with EntityNotFoundException

use of org.motechproject.mds.exception.entity.EntityNotFoundException in project motech by motech.

the class EntityControllerTest method shouldThrowExceptionIfNotFoundEntity.

@Test
public void shouldThrowExceptionIfNotFoundEntity() throws Exception {
    doThrow(new EntityNotFoundException(10L)).when(entityService).getEntityForEdit(10L);
    controller.perform(get("/entities/10")).andExpect(status().isConflict()).andExpect(content().string(ENTITY_NOT_FOUND));
}
Also used : EntityNotFoundException(org.motechproject.mds.exception.entity.EntityNotFoundException) Test(org.junit.Test)

Example 2 with EntityNotFoundException

use of org.motechproject.mds.exception.entity.EntityNotFoundException in project motech by motech.

the class EntityControllerTest method shouldNotSaveTemporaryChangeIfEntityNotExists.

@Test
public void shouldNotSaveTemporaryChangeIfEntityNotExists() throws Exception {
    doThrow(new EntityNotFoundException(100L)).when(entityService).saveDraftEntityChanges(eq(100L), any(DraftData.class));
    controller.perform(post("/entities/100/draft").body(new ObjectMapper().writeValueAsString(new DraftData()).getBytes()).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isConflict()).andExpect(content().string(ENTITY_NOT_FOUND));
}
Also used : DraftData(org.motechproject.mds.dto.DraftData) EntityNotFoundException(org.motechproject.mds.exception.entity.EntityNotFoundException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 3 with EntityNotFoundException

use of org.motechproject.mds.exception.entity.EntityNotFoundException in project motech by motech.

the class EntityControllerTest method shouldNotAbandonChangesIfEntityNotExists.

@Test
public void shouldNotAbandonChangesIfEntityNotExists() throws Exception {
    doThrow(new EntityNotFoundException(10000L)).when(entityService).abandonChanges(10000L);
    controller.perform(post("/entities/10000/abandon").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isConflict()).andExpect(content().string(ENTITY_NOT_FOUND));
    verify(entityService).abandonChanges(10000L);
}
Also used : EntityNotFoundException(org.motechproject.mds.exception.entity.EntityNotFoundException) Test(org.junit.Test)

Example 4 with EntityNotFoundException

use of org.motechproject.mds.exception.entity.EntityNotFoundException in project motech by motech.

the class EntityControllerTest method shouldNotGetEntityFieldsIfEntityNotExists.

@Test
public void shouldNotGetEntityFieldsIfEntityNotExists() throws Exception {
    doThrow(new EntityNotFoundException(10000L)).when(entityService).getFields(10000L);
    controller.perform(get("/entities/10000/fields")).andExpect(status().isConflict()).andExpect(content().string(ENTITY_NOT_FOUND));
}
Also used : EntityNotFoundException(org.motechproject.mds.exception.entity.EntityNotFoundException) Test(org.junit.Test)

Example 5 with EntityNotFoundException

use of org.motechproject.mds.exception.entity.EntityNotFoundException in project motech by motech.

the class InstanceController method getPreviousInstance.

@RequestMapping(value = "/instances/{entityId}/{instanceId}/previousVersion/{historyId}", method = RequestMethod.GET)
@ResponseBody
public HistoryRecord getPreviousInstance(@PathVariable Long entityId, @PathVariable Long instanceId, @PathVariable Long historyId) {
    HistoryRecord historyRecord = instanceService.getHistoryRecord(entityId, instanceId, historyId);
    if (historyRecord == null) {
        throw new EntityNotFoundException(entityId);
    }
    processFieldsForUIInHistoryRecord(historyRecord.getFields());
    return historyRecord;
}
Also used : EntityNotFoundException(org.motechproject.mds.exception.entity.EntityNotFoundException) BasicHistoryRecord(org.motechproject.mds.web.domain.BasicHistoryRecord) HistoryRecord(org.motechproject.mds.web.domain.HistoryRecord) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

EntityNotFoundException (org.motechproject.mds.exception.entity.EntityNotFoundException)9 Test (org.junit.Test)7 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 DraftData (org.motechproject.mds.dto.DraftData)1 FieldDto (org.motechproject.mds.dto.FieldDto)1 EntityInfo (org.motechproject.mds.entityinfo.EntityInfo)1 FieldNotFoundException (org.motechproject.mds.exception.field.FieldNotFoundException)1 BasicHistoryRecord (org.motechproject.mds.web.domain.BasicHistoryRecord)1 HistoryRecord (org.motechproject.mds.web.domain.HistoryRecord)1 Transactional (org.springframework.transaction.annotation.Transactional)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1