RegisterController { @RequestMapping(method = GET, value = "/registers/fp") @ResponseBody public ResponseEntity<FPRegisterDTO> fpRegister(@RequestParam("anm-id") String anmIdentifier) { FPRegister fpRegister = fpRegisterService.getRegisterForANM(anmIdentifier); return new ResponseEntity<>(fpRegisterMapper.mapToDTO(fpRegister), HttpStatus.OK); } @Autowired  RegisterController(ANCRegisterService ancRegisterService,
                              PNCRegisterService pncRegisterService,
                              ECRegisterService ecRegisterService,
                              ChildRegisterService childRegisterService,
                              FPRegisterService fpRegisterService,
                              ANCRegisterMapper ancRegisterMapper,
                              ECRegisterMapper ecRegisterMapper,
                              ChildRegisterMapper childRegisterMapper,
                              FPRegisterMapper fpRegisterMapper,
                              PNCRegisterMapper pncRegisterMapper); @RequestMapping(method = GET, value = "/registers/ec") @ResponseBody ResponseEntity<ECRegisterDTO> ecRegister(@RequestParam("anm-id") String anmIdentifier); @RequestMapping(method = GET, value = "/registers/anc") @ResponseBody ResponseEntity<ANCRegisterDTO> ancRegister(@RequestParam("anm-id") String anmIdentifier); @RequestMapping(method = GET, value = "/registers/child") @ResponseBody ResponseEntity<ChildRegisterDTO> childRegister(@RequestParam("anm-id") String anmIdentifier); @RequestMapping(method = GET, value = "/registers/fp") @ResponseBody ResponseEntity<FPRegisterDTO> fpRegister(@RequestParam("anm-id") String anmIdentifier); @RequestMapping(method = GET, value = "/registers/pnc") @ResponseBody ResponseEntity<PNCRegisterDTO> pncRegister(@RequestParam("anm-id") String anmIdentifier);  }
