use of org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason in project openlmis-stockmanagement by OpenLMIS.
the class StockCardLineItemReasonControllerIntegrationTest method shouldReturn200WhenReasonSuccessfullyUpdated.
@Test
public void shouldReturn200WhenReasonSuccessfullyUpdated() throws Exception {
// given
StockCardLineItemReason updatedReason = new StockCardLineItemReasonDataBuilder().withDescription("test reason").build();
when(stockCardLineItemReasonService.saveOrUpdate(any(StockCardLineItemReason.class))).thenReturn(updatedReason);
// when
ResultActions resultActions = mvc.perform(MockMvcRequestBuilders.put(STOCK_CARD_LINE_ITEM_REASON_API + "/" + updatedReason.getId().toString()).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(updatedReason)));
// then
resultActions.andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.id", is(updatedReason.getId().toString()))).andExpect(jsonPath("$.name", is(updatedReason.getName()))).andExpect(jsonPath("$.description", is(updatedReason.getDescription()))).andExpect(jsonPath("$.reasonType", is(updatedReason.getReasonType().toString()))).andExpect(jsonPath("$.reasonCategory", is(updatedReason.getReasonCategory().toString()))).andExpect(jsonPath("$.isFreeTextAllowed", is(updatedReason.getIsFreeTextAllowed())));
}
use of org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason in project openlmis-stockmanagement by OpenLMIS.
the class ValidReasonAssignmentControllerIntegrationTest method shouldNotAssignSameReasonTwice.
@Test
public void shouldNotAssignSameReasonTwice() throws Exception {
// given
UUID reasonId = UUID.randomUUID();
StockCardLineItemReason reason = new StockCardLineItemReason();
reason.setId(reasonId);
ValidReasonAssignmentDto assignment = new ValidReasonAssignmentDto();
assignment.setReason(reason);
assignment.setProgramId(UUID.randomUUID());
assignment.setFacilityTypeId(UUID.randomUUID());
when(reasonRepository.exists(reasonId)).thenReturn(true);
when(reasonAssignmentRepository.findByProgramIdAndFacilityTypeIdAndReasonId(assignment.getProgramId(), assignment.getFacilityTypeId(), reasonId)).thenReturn(new ValidReasonAssignment());
// 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().isOk());
verify(reasonAssignmentRepository, never()).save(any(ValidReasonAssignment.class));
}
use of org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason in project openlmis-stockmanagement by OpenLMIS.
the class StockEventNotificationProcessor method callNotifications.
private void callNotifications(StockEventDto event, StockEventLineItemDto eventLine) {
XLOGGER.entry(event, eventLine);
Profiler profiler = new Profiler("CALL_NOTIFICATION_FOR_LINE_ITEM");
profiler.setLogger(XLOGGER);
profiler.start("COPY_STOCK_CARD");
OrderableLotIdentity identity = OrderableLotIdentity.identityOf(eventLine);
StockCard card = event.getContext().findCard(identity);
StockCard copy = card.shallowCopy();
for (StockCardLineItem line : copy.getLineItems()) {
StockCardLineItemReason reason = line.getReason();
if (null != reason) {
line.setReason(event.getContext().findCardReason(reason.getId()));
}
}
profiler.start("CALCULATE_STOCK_ON_HAND");
copy.calculateStockOnHand();
profiler.start("NOTIFY_STOCK_CARD_EDITORS");
if (copy.getStockOnHand() == 0) {
stockoutNotifier.notifyStockEditors(copy);
}
profiler.stop().log();
XLOGGER.exit();
}
use of org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason in project openlmis-stockmanagement by OpenLMIS.
the class StockEventAdjustmentDto method toPhysicalInventoryLineItemAdjustment.
PhysicalInventoryLineItemAdjustment toPhysicalInventoryLineItemAdjustment() {
StockCardLineItemReason reason = new StockCardLineItemReason();
reason.setId(reasonId);
return new PhysicalInventoryLineItemAdjustment(reason, quantity);
}
use of org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason in project openlmis-stockmanagement by OpenLMIS.
the class ValidReasonAssignmentRepositoryIntegrationTest method shouldReturnValidReasonWithProgramAndFacilityTypeAndReasonTypes.
@Test
public void shouldReturnValidReasonWithProgramAndFacilityTypeAndReasonTypes() throws Exception {
ValidReasonAssignment validReasonAssignment = generateInstance();
repository.save(validReasonAssignment);
StockCardLineItemReason newReason = new StockCardLineItemReasonDataBuilder().withoutId().withName("Damage").withDebitType().build();
reasonRepository.save(newReason);
ValidReasonAssignment newAssignment = new ValidReasonAssignment(PROGRAM_ID, FACILITY_TYPE_ID, false, newReason);
repository.save(newAssignment);
List<StockCardLineItemReason> reasons = Arrays.asList(validReasonAssignment.getReason(), newReason);
List<ValidReasonAssignment> validReasonAssignments = repository.findByProgramIdAndFacilityTypeIdAndReasonIn(PROGRAM_ID, FACILITY_TYPE_ID, reasons);
assertThat(validReasonAssignments.size(), is(2));
assertThat(validReasonAssignments, hasItems(validReasonAssignment, newAssignment));
}
Aggregations