@Test public void shouldHandlerTransactionNotification() throws Exception { when(httpServletRequest.getParameter("notificationCode")).thenReturn("code"); when(httpServletRequest.getParameter("notificationType")).thenReturn("transaction"); notificationsResource.handle(httpServletRequest, handler); InOrder inOrder = inOrder(httpServletRequest, handler); inOrder.verify(httpServletRequest, times(1)).getParameter("notificationCode"); inOrder.verify(httpServletRequest, times(2)).getParameter("notificationType"); inOrder.verify(handler, times(1)).handleTransactionNotification(any(TransactionDetail.class)); inOrder.verify(handler, times(0)).handleAuthorizationNotification(any(AuthorizationDetail.class)); inOrder.verify(handler, times(0)).handlePreApprovalNotification(any(PreApprovalDetail.class)); }
public void handle(HttpServletRequest request, PagSeguroNotificationHandler handle) { LOGGER.info("Iniciando handler de notificacoes"); if (request.getParameter("notificationCode").isEmpty() || request.getParameter("notificationType").isEmpty()) { throw new PagSeguroLibException(new IllegalArgumentException("Notification code or " + "notification type not exists")); } NotificationType notificationType = NotificationType.fromName(request.getParameter("notificationType")); switch (notificationType) { case TRANSACTION: LOGGER.info("Notificacao de transacao"); handle.handleTransactionNotification(pagSeguro.transactions().search() .byNotificationCode(request.getParameter("notificationCode"))); break; case APPLICATION_AUTHORIZATION: LOGGER.info("Notificacao de autorizcao"); handle.handleAuthorizationNotification(pagSeguro.authorizations().search() .byNotificationCode(request.getParameter("notificationCode"))); break; case PRE_APPROVAL: LOGGER.info("Notificacao de assinatura"); handle.handlePreApprovalNotification(pagSeguro.preApprovals().search() .byNotificationCode(request.getParameter("notificationCode"))); break; default: throw new PagSeguroLibException(new IllegalArgumentException("Notification not exists")); } LOGGER.info("Handler de notificacoes finalizado"); }
NotificationsResource { public void handle(HttpServletRequest request, PagSeguroNotificationHandler handle) { LOGGER.info("Iniciando handler de notificacoes"); if (request.getParameter("notificationCode").isEmpty() || request.getParameter("notificationType").isEmpty()) { throw new PagSeguroLibException(new IllegalArgumentException("Notification code or " + "notification type not exists")); } NotificationType notificationType = NotificationType.fromName(request.getParameter("notificationType")); switch (notificationType) { case TRANSACTION: LOGGER.info("Notificacao de transacao"); handle.handleTransactionNotification(pagSeguro.transactions().search() .byNotificationCode(request.getParameter("notificationCode"))); break; case APPLICATION_AUTHORIZATION: LOGGER.info("Notificacao de autorizcao"); handle.handleAuthorizationNotification(pagSeguro.authorizations().search() .byNotificationCode(request.getParameter("notificationCode"))); break; case PRE_APPROVAL: LOGGER.info("Notificacao de assinatura"); handle.handlePreApprovalNotification(pagSeguro.preApprovals().search() .byNotificationCode(request.getParameter("notificationCode"))); break; default: throw new PagSeguroLibException(new IllegalArgumentException("Notification not exists")); } LOGGER.info("Handler de notificacoes finalizado"); } }
NotificationsResource { public void handle(HttpServletRequest request, PagSeguroNotificationHandler handle) { LOGGER.info("Iniciando handler de notificacoes"); if (request.getParameter("notificationCode").isEmpty() || request.getParameter("notificationType").isEmpty()) { throw new PagSeguroLibException(new IllegalArgumentException("Notification code or " + "notification type not exists")); } NotificationType notificationType = NotificationType.fromName(request.getParameter("notificationType")); switch (notificationType) { case TRANSACTION: LOGGER.info("Notificacao de transacao"); handle.handleTransactionNotification(pagSeguro.transactions().search() .byNotificationCode(request.getParameter("notificationCode"))); break; case APPLICATION_AUTHORIZATION: LOGGER.info("Notificacao de autorizcao"); handle.handleAuthorizationNotification(pagSeguro.authorizations().search() .byNotificationCode(request.getParameter("notificationCode"))); break; case PRE_APPROVAL: LOGGER.info("Notificacao de assinatura"); handle.handlePreApprovalNotification(pagSeguro.preApprovals().search() .byNotificationCode(request.getParameter("notificationCode"))); break; default: throw new PagSeguroLibException(new IllegalArgumentException("Notification not exists")); } LOGGER.info("Handler de notificacoes finalizado"); } NotificationsResource(PagSeguro pagSeguro, HttpClient httpClient); }
NotificationsResource { public void handle(HttpServletRequest request, PagSeguroNotificationHandler handle) { LOGGER.info("Iniciando handler de notificacoes"); if (request.getParameter("notificationCode").isEmpty() || request.getParameter("notificationType").isEmpty()) { throw new PagSeguroLibException(new IllegalArgumentException("Notification code or " + "notification type not exists")); } NotificationType notificationType = NotificationType.fromName(request.getParameter("notificationType")); switch (notificationType) { case TRANSACTION: LOGGER.info("Notificacao de transacao"); handle.handleTransactionNotification(pagSeguro.transactions().search() .byNotificationCode(request.getParameter("notificationCode"))); break; case APPLICATION_AUTHORIZATION: LOGGER.info("Notificacao de autorizcao"); handle.handleAuthorizationNotification(pagSeguro.authorizations().search() .byNotificationCode(request.getParameter("notificationCode"))); break; case PRE_APPROVAL: LOGGER.info("Notificacao de assinatura"); handle.handlePreApprovalNotification(pagSeguro.preApprovals().search() .byNotificationCode(request.getParameter("notificationCode"))); break; default: throw new PagSeguroLibException(new IllegalArgumentException("Notification not exists")); } LOGGER.info("Handler de notificacoes finalizado"); } NotificationsResource(PagSeguro pagSeguro, HttpClient httpClient); void handle(HttpServletRequest request, PagSeguroNotificationHandler handle); }
NotificationsResource { public void handle(HttpServletRequest request, PagSeguroNotificationHandler handle) { LOGGER.info("Iniciando handler de notificacoes"); if (request.getParameter("notificationCode").isEmpty() || request.getParameter("notificationType").isEmpty()) { throw new PagSeguroLibException(new IllegalArgumentException("Notification code or " + "notification type not exists")); } NotificationType notificationType = NotificationType.fromName(request.getParameter("notificationType")); switch (notificationType) { case TRANSACTION: LOGGER.info("Notificacao de transacao"); handle.handleTransactionNotification(pagSeguro.transactions().search() .byNotificationCode(request.getParameter("notificationCode"))); break; case APPLICATION_AUTHORIZATION: LOGGER.info("Notificacao de autorizcao"); handle.handleAuthorizationNotification(pagSeguro.authorizations().search() .byNotificationCode(request.getParameter("notificationCode"))); break; case PRE_APPROVAL: LOGGER.info("Notificacao de assinatura"); handle.handlePreApprovalNotification(pagSeguro.preApprovals().search() .byNotificationCode(request.getParameter("notificationCode"))); break; default: throw new PagSeguroLibException(new IllegalArgumentException("Notification not exists")); } LOGGER.info("Handler de notificacoes finalizado"); } NotificationsResource(PagSeguro pagSeguro, HttpClient httpClient); void handle(HttpServletRequest request, PagSeguroNotificationHandler handle);  }