Search in sources :

Example 1 with StockCardLineItemReasonDataBuilder

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

Example 2 with StockCardLineItemReasonDataBuilder

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)));
}
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 3 with StockCardLineItemReasonDataBuilder

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())));
}
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 4 with StockCardLineItemReasonDataBuilder

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();
}
Also used : StockCardLineItemReasonDataBuilder(org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder) Before(org.junit.Before)

Example 5 with StockCardLineItemReasonDataBuilder

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

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