@Test public void returnsTheCanvassCard() throws Exception { User user = mock(User.class); Ward ward = ward().withWardCode("code").build(); byte[] pdfContent = "content".getBytes(); given(wardService.getByCode(ward.getCode(), user)).willReturn(Try.success(ward)); given(pdfClient.requestCanvassCard(any())).willReturn(Try.success(pdfContent)); ElectorsByStreetsRequest request = streetsRequest(); Try<byte[]> canvassCard = underTest.generateCanvassCard(request, ward.getCode(), user); assertThat(canvassCard.get(), is(pdfContent)); }
public Try<byte[]> generateCanvassCard(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(), null, requestInfo); return pdfServerClient.requestCanvassCard(generatePdfRequest); }).map(content -> { int streets = request.getStreets().size(); log.info("User={} generated canvass card for ward={}, numStreets={}", user, wardCode, streets); auditor.audit(createCanvassCard(wardCode, user.getUsername(), String.valueOf(streets))); return content; }); }
CanvassCardService { public Try<byte[]> generateCanvassCard(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(), null, requestInfo); return pdfServerClient.requestCanvassCard(generatePdfRequest); }).map(content -> { int streets = request.getStreets().size(); log.info("User={} generated canvass card for ward={}, numStreets={}", user, wardCode, streets); auditor.audit(createCanvassCard(wardCode, user.getUsername(), String.valueOf(streets))); return content; }); } }
CanvassCardService { public Try<byte[]> generateCanvassCard(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(), null, requestInfo); return pdfServerClient.requestCanvassCard(generatePdfRequest); }).map(content -> { int streets = request.getStreets().size(); log.info("User={} generated canvass card for ward={}, numStreets={}", user, wardCode, streets); auditor.audit(createCanvassCard(wardCode, user.getUsername(), String.valueOf(streets))); return content; }); } @Autowired  CanvassCardService(WardService wardService, PdfClient pdfServerClient, Auditor auditor); }
CanvassCardService { public Try<byte[]> generateCanvassCard(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(), null, requestInfo); return pdfServerClient.requestCanvassCard(generatePdfRequest); }).map(content -> { int streets = request.getStreets().size(); log.info("User={} generated canvass card for ward={}, numStreets={}", user, wardCode, streets); auditor.audit(createCanvassCard(wardCode, user.getUsername(), String.valueOf(streets))); return content; }); } @Autowired  CanvassCardService(WardService wardService, PdfClient pdfServerClient, Auditor auditor); Try<byte[]> generateCanvassCard(ElectorsByStreetsRequest request, String wardCode, User user); }
CanvassCardService { public Try<byte[]> generateCanvassCard(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(), null, requestInfo); return pdfServerClient.requestCanvassCard(generatePdfRequest); }).map(content -> { int streets = request.getStreets().size(); log.info("User={} generated canvass card for ward={}, numStreets={}", user, wardCode, streets); auditor.audit(createCanvassCard(wardCode, user.getUsername(), String.valueOf(streets))); return content; }); } @Autowired  CanvassCardService(WardService wardService, PdfClient pdfServerClient, Auditor auditor); Try<byte[]> generateCanvassCard(ElectorsByStreetsRequest request, String wardCode, User user);  }