@Test
 public void shouldThrowExceptionIfNoProgramProductExistForGivenProgramIdAndProductId() {
   when(programProductMapper.getIdByProgramAndProductId(1L, 2L)).thenReturn(null);
   expectedEx.expect(DataException.class);
   expectedEx.expectMessage("programProduct.product.program.invalid");
   programProductRepository.getIdByProgramIdAndProductId(1L, 2L);
 }
示例#2
0
  @Before
  public void setUp() throws Exception {
    Product product = make(a(ProductBuilder.defaultProduct));
    productMapper.insert(product);

    Program program = make(a(ProgramBuilder.defaultProgram));
    programMapper.insert(program);

    ProductCategory category = new ProductCategory("C1", "Category 1", 1);
    productCategoryMapper.insert(category);

    ProgramProduct programProduct =
        new ProgramProduct(program, product, 30, true, new Money("12.5"));
    programProduct.setProductCategory(category);
    programProductMapper.insert(programProduct);

    Facility facility = make(a(FacilityBuilder.defaultFacility));
    facilityMapper.insert(facility);

    ProcessingSchedule processingSchedule =
        make(a(ProcessingScheduleBuilder.defaultProcessingSchedule));
    processingScheduleMapper.insert(processingSchedule);

    ProcessingPeriod processingPeriod =
        make(a(defaultProcessingPeriod, with(scheduleId, processingSchedule.getId())));
    processingPeriodMapper.insert(processingPeriod);

    requisition = new Rnr(facility, new Program(HIV), processingPeriod, false, MODIFIED_BY, 1L);
    requisition.setStatus(INITIATED);
    requisitionMapper.insert(requisition);

    user = new User();
    user.setId(MODIFIED_BY);
  }
  @Test
  public void shouldGetProgramProductIdByProgramAndProductId() {
    when(programProductMapper.getIdByProgramAndProductId(1L, 2L)).thenReturn(3L);

    assertThat(programProductRepository.getIdByProgramIdAndProductId(1L, 2L), is(3L));
    verify(programProductMapper).getIdByProgramAndProductId(1L, 2L);
  }
  @Test
  public void shouldGetProgramProductsByProgram() {
    Program program = new Program();
    List<ProgramProduct> expectedProgramProducts = new ArrayList<>();
    when(programProductMapper.getByProgram(program)).thenReturn(expectedProgramProducts);

    List<ProgramProduct> programProducts = programProductRepository.getByProgram(program);

    verify(programProductMapper).getByProgram(program);
    assertThat(programProducts, is(expectedProgramProducts));
  }
  @Before
  public void setUp() throws Exception {
    programProductRepository =
        new ProgramProductRepository(
            programRepository, programProductMapper, productRepository, programProductPriceMapper);
    programProduct = make(a(ProgramProductBuilder.defaultProgramProduct));
    programProduct.setModifiedDate(new Date());

    when(productRepository.getIdByCode("productCode")).thenReturn(1L);

    when(programProductMapper.getByProgramAndProductId(anyLong(), anyLong()))
        .thenReturn(programProduct);
  }
  @Test
  public void shouldInsertProgramForAProduct() {
    Program program = new Program();
    program.setCode("P1");
    Product product = new Product();
    product.setCode("P2");
    ProgramProduct programProduct = new ProgramProduct(program, product, 10, true);
    programProduct.setModifiedDate(new Date());

    when(programProductMapper.getByProgramAndProductId(anyLong(), anyLong())).thenReturn(null);

    programProductRepository.save(programProduct);
    verify(programProductMapper).insert(programProduct);
  }
  @Test
  public void shouldGetProgramProductByProgramAndProductCodes() throws Exception {
    ProgramProduct programProduct = make(a(ProgramProductBuilder.defaultProgramProduct));

    final Long programId = 123L;
    when(programRepository.getIdByCode(PROGRAM_CODE)).thenReturn(programId);
    final Long productId = 12L;
    when(productRepository.getIdByCode(PRODUCT_CODE)).thenReturn(productId);
    ProgramProduct expectedProgramProduct = new ProgramProduct();
    when(programProductMapper.getByProgramAndProductId(programId, productId))
        .thenReturn(expectedProgramProduct);

    ProgramProduct result = programProductRepository.getByProgramAndProductCode(programProduct);
    verify(programRepository).getIdByCode(PROGRAM_CODE);
    verify(productRepository).getIdByCode(PRODUCT_CODE);
    verify(programProductMapper).getByProgramAndProductId(programId, productId);

    assertThat(result, is(expectedProgramProduct));
  }