@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 shouldNotInsertDuplicatePeriodName() throws Exception { ProcessingSchedule schedule2 = make(a(defaultProcessingSchedule, with(code, "XXX"))); scheduleMapper.insert(schedule2); ProcessingPeriod period1 = make(a(defaultProcessingPeriod, with(scheduleId, schedule.getId()), with(name, "Month1"))); ProcessingPeriod period2 = make(a(defaultProcessingPeriod, with(scheduleId, schedule2.getId()), with(name, "Month1"))); ProcessingPeriod period3 = make(a(defaultProcessingPeriod, with(scheduleId, schedule2.getId()), with(name, "Month1"))); expectedException.expect(DuplicateKeyException.class); expectedException.expectMessage("duplicate key value violates unique constraint"); mapper.insert(period1); mapper.insert(period2); mapper.insert(period3); }
@Before public void setUp() throws Exception { schedule = make(a(defaultProcessingSchedule)); scheduleMapper.insert(schedule); }