@Test public void shouldGetFPRegisterForGivenANM() throws Exception { IUDRegisterEntry iudRegisterEntry = new IUDRegisterEntry() .withEcNumber("90") .withWifeName("Saranya") .withHusbandName("Manjunatha") .withVillage("hosa_agrahara") .withSubCenter("hosa_agrahara") .withWifeAge("27") .withHusbandAge("38") .withCaste("c_others") .withReligion("Hindu") .withNumberOfLivingMaleChildren("1") .withNumberOfLivingFemaleChildren("1") .withWifeEducationLevel("illiterate") .withHusbandEducationLevel("illiterate") .withFpDetails(new IUDFPDetails("2014-02-23", "district hospital", "2014-05-12", "positive")); Map<String, String> refill1 = create("date", "2014-10-02") .put("pieces", "10") .map(); Map<String, String> refill2 = create("date", "2014-10-12") .put("pieces", "10") .map(); CondomRegisterEntry condomRegisterEntry = new CondomRegisterEntry() .withEcNumber("90") .withWifeName("Saranya") .withHusbandName("Manjunatha") .withVillage("hosa_agrahara") .withSubCenter("hosa_agrahara") .withWifeAge("27") .withCaste("c_others") .withReligion("Hindu") .withNumberOfLivingMaleChildren("1") .withNumberOfLivingFemaleChildren("1") .withWifeEducationLevel("illiterate") .withHusbandEducationLevel("illiterate") .withFpDetails(new CondomFPDetails("2014-02-23", asList(refill1, refill2))); Map<String, String> refill3 = create("date", "2014-10-22") .put("pieces", "10") .map(); Map<String, String> refill4 = create("date", "2014-10-24") .put("pieces", "10") .map(); OCPRegisterEntry ocpRegisterEntry = new OCPRegisterEntry() .withEcNumber("90") .withWifeName("Saranya") .withHusbandName("Manjunatha") .withVillage("hosa_agrahara") .withSubCenter("hosa_agrahara") .withWifeAge("27") .withCaste("c_others") .withReligion("Hindu") .withNumberOfLivingMaleChildren("1") .withNumberOfLivingFemaleChildren("1") .withWifeEducationLevel("illiterate") .withHusbandEducationLevel("illiterate") .withFpDetails(new OCPFPDetails("2014-02-23", asList(refill1, refill2, refill3, refill4), null, null)); MaleSterilizationRegisterEntry maleSterilizationRegisterEntry = new MaleSterilizationRegisterEntry() .withEcNumber("90") .withWifeName("Saranya") .withHusbandName("Manjunatha") .withVillage("hosa_agrahara") .withSubCenter("hosa_agrahara") .withWifeAge("27") .withHusbandAge("30") .withCaste("c_others") .withReligion("Hindu") .withNumberOfLivingMaleChildren("1") .withNumberOfLivingFemaleChildren("1") .withWifeEducationLevel("illiterate") .withHusbandEducationLevel("illiterate") .withFpDetails(new MaleSterilizationFPDetails("nsv", "2014-05-01", asList("2014-05-06", "2014-05-10"))); FemaleSterilizationRegisterEntry femaleSterilizationRegisterEntry = new FemaleSterilizationRegisterEntry() .withEcNumber("90") .withWifeName("Saranya") .withHusbandName("Manjunatha") .withVillage("hosa_agrahara") .withSubCenter("hosa_agrahara") .withWifeAge("27") .withHusbandAge("30") .withCaste("c_others") .withReligion("Hindu") .withNumberOfLivingMaleChildren("1") .withNumberOfLivingFemaleChildren("1") .withWifeEducationLevel("illiterate") .withHusbandEducationLevel("illiterate") .withFpDetails(new FemaleSterilizationFPDetails("minilap", "2014-06-02", asList("2014-06-06", "2014-06-10", "2014-07-10" ))); FPRegister fpRegister = new FPRegister(asList(iudRegisterEntry), asList(condomRegisterEntry), asList(ocpRegisterEntry), asList(maleSterilizationRegisterEntry), asList(femaleSterilizationRegisterEntry), 2014); IUDRegisterEntryDTO iudRegisterEntryDTO = new IUDRegisterEntryDTO() .withEcNumber("90") .withWifeName("Saranya") .withHusbandName("Manjunatha") .withVillage("hosa_agrahara") .withSubCenter("hosa_agrahara") .withWifeAge("27") .withHusbandAge("38") .withCaste("c_others") .withReligion("Hindu") .withNumberOfLivingMaleChildren("1") .withNumberOfLivingFemaleChildren("1") .withLmpDate("2014-05-12") .withUptResult("positive") .withWifeEducationLevel("illiterate") .withHusbandEducationLevel("illiterate") .withFpDetails(new IUDFPDetailsDTO("2014-02-23", "district hospital", "2014-05-12", "positive")); CondomRegisterEntryDTO condomRegisterEntryDTO = new CondomRegisterEntryDTO() .withEcNumber("90") .withWifeName("Saranya") .withHusbandName("Manjunatha") .withVillage("hosa_agrahara") .withSubCenter("hosa_agrahara") .withWifeAge("27") .withCaste("c_others") .withReligion("Hindu") .withNumberOfLivingMaleChildren("1") .withNumberOfLivingFemaleChildren("1") .withWifeEducationLevel("illiterate") .withHusbandEducationLevel("illiterate") .withFpDetails(new CondomFPDetailsDTO("2014-02-23", asList(refill1, refill2))); OCPRegisterEntryDTO ocpRegisterEntryDTO = new OCPRegisterEntryDTO() .withEcNumber("90") .withWifeName("Saranya") .withHusbandName("Manjunatha") .withVillage("hosa_agrahara") .withSubCenter("hosa_agrahara") .withWifeAge("27") .withCaste("c_others") .withReligion("Hindu") .withNumberOfLivingMaleChildren("1") .withNumberOfLivingFemaleChildren("1") .withWifeEducationLevel("illiterate") .withHusbandEducationLevel("illiterate") .withFpDetails(new OCPFPDetailsDTO("2014-02-23", asList(refill1, refill2, refill3, refill4), null, null)); MaleSterilizationRegisterEntryDTO maleSterilizationRegisterEntryDTO = new MaleSterilizationRegisterEntryDTO() .withEcNumber("90") .withWifeName("Saranya") .withHusbandName("Manjunatha") .withVillage("hosa_agrahara") .withSubCenter("hosa_agrahara") .withWifeAge("27") .withHusbandAge("30") .withCaste("c_others") .withReligion("Hindu") .withNumberOfLivingMaleChildren("1") .withNumberOfLivingFemaleChildren("1") .withWifeEducationLevel("illiterate") .withHusbandEducationLevel("illiterate") .withFpDetails(new MaleSterilizationFPDetailsDTO("nsv", "2014-05-01", asList("2014-05-06", "2014-05-10"))); FemaleSterilizationRegisterEntryDTO femaleSterilizationRegisterEntryDTO = new FemaleSterilizationRegisterEntryDTO() .withEcNumber("90") .withWifeName("Saranya") .withHusbandName("Manjunatha") .withVillage("hosa_agrahara") .withSubCenter("hosa_agrahara") .withWifeAge("27") .withHusbandAge("30") .withCaste("c_others") .withReligion("Hindu") .withNumberOfLivingMaleChildren("1") .withNumberOfLivingFemaleChildren("1") .withWifeEducationLevel("illiterate") .withHusbandEducationLevel("illiterate") .withFpDetails(new FemaleSterilizationFPDetailsDTO("minilap", "2014-06-02", asList("2014-06-06", "2014-06-10", "2014-07-10" ))); FPRegisterDTO expectedFPRegisterDTO = new FPRegisterDTO( asList(iudRegisterEntryDTO), asList(condomRegisterEntryDTO), asList(ocpRegisterEntryDTO), asList(maleSterilizationRegisterEntryDTO), asList(femaleSterilizationRegisterEntryDTO), 2014); when(fpRegisterService.getRegisterForANM("anm1")).thenReturn(fpRegister); when(fpRegisterMapper.mapToDTO(fpRegister)).thenReturn(expectedFPRegisterDTO); ResponseEntity<FPRegisterDTO> response = controller.fpRegister("anm1"); assertEquals(expectedFPRegisterDTO, response.getBody()); assertEquals(HttpStatus.OK, response.getStatusCode()); }