Search in sources :

Example 1 with StockCardLineItemReason

use of org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason in project openlmis-stockmanagement by OpenLMIS.

the class StockCardLineItemReasonServiceTest method shouldThrowValidationExceptionWithUnavailableReasonDto.

@Test(expected = ValidationMessageException.class)
public void shouldThrowValidationExceptionWithUnavailableReasonDto() throws Exception {
    // given
    StockCardLineItemReason reason = new StockCardLineItemReason();
    // when
    reasonService.saveOrUpdate(reason);
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) Test(org.junit.Test)

Example 2 with StockCardLineItemReason

use of org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason in project openlmis-stockmanagement by OpenLMIS.

the class StockCardLineItemReasonServiceTest method shouldThrowExceptionWhenCreatingReasonNameIsDuplicateWithOtherOne.

@Test(expected = ValidationMessageException.class)
public void shouldThrowExceptionWhenCreatingReasonNameIsDuplicateWithOtherOne() throws Exception {
    // given
    StockCardLineItemReason creatingReason = new StockCardLineItemReasonDataBuilder().withoutId().build();
    StockCardLineItemReason existingReason = new StockCardLineItemReasonDataBuilder().build();
    when(reasonRepository.findByName(creatingReason.getName())).thenReturn(existingReason);
    // when
    reasonService.saveOrUpdate(creatingReason);
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) StockCardLineItemReasonDataBuilder(org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder) Test(org.junit.Test)

Example 3 with StockCardLineItemReason

use of org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason in project openlmis-stockmanagement by OpenLMIS.

the class ReceiveIssueReasonValidator method checkReason.

private void checkReason(StockEventDto event, StockEventLineItemDto lineItem, ReasonType expectedReasonType, String typeErrorKey, String categoryErrorKey) {
    if (lineItem.hasReasonId()) {
        StockCardLineItemReason foundReason = event.getContext().findEventReason(lineItem.getReasonId());
        // that is handled by other validators
        if (foundReason != null) {
            checkReasonType(expectedReasonType, typeErrorKey, lineItem.getReasonId(), foundReason);
            checkReasonCategory(categoryErrorKey, lineItem.getReasonId(), foundReason);
        }
    }
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason)

Example 4 with StockCardLineItemReason

use of org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason in project openlmis-stockmanagement by OpenLMIS.

the class StockCardLineItemTest method shouldNotIncreaseSohOverIntLimit.

@Test
public void shouldNotIncreaseSohOverIntLimit() throws Exception {
    // expect
    exception.expectMessage("exceed.upperLimit");
    // given
    StockCardLineItemReason creditReason = StockCardLineItemReason.builder().reasonType(ReasonType.CREDIT).build();
    int quantityToAdd = 10;
    StockCardLineItem lineItem = StockCardLineItem.builder().reason(creditReason).quantity(quantityToAdd).build();
    // when
    lineItem.calculateStockOnHand(MAX_VALUE - quantityToAdd + 1);
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) Test(org.junit.Test)

Example 5 with StockCardLineItemReason

use of org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason in project openlmis-stockmanagement by OpenLMIS.

the class StockCardLineItemReasonControllerIntegrationTest method shouldReturn403WhenUserHasNoPermissionToManageReasons.

@Test
public void shouldReturn403WhenUserHasNoPermissionToManageReasons() throws Exception {
    doThrow(new PermissionMessageException(new Message("key"))).when(permissionService).canManageReasons();
    // 1.create reason
    ResultActions postResults = mvc.perform(MockMvcRequestBuilders.post(STOCK_CARD_LINE_ITEM_REASON_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(new StockCardLineItemReason())));
    postResults.andExpect(status().isForbidden());
    // 2.update reason
    ResultActions putResults = mvc.perform(MockMvcRequestBuilders.put(STOCK_CARD_LINE_ITEM_REASON_API + "/" + UUID.randomUUID().toString()).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(new StockCardLineItemReason())));
    putResults.andExpect(status().isForbidden());
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) Message(org.openlmis.stockmanagement.util.Message) ResultActions(org.springframework.test.web.servlet.ResultActions) PermissionMessageException(org.openlmis.stockmanagement.exception.PermissionMessageException) 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