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));
}
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);
}
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);
}
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);
}
Aggregations