@Test public void test() { mockery.checking(new Expectations() { { allowing(principalPopulator).getPrincipal(with(any(String.class)), with(any(String.class))); will(returnValue(principal)); allowing(serviceActionController).execute(with(new EasyMatcher<PrincipalActionContext>() { @Override protected boolean isMatch(final PrincipalActionContext inTestObject) { return (Long) inTestObject.getParams() == PERSON_ID && inTestObject.getPrincipal() == principal; } }), with(same(getPersonAction))); will(returnValue(person)); allowing(serviceActionController).execute(with(new EasyMatcher<PrincipalActionContext>() { @Override protected boolean isMatch(final PrincipalActionContext inTestObject) { if (inTestObject.getParams() instanceof EntityIdentifier) { EntityIdentifier rqst = (EntityIdentifier) inTestObject.getParams(); return rqst.getType() == EntityType.PERSON && rqst.getId() == PERSON_ID && inTestObject.getPrincipal() == principal; } return false; } }), with(same(getTokenForStreamAction))); will(returnValue(ADDRESS)); allowing(person).getUniqueId(); will(returnValue("personid")); oneOf(response).setHeader("Content-Disposition", "attachment; filename=person-personid.vcf"); oneOf(response).setHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0"); oneOf(response).addHeader("Pragma", "no-cache"); } }); ModelAndView result = sut.getStreamContact(EntityType.PERSON, PERSON_ID, response); mockery.assertIsSatisfied(); assertEquals("vcardView", result.getViewName()); assertSame(person, result.getModel().get("streamEntity")); assertEquals(ADDRESS, result.getModel().get("email")); }
@RequestMapping(value = "stream", method = RequestMethod.GET) public ModelAndView getStreamContact(@RequestParam("type") final EntityType streamType, @RequestParam("id") final long id, final HttpServletResponse response) { Principal principal = principalPopulator.getPrincipal(null, null); ServiceAction action = typeToFetchActionIndex.get(streamType); if (action == null) { throw new ExecutionException("Stream type not supported."); } Identifiable entity = (Identifiable) serviceActionController.execute(new ServiceActionContext(id, principal), action); String address = (String) serviceActionController.execute(new ServiceActionContext(new EntityIdentifier( streamType, id), principal), getTokenForStreamAction); ModelAndView mv = new ModelAndView("vcardView"); mv.addObject("streamEntity", entity); mv.addObject("email", address); response.setHeader("Content-Disposition", "attachment; filename=" + streamType.name().toLowerCase() + "-" + entity.getUniqueId() + ".vcf"); response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0"); response.addHeader("Pragma", "no-cache"); return mv; }
EmailContactController { @RequestMapping(value = "stream", method = RequestMethod.GET) public ModelAndView getStreamContact(@RequestParam("type") final EntityType streamType, @RequestParam("id") final long id, final HttpServletResponse response) { Principal principal = principalPopulator.getPrincipal(null, null); ServiceAction action = typeToFetchActionIndex.get(streamType); if (action == null) { throw new ExecutionException("Stream type not supported."); } Identifiable entity = (Identifiable) serviceActionController.execute(new ServiceActionContext(id, principal), action); String address = (String) serviceActionController.execute(new ServiceActionContext(new EntityIdentifier( streamType, id), principal), getTokenForStreamAction); ModelAndView mv = new ModelAndView("vcardView"); mv.addObject("streamEntity", entity); mv.addObject("email", address); response.setHeader("Content-Disposition", "attachment; filename=" + streamType.name().toLowerCase() + "-" + entity.getUniqueId() + ".vcf"); response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0"); response.addHeader("Pragma", "no-cache"); return mv; } }
EmailContactController { @RequestMapping(value = "stream", method = RequestMethod.GET) public ModelAndView getStreamContact(@RequestParam("type") final EntityType streamType, @RequestParam("id") final long id, final HttpServletResponse response) { Principal principal = principalPopulator.getPrincipal(null, null); ServiceAction action = typeToFetchActionIndex.get(streamType); if (action == null) { throw new ExecutionException("Stream type not supported."); } Identifiable entity = (Identifiable) serviceActionController.execute(new ServiceActionContext(id, principal), action); String address = (String) serviceActionController.execute(new ServiceActionContext(new EntityIdentifier( streamType, id), principal), getTokenForStreamAction); ModelAndView mv = new ModelAndView("vcardView"); mv.addObject("streamEntity", entity); mv.addObject("email", address); response.setHeader("Content-Disposition", "attachment; filename=" + streamType.name().toLowerCase() + "-" + entity.getUniqueId() + ".vcf"); response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0"); response.addHeader("Pragma", "no-cache"); return mv; } EmailContactController(final ActionController inServiceActionController,
            final PrincipalPopulator inPrincipalPopulator,
            final Map<EntityType, ServiceAction> inTypeToFetchActionIndex,
            final ServiceAction inGetTokenForStreamAction); }
EmailContactController { @RequestMapping(value = "stream", method = RequestMethod.GET) public ModelAndView getStreamContact(@RequestParam("type") final EntityType streamType, @RequestParam("id") final long id, final HttpServletResponse response) { Principal principal = principalPopulator.getPrincipal(null, null); ServiceAction action = typeToFetchActionIndex.get(streamType); if (action == null) { throw new ExecutionException("Stream type not supported."); } Identifiable entity = (Identifiable) serviceActionController.execute(new ServiceActionContext(id, principal), action); String address = (String) serviceActionController.execute(new ServiceActionContext(new EntityIdentifier( streamType, id), principal), getTokenForStreamAction); ModelAndView mv = new ModelAndView("vcardView"); mv.addObject("streamEntity", entity); mv.addObject("email", address); response.setHeader("Content-Disposition", "attachment; filename=" + streamType.name().toLowerCase() + "-" + entity.getUniqueId() + ".vcf"); response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0"); response.addHeader("Pragma", "no-cache"); return mv; } EmailContactController(final ActionController inServiceActionController,
            final PrincipalPopulator inPrincipalPopulator,
            final Map<EntityType, ServiceAction> inTypeToFetchActionIndex,
            final ServiceAction inGetTokenForStreamAction); @RequestMapping(value = "stream", method = RequestMethod.GET) ModelAndView getStreamContact(@RequestParam("type") final EntityType streamType,
            @RequestParam("id") final long id, final HttpServletResponse response); }
EmailContactController { @RequestMapping(value = "stream", method = RequestMethod.GET) public ModelAndView getStreamContact(@RequestParam("type") final EntityType streamType, @RequestParam("id") final long id, final HttpServletResponse response) { Principal principal = principalPopulator.getPrincipal(null, null); ServiceAction action = typeToFetchActionIndex.get(streamType); if (action == null) { throw new ExecutionException("Stream type not supported."); } Identifiable entity = (Identifiable) serviceActionController.execute(new ServiceActionContext(id, principal), action); String address = (String) serviceActionController.execute(new ServiceActionContext(new EntityIdentifier( streamType, id), principal), getTokenForStreamAction); ModelAndView mv = new ModelAndView("vcardView"); mv.addObject("streamEntity", entity); mv.addObject("email", address); response.setHeader("Content-Disposition", "attachment; filename=" + streamType.name().toLowerCase() + "-" + entity.getUniqueId() + ".vcf"); response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0"); response.addHeader("Pragma", "no-cache"); return mv; } EmailContactController(final ActionController inServiceActionController,
            final PrincipalPopulator inPrincipalPopulator,
            final Map<EntityType, ServiceAction> inTypeToFetchActionIndex,
            final ServiceAction inGetTokenForStreamAction); @RequestMapping(value = "stream", method = RequestMethod.GET) ModelAndView getStreamContact(@RequestParam("type") final EntityType streamType,
            @RequestParam("id") final long id, final HttpServletResponse response);  }