use of org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason in project openlmis-stockmanagement by OpenLMIS.
the class StockCardLineItemReasonControllerIntegrationTest method shouldReturn200WhenUserGetAllReasons.
@Test
public void shouldReturn200WhenUserGetAllReasons() throws Exception {
// given
StockCardLineItemReason reason1 = new StockCardLineItemReasonDataBuilder().build();
StockCardLineItemReason reason2 = new StockCardLineItemReasonDataBuilder().withName("Another test reason").build();
when(stockCardLineItemReasonService.findReasons()).thenReturn(Arrays.asList(reason1, reason2));
// when
ResultActions resultActions = mvc.perform(MockMvcRequestBuilders.get(STOCK_CARD_LINE_ITEM_REASON_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE));
// then
resultActions.andExpect(status().isOk()).andExpect(jsonPath("$", hasSize(2)));
}
use of org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason in project openlmis-stockmanagement by OpenLMIS.
the class StockCardLineItemReasonControllerIntegrationTest method shouldReturn201WhenReasonSuccessfullyCreated.
@Test
public void shouldReturn201WhenReasonSuccessfullyCreated() throws Exception {
// given
StockCardLineItemReason createdReason = new StockCardLineItemReasonDataBuilder().withoutId().build();
when(stockCardLineItemReasonService.saveOrUpdate(any(StockCardLineItemReason.class))).thenReturn(createdReason);
// when
ResultActions resultActions = mvc.perform(MockMvcRequestBuilders.post(STOCK_CARD_LINE_ITEM_REASON_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(createdReason)));
// then
resultActions.andDo(print()).andExpect(status().isCreated()).andExpect(jsonPath("$.name", is(createdReason.getName()))).andExpect(jsonPath("$.description", is(createdReason.getDescription()))).andExpect(jsonPath("$.reasonType", is(createdReason.getReasonType().toString()))).andExpect(jsonPath("$.reasonCategory", is(createdReason.getReasonCategory().toString()))).andExpect(jsonPath("$.isFreeTextAllowed", is(createdReason.getIsFreeTextAllowed())));
}
use of org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason in project openlmis-stockmanagement by OpenLMIS.
the class ValidReasonAssignmentControllerIntegrationTest method mockedValidReasonAssignment.
private ValidReasonAssignmentDto mockedValidReasonAssignment(UUID reasonId, ReasonType reasonType) {
StockCardLineItemReason reason = new StockCardLineItemReason();
reason.setId(reasonId);
reason.setReasonType(reasonType);
ValidReasonAssignmentDto assignment = new ValidReasonAssignmentDto();
assignment.setReason(reason);
assignment.setProgramId(reasonId);
assignment.setFacilityTypeId(reasonId);
when(reasonRepository.exists(assignment.getReason().getId())).thenReturn(true);
return assignment;
}
use of org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason in project openlmis-stockmanagement by OpenLMIS.
the class ValidReasonAssignmentControllerIntegrationTest method shouldReturn400IfReasonNotExist.
@Test
public void shouldReturn400IfReasonNotExist() throws Exception {
// given
UUID reasonId = UUID.randomUUID();
StockCardLineItemReason reason = new StockCardLineItemReason();
reason.setId(reasonId);
when(reasonRepository.findOne(reasonId)).thenReturn(null);
ValidReasonAssignment assignment = new ValidReasonAssignment();
assignment.setReason(reason);
// when
ResultActions resultActions = mvc.perform(post(VALID_REASON_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(assignment)));
// then
resultActions.andExpect(status().isBadRequest());
verify(reasonAssignmentRepository, never()).save(any(ValidReasonAssignment.class));
}
use of org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason in project openlmis-stockmanagement by OpenLMIS.
the class AdjustmentReasonValidatorIntegrationTest method incorrectReasonTypeShouldNotPassWhenEventHasNoSourceAndDestination.
@Test
public void incorrectReasonTypeShouldNotPassWhenEventHasNoSourceAndDestination() throws Exception {
// given
StockCardLineItemReason reason = StockCardLineItemReason.builder().reasonType(ReasonType.BALANCE_ADJUSTMENT).reasonCategory(ReasonCategory.ADJUSTMENT).isFreeTextAllowed(true).name("Balance Adjustment").build();
StockEventDto stockEventDto = StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto();
stockEventDto.getLineItems().get(0).setReasonId(reasonRepository.save(reason).getId());
setContext(stockEventDto);
expectedEx.expect(ValidationMessageException.class);
expectedEx.expectMessage(ERROR_EVENT_ADJUSTMENT_REASON_TYPE_INVALID + ": " + reason.getReasonType());
// when
adjustmentReasonValidator.validate(stockEventDto);
}
Aggregations