@Test public void generatesTheAddressLabels() throws Exception { String wardCode = "E05000403"; String wardName = "Canbury"; String constituencyName = "Richmond Park"; User user = user().build(); ArgumentCaptor<GeneratePdfRequest> pdfRequestCaptor = ArgumentCaptor.forClass(GeneratePdfRequest.class); Flags flags = flags().build(); ElectorsByStreetsRequest request = new ElectorsByStreetsRequest( singletonList(new StreetRequest("mainStreet", "postTown", "dependentStreet", "dependentLocality")), flags); Ward ward = ward().withWardName(wardName).withWardCode(wardCode).withConstituency(constituency().withName(constituencyName).build()).build(); given(wardService.getByCode(wardCode, user)).willReturn(Try.success(ward)); when(pdfClient.requestAddressLabels(pdfRequestCaptor.capture())).thenReturn(Try.success("content".getBytes())); Try<byte[]> labels = underTest.generateAddressLabelsForPostalVoters(request, wardCode, user); assertThat(labels.get(), is("content".getBytes())); assertThat(labels.isSuccess(), is(true)); GeneratePdfRequest pdfRequest = pdfRequestCaptor.getValue(); assertThat(pdfRequest.getFlags(), is(flags)); assertThat(pdfRequest.getInfo().getWardCode(), is(wardCode)); assertThat(pdfRequest.getInfo().getWardName(), is(wardName)); assertThat(pdfRequest.getInfo().getConstituencyName(), is(constituencyName)); }
public Try<byte[]> generateAddressLabelsForPostalVoters(ElectorsByStreetsRequest request, String wardCode, User user) { return wardService.getByCode(wardCode, user) .flatMap(ward -> { RequestInfo requestInfo = new RequestInfo(wardCode, ward.getName(), ward.getConstituency().getName()); GeneratePdfRequest generatePdfRequest = new GeneratePdfRequest(request.getStreets(), request.getFlags(), requestInfo); return pdfServerClient.requestAddressLabels(generatePdfRequest); }).map(content -> { log.info("User={} generated address labels for GOTPV. ward={}", user, wardCode); return content; }); }
LabelService { public Try<byte[]> generateAddressLabelsForPostalVoters(ElectorsByStreetsRequest request, String wardCode, User user) { return wardService.getByCode(wardCode, user) .flatMap(ward -> { RequestInfo requestInfo = new RequestInfo(wardCode, ward.getName(), ward.getConstituency().getName()); GeneratePdfRequest generatePdfRequest = new GeneratePdfRequest(request.getStreets(), request.getFlags(), requestInfo); return pdfServerClient.requestAddressLabels(generatePdfRequest); }).map(content -> { log.info("User={} generated address labels for GOTPV. ward={}", user, wardCode); return content; }); } }
LabelService { public Try<byte[]> generateAddressLabelsForPostalVoters(ElectorsByStreetsRequest request, String wardCode, User user) { return wardService.getByCode(wardCode, user) .flatMap(ward -> { RequestInfo requestInfo = new RequestInfo(wardCode, ward.getName(), ward.getConstituency().getName()); GeneratePdfRequest generatePdfRequest = new GeneratePdfRequest(request.getStreets(), request.getFlags(), requestInfo); return pdfServerClient.requestAddressLabels(generatePdfRequest); }).map(content -> { log.info("User={} generated address labels for GOTPV. ward={}", user, wardCode); return content; }); } @Autowired  LabelService(WardService wardService,
                        PdfClient pdfServerClient); }
LabelService { public Try<byte[]> generateAddressLabelsForPostalVoters(ElectorsByStreetsRequest request, String wardCode, User user) { return wardService.getByCode(wardCode, user) .flatMap(ward -> { RequestInfo requestInfo = new RequestInfo(wardCode, ward.getName(), ward.getConstituency().getName()); GeneratePdfRequest generatePdfRequest = new GeneratePdfRequest(request.getStreets(), request.getFlags(), requestInfo); return pdfServerClient.requestAddressLabels(generatePdfRequest); }).map(content -> { log.info("User={} generated address labels for GOTPV. ward={}", user, wardCode); return content; }); } @Autowired  LabelService(WardService wardService,
                        PdfClient pdfServerClient); Try<byte[]> generateAddressLabelsForPostalVoters(ElectorsByStreetsRequest request,
                                                            String wardCode,
                                                            User user); }
LabelService { public Try<byte[]> generateAddressLabelsForPostalVoters(ElectorsByStreetsRequest request, String wardCode, User user) { return wardService.getByCode(wardCode, user) .flatMap(ward -> { RequestInfo requestInfo = new RequestInfo(wardCode, ward.getName(), ward.getConstituency().getName()); GeneratePdfRequest generatePdfRequest = new GeneratePdfRequest(request.getStreets(), request.getFlags(), requestInfo); return pdfServerClient.requestAddressLabels(generatePdfRequest); }).map(content -> { log.info("User={} generated address labels for GOTPV. ward={}", user, wardCode); return content; }); } @Autowired  LabelService(WardService wardService,
                        PdfClient pdfServerClient); Try<byte[]> generateAddressLabelsForPostalVoters(ElectorsByStreetsRequest request,
                                                            String wardCode,
                                                            User user);  }