use of org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder 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);
}
use of org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder in project openlmis-stockmanagement by OpenLMIS.
the class StockCardLineItemReasonControllerIntegrationTest method shouldReturn200WhenUserGetAllReasons.
@Test
public void shouldReturn200WhenUserGetAllReasons() throws Exception {
// given
StockCardLineItemReason reason1 = new StockCardLineItemReasonDataBuilder().build();
StockCardLineItemReason reason2 = new StockCardLineItemReasonDataBuilder().withName("Another test reason").build();
when(stockCardLineItemReasonService.findReasons()).thenReturn(Arrays.asList(reason1, reason2));
// when
ResultActions resultActions = mvc.perform(MockMvcRequestBuilders.get(STOCK_CARD_LINE_ITEM_REASON_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE));
// then
resultActions.andExpect(status().isOk()).andExpect(jsonPath("$", hasSize(2)));
}
use of org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder in project openlmis-stockmanagement by OpenLMIS.
the class StockCardLineItemReasonControllerIntegrationTest method shouldReturn201WhenReasonSuccessfullyCreated.
@Test
public void shouldReturn201WhenReasonSuccessfullyCreated() throws Exception {
// given
StockCardLineItemReason createdReason = new StockCardLineItemReasonDataBuilder().withoutId().build();
when(stockCardLineItemReasonService.saveOrUpdate(any(StockCardLineItemReason.class))).thenReturn(createdReason);
// when
ResultActions resultActions = mvc.perform(MockMvcRequestBuilders.post(STOCK_CARD_LINE_ITEM_REASON_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(createdReason)));
// then
resultActions.andDo(print()).andExpect(status().isCreated()).andExpect(jsonPath("$.name", is(createdReason.getName()))).andExpect(jsonPath("$.description", is(createdReason.getDescription()))).andExpect(jsonPath("$.reasonType", is(createdReason.getReasonType().toString()))).andExpect(jsonPath("$.reasonCategory", is(createdReason.getReasonCategory().toString()))).andExpect(jsonPath("$.isFreeTextAllowed", is(createdReason.getIsFreeTextAllowed())));
}
use of org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder in project openlmis-stockmanagement by OpenLMIS.
the class QuantityValidatorTest method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
creditAdjustmentReason = new StockCardLineItemReasonDataBuilder().withAdjustmentCategory().build();
debitAdjustmentReason = new StockCardLineItemReasonDataBuilder().withAdjustmentCategory().withDebitType().build();
}
use of org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder 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())));
}
Aggregations