Search in sources :

Example 16 with StockCardLineItemReason

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())));
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) ResultActions(org.springframework.test.web.servlet.ResultActions) StockCardLineItemReasonDataBuilder(org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder) Test(org.junit.Test)

Example 17 with StockCardLineItemReason

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));
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) ValidReasonAssignmentDto(org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto) ValidReasonAssignment(org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment) ResultActions(org.springframework.test.web.servlet.ResultActions) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 18 with StockCardLineItemReason

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();
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) Profiler(org.slf4j.profiler.Profiler) StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem) OrderableLotIdentity(org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity) StockCard(org.openlmis.stockmanagement.domain.card.StockCard)

Example 19 with StockCardLineItemReason

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);
}
Also used : PhysicalInventoryLineItemAdjustment(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventoryLineItemAdjustment) StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason)

Example 20 with StockCardLineItemReason

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));
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) ValidReasonAssignment(org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment) StockCardLineItemReasonDataBuilder(org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder) Test(org.junit.Test)

Aggregations

StockCardLineItemReason (org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason)28 Test (org.junit.Test)18 StockCardLineItemReasonDataBuilder (org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder)8 ResultActions (org.springframework.test.web.servlet.ResultActions)6 UUID (java.util.UUID)4 ValidReasonAssignment (org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment)4 UUID.randomUUID (java.util.UUID.randomUUID)3 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)3 BaseIntegrationTest (org.openlmis.stockmanagement.BaseIntegrationTest)2 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)2 StockCardLineItem (org.openlmis.stockmanagement.domain.card.StockCardLineItem)2 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)2 Node (org.openlmis.stockmanagement.domain.sourcedestination.Node)2 ValidReasonAssignmentDto (org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto)2 Profiler (org.slf4j.profiler.Profiler)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 List (java.util.List)1 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)1 PhysicalInventoryLineItemAdjustment (org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventoryLineItemAdjustment)1 ValidDestinationAssignment (org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment)1