@Test public void signTask_exception() throws Exception { Long objectId = 500L; String objectType = "TASK"; String ipAddress = "ipAddress"; String password = "password"; String userName = "userName"; Signature foundSignature = new Signature(); foundSignature.setObjectId(objectId); Capture<Signature> signatureToSave = new Capture<>(); Capture<ApplicationSignatureEvent> capturedEvent = new Capture<>(); mockHttpSession.setAttribute("acm_ip_address", ipAddress); expect(mockLdapAuthenticateManager.authenticate(userName, password)).andReturn(true); expect(mockSignatureDao.save(capture(signatureToSave))).andThrow(new RuntimeException("testException")); mockSignatureEventPublisher.publishSignatureEvent(capture(capturedEvent)); expect(mockAuthentication.getName()).andReturn(userName).atLeastOnce(); replayAll(); MvcResult result = mockMvc .perform( post("/api/v1/plugin/signature/confirm/{objectType}/{objectId}", objectType, objectId) .content("{\"confirmPassword\":\"password\"}") .contentType( MediaType.APPLICATION_JSON_VALUE) .session(mockHttpSession) .principal(mockAuthentication)) .andReturn(); verifyAll(); ApplicationSignatureEvent event = capturedEvent.getValue(); assertEquals(objectId, event.getParentObjectId()); assertEquals(objectType, event.getParentObjectType()); assertFalse(event.isSucceeded()); }
protected void publishSignatureEvent( Authentication authentication, HttpSession httpSession, Signature signed, boolean succeeded) { String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); ApplicationSignatureEvent event = new ApplicationSignatureEvent(signed, String.format("%s.%s", "com.armedia.acm.app.signature.signed", signed.getObjectType().toLowerCase()), succeeded, ipAddress); log.debug("Sign event type: [{}]", event.getEventType()); getSignatureEventPublisher().publishSignatureEvent(event); }
SignatureAPIController { protected void publishSignatureEvent( Authentication authentication, HttpSession httpSession, Signature signed, boolean succeeded) { String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); ApplicationSignatureEvent event = new ApplicationSignatureEvent(signed, String.format("%s.%s", "com.armedia.acm.app.signature.signed", signed.getObjectType().toLowerCase()), succeeded, ipAddress); log.debug("Sign event type: [{}]", event.getEventType()); getSignatureEventPublisher().publishSignatureEvent(event); } }
SignatureAPIController { protected void publishSignatureEvent( Authentication authentication, HttpSession httpSession, Signature signed, boolean succeeded) { String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); ApplicationSignatureEvent event = new ApplicationSignatureEvent(signed, String.format("%s.%s", "com.armedia.acm.app.signature.signed", signed.getObjectType().toLowerCase()), succeeded, ipAddress); log.debug("Sign event type: [{}]", event.getEventType()); getSignatureEventPublisher().publishSignatureEvent(event); }  }
SignatureAPIController { protected void publishSignatureEvent( Authentication authentication, HttpSession httpSession, Signature signed, boolean succeeded) { String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); ApplicationSignatureEvent event = new ApplicationSignatureEvent(signed, String.format("%s.%s", "com.armedia.acm.app.signature.signed", signed.getObjectType().toLowerCase()), succeeded, ipAddress); log.debug("Sign event type: [{}]", event.getEventType()); getSignatureEventPublisher().publishSignatureEvent(event); }  @RequestMapping(value = "/confirm/{objectType}/{objectId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody Signature signObject(
            @PathVariable("objectType") String objectType,
            @PathVariable("objectId") Long objectId,
            @RequestBody Map<String, String> body,
            Authentication authentication,
            HttpSession httpSession); SignatureDao getSignatureDao(); void setSignatureDao(SignatureDao signatureDao); SignatureEventPublisher getSignatureEventPublisher(); void setSignatureEventPublisher(
            SignatureEventPublisher signatureEventPublisher); LdapAuthenticateManager getLdapAuthenticateManager(); void setLdapAuthenticateManager(
            LdapAuthenticateManager ldapAuthenticateManager); }
SignatureAPIController { protected void publishSignatureEvent( Authentication authentication, HttpSession httpSession, Signature signed, boolean succeeded) { String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); ApplicationSignatureEvent event = new ApplicationSignatureEvent(signed, String.format("%s.%s", "com.armedia.acm.app.signature.signed", signed.getObjectType().toLowerCase()), succeeded, ipAddress); log.debug("Sign event type: [{}]", event.getEventType()); getSignatureEventPublisher().publishSignatureEvent(event); }  @RequestMapping(value = "/confirm/{objectType}/{objectId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody Signature signObject(
            @PathVariable("objectType") String objectType,
            @PathVariable("objectId") Long objectId,
            @RequestBody Map<String, String> body,
            Authentication authentication,
            HttpSession httpSession); SignatureDao getSignatureDao(); void setSignatureDao(SignatureDao signatureDao); SignatureEventPublisher getSignatureEventPublisher(); void setSignatureEventPublisher(
            SignatureEventPublisher signatureEventPublisher); LdapAuthenticateManager getLdapAuthenticateManager(); void setLdapAuthenticateManager(
            LdapAuthenticateManager ldapAuthenticateManager);  }