Search in sources :

Example 6 with StockCardLineItemReasonDataBuilder

use of org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder 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)

Example 7 with StockCardLineItemReasonDataBuilder

use of org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder in project openlmis-stockmanagement by OpenLMIS.

the class ValidReasonAssignmentRepositoryIntegrationTest method generateInstance.

@Override
ValidReasonAssignment generateInstance() throws Exception {
    int instanceNumber = getNextInstanceNumber();
    StockCardLineItemReason reason = new StockCardLineItemReasonDataBuilder().withoutId().withName("Name" + instanceNumber).withCreditType().build();
    reasonRepository.save(reason);
    return new ValidReasonAssignment(PROGRAM_ID, FACILITY_TYPE_ID, false, reason);
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) ValidReasonAssignment(org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment) StockCardLineItemReasonDataBuilder(org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder)

Example 8 with StockCardLineItemReasonDataBuilder

use of org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder in project openlmis-stockmanagement by OpenLMIS.

the class StockCardLineItemReasonServiceTest method shouldThrowExceptionWhenUpdatingReasonNameIsDuplicateWithOtherOne.

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

Example 9 with StockCardLineItemReasonDataBuilder

use of org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder in project openlmis-stockmanagement by OpenLMIS.

the class StockCardLineItemReasonServiceTest method shouldSaveReasonWhenPassNullValueValidation.

@Test
public void shouldSaveReasonWhenPassNullValueValidation() throws Exception {
    // when
    StockCardLineItemReason reason = new StockCardLineItemReasonDataBuilder().withoutId().build();
    reasonService.saveOrUpdate(reason);
    // then
    verify(reasonRepository, times(1)).save(reason);
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) StockCardLineItemReasonDataBuilder(org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder) Test(org.junit.Test)

Aggregations

StockCardLineItemReasonDataBuilder (org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder)9 StockCardLineItemReason (org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason)8 Test (org.junit.Test)7 ResultActions (org.springframework.test.web.servlet.ResultActions)3 ValidReasonAssignment (org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment)2 Before (org.junit.Before)1