Guest User

Untitled

a guest
Aug 9th, 2018
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.72 KB | None | 0 0
  1. [MIR-3740] Notifications sent to Beneficiary must use the address email from the consumer and not from The beneficiary [BNA]
  2.  
  3. ### Eclipse Workspace Patch 1.0
  4. #P batch-services
  5. Index: src/main/java/net/sxpbelux/mirage/service/batch/card/CardRequestDataProcessor.java
  6. ===================================================================
  7. --- src/main/java/net/sxpbelux/mirage/service/batch/card/CardRequestDataProcessor.java (revision 9266)
  8. +++ src/main/java/net/sxpbelux/mirage/service/batch/card/CardRequestDataProcessor.java (working copy)
  9. @@ -69,7 +69,7 @@
  10. }
  11.  
  12. if (informBeneficiaries) {
  13. - mailSenderService.sendMailToInformBeneficiaryForBlockCard(card);
  14. + mailSenderService.sendMailToInformConsumerForBlockCard(card);
  15. }
  16.  
  17. if (informClients) {
  18. @@ -90,7 +90,7 @@
  19. cardRequestItemRepository.add(cardRequestItem);
  20.  
  21. if (informBeneficiaries) {
  22. - mailSenderService.sendMailToInformBeneficiaryForPinResend(card);
  23. + mailSenderService.sendMailToInformConsumerForPinResend(card);
  24. }
  25.  
  26. if (informClients) {
  27. Index: src/test/java/net/sxpbelux/mirage/service/batch/card/CardRequestDataProcessorTest.java
  28. ===================================================================
  29. --- src/test/java/net/sxpbelux/mirage/service/batch/card/CardRequestDataProcessorTest.java (revision 8971)
  30. +++ src/test/java/net/sxpbelux/mirage/service/batch/card/CardRequestDataProcessorTest.java (working copy)
  31. @@ -102,7 +102,7 @@
  32. assertEquals(blockCardRequestData,item);
  33. assertEquals(item.getCardRequestDataState(), CardRequestDataState.IN_PROGRESS);
  34.  
  35. - verify(mailSenderService, times(1)).sendMailToInformBeneficiaryForBlockCard(card);
  36. + verify(mailSenderService, times(1)).sendMailToInformConsumerForBlockCard(card);
  37. verify(mailSenderService, times(1)).sendMailToInformClientForBlockCard(card);
  38. }
  39.  
  40. @@ -116,7 +116,7 @@
  41. assertEquals(item.getCardRequestDataState(), CardRequestDataState.IN_PROGRESS);
  42. assertEquals(item.getPinResendReason(), PinResendReason.NEVER_ARRIVED_PIN);
  43.  
  44. - verify(mailSenderService, times(1)).sendMailToInformBeneficiaryForPinResend(card);
  45. + verify(mailSenderService, times(1)).sendMailToInformConsumerForPinResend(card);
  46. verify(mailSenderService, times(1)).sendMailToInformClientForPinResend(card);
  47.  
  48.  
  49. #P domain
  50. Index: src/main/java/net/sxpbelux/mirage/domain/EmailRecipientFactory.java
  51. ===================================================================
  52. --- src/main/java/net/sxpbelux/mirage/domain/EmailRecipientFactory.java (revision 9290)
  53. +++ src/main/java/net/sxpbelux/mirage/domain/EmailRecipientFactory.java (working copy)
  54. @@ -1,8 +1,11 @@
  55. package net.sxpbelux.mirage.domain;
  56.  
  57. +import net.sxpbelux.mirage.domain.beneficiary.Beneficiary;
  58. +
  59. public interface EmailRecipientFactory {
  60.  
  61. EmailRecipient createNewEmailRecipient(String emailAddress, Language language);
  62. EmailRecipient createNewEmailRecipient(EmailAddress emailAddress, Language language);
  63. + EmailRecipient createNewEmailRecipientBasedOnConsumerFirstAndBeneficiaryAfterwards(Beneficiary beneficiary);
  64.  
  65. }
  66. \ No newline at end of file
  67. Index: src/main/java/net/sxpbelux/mirage/domain/EmailRecipientFactoryImpl.java
  68. ===================================================================
  69. --- src/main/java/net/sxpbelux/mirage/domain/EmailRecipientFactoryImpl.java (revision 9290)
  70. +++ src/main/java/net/sxpbelux/mirage/domain/EmailRecipientFactoryImpl.java (working copy)
  71. @@ -1,5 +1,8 @@
  72. package net.sxpbelux.mirage.domain;
  73.  
  74. +import net.sxpbelux.mirage.domain.beneficiary.Beneficiary;
  75. +
  76. +import org.apache.commons.lang.StringUtils;
  77. import org.springframework.stereotype.Service;
  78.  
  79. @Service
  80. @@ -15,4 +18,23 @@
  81. return new EmailRecipient(language, emailAddress);
  82. }
  83.  
  84. + @Override
  85. + public EmailRecipient createNewEmailRecipientBasedOnConsumerFirstAndBeneficiaryAfterwards (Beneficiary beneficiary) {
  86. + EmailAddress emailAddress = null;
  87. + Language language = null;
  88. + if (beneficiary.getConsumer().getEmail() != null && !StringUtils.isEmpty(beneficiary.getConsumer().getEmail().toString())) {
  89. + emailAddress = beneficiary.getConsumer ().getEmail();
  90. + }
  91. + else {
  92. + emailAddress = beneficiary.getEmail();
  93. + }
  94. + if (beneficiary.getConsumer().getLanguage() != null && !StringUtils.isEmpty(beneficiary.getConsumer().getLanguage().toString())) {
  95. + language = beneficiary.getConsumer ().getLanguage();
  96. + }
  97. + else {
  98. + language = beneficiary.getLanguage();
  99. + }
  100. + return new EmailRecipient(language, emailAddress);
  101. +
  102. + }
  103. }
  104. \ No newline at end of file
  105. Index: src/main/java/net/sxpbelux/mirage/domain/notifications/NotificationFactoryImpl.java
  106. ===================================================================
  107. --- src/main/java/net/sxpbelux/mirage/domain/notifications/NotificationFactoryImpl.java (revision 9290)
  108. +++ src/main/java/net/sxpbelux/mirage/domain/notifications/NotificationFactoryImpl.java (working copy)
  109. @@ -45,7 +45,7 @@
  110.  
  111. public static final String DATE_FORMAT_SUBJECT = "dd-MM-yyyy hh:mm:ss";
  112.  
  113. - private EmailRecipientFactory emailRecipientFactory;
  114. + private final EmailRecipientFactory emailRecipientFactory;
  115.  
  116. @Autowired public NotificationFactoryImpl(EmailRecipientFactory emailRecipientFactory){
  117. this.emailRecipientFactory = emailRecipientFactory;
  118. @@ -68,7 +68,7 @@
  119. public ProductDeliveryNotification createProductDeliveryNotification(OrderDeliveryEvent orderDeliveryEvent) {
  120. ConsumableProduct consumableProduct = orderDeliveryEvent.getProduct();
  121. Beneficiary beneficiary = consumableProduct.getBeneficiary();
  122. - EmailRecipient recipient = emailRecipientFactory.createNewEmailRecipient(beneficiary.getEmail(),beneficiary.getLanguage());
  123. + EmailRecipient recipient = emailRecipientFactory.createNewEmailRecipientBasedOnConsumerFirstAndBeneficiaryAfterwards(beneficiary);
  124. return new ProductDeliveryNotification(recipient, beneficiary.getConsumer(), orderDeliveryEvent);
  125. }
  126.  
  127. Index: src/main/java/net/sxpbelux/mirage/service/MailSenderService.java
  128. ===================================================================
  129. --- src/main/java/net/sxpbelux/mirage/service/MailSenderService.java (revision 9266)
  130. +++ src/main/java/net/sxpbelux/mirage/service/MailSenderService.java (working copy)
  131. @@ -25,8 +25,8 @@
  132. void sendMailForAccountRetrieval(List<UserContext> userContexts, EmailAddress emailTo, Language language);
  133. void sendMailForPDFEmailToClient(InputStream pdfFile, List<EmailAddress> emailAddresses, AbstractBillingDocument document);
  134. void sendMailForPDFEmailToAffiliate(InputStream pdfFile, List<EmailAddress> emailAddresses, AbstractBillingDocument document);
  135. - void sendMailToInformBeneficiaryForBlockCard(Card card);
  136. + void sendMailToInformConsumerForBlockCard(Card card);
  137. void sendMailToInformClientForBlockCard(Card card);
  138. - void sendMailToInformBeneficiaryForPinResend(Card card);
  139. + void sendMailToInformConsumerForPinResend(Card card);
  140. void sendMailToInformClientForPinResend(Card card);
  141. }
  142. \ No newline at end of file
  143. Index: src/test/java/net/sxpbelux/mirage/domain/beneficiary/BeneficiaryMother.java
  144. ===================================================================
  145. --- src/test/java/net/sxpbelux/mirage/domain/beneficiary/BeneficiaryMother.java (revision 9290)
  146. +++ src/test/java/net/sxpbelux/mirage/domain/beneficiary/BeneficiaryMother.java (working copy)
  147. @@ -120,6 +120,11 @@
  148. public static Beneficiary createBeneficiary(Client client, Consumer consumer) {
  149. return createBeneficiary(client, consumer, FACEVALUE, new EmailAddress("test@test.be"));
  150. }
  151. +
  152. + public static Beneficiary createBeneficiaryWithoutEmailAddress(Client client, Consumer consumer) {
  153. + return createBeneficiary(client, consumer, FACEVALUE, null);
  154. + }
  155. +
  156. public static Beneficiary createBeneficiary(Client client, Consumer consumer, EmailAddress emailAddress) {
  157. return createBeneficiary(client, consumer, FACEVALUE, emailAddress);
  158. }
  159. Index: src/test/java/net/sxpbelux/mirage/domain/owner/ConsumerMother.java
  160. ===================================================================
  161. --- src/test/java/net/sxpbelux/mirage/domain/owner/ConsumerMother.java (revision 9266)
  162. +++ src/test/java/net/sxpbelux/mirage/domain/owner/ConsumerMother.java (working copy)
  163. @@ -21,6 +21,10 @@
  164. return createConsumer(Constants.DUMMY_INSZ);
  165. }
  166.  
  167. + public static Consumer createConsumerWithoutEmailAddress(){
  168. + return new ConsumerFactoryTestImpl().createConsumer(PersonMother.createDefaultPerson(), null);
  169. + }
  170. +
  171. public static Consumer createConsumer(PersistedPersonIdentifier insz){
  172. return createConsumer(PersonMother.createPerson(insz));
  173. }
  174. Index: src/test/java/net/sxpbelux/mirage/domain/EmailRecipientFactoryTest.java
  175. ===================================================================
  176. --- src/test/java/net/sxpbelux/mirage/domain/EmailRecipientFactoryTest.java (revision 0)
  177. +++ src/test/java/net/sxpbelux/mirage/domain/EmailRecipientFactoryTest.java (revision 0)
  178. @@ -0,0 +1,68 @@
  179. +package net.sxpbelux.mirage.domain;
  180. +
  181. +import static org.junit.Assert.assertEquals;
  182. +import static org.junit.Assert.assertNotNull;
  183. +import static org.junit.Assert.assertNull;
  184. +import net.sxpbelux.mirage.domain.beneficiary.Beneficiary;
  185. +import net.sxpbelux.mirage.domain.beneficiary.BeneficiaryMother;
  186. +import net.sxpbelux.mirage.domain.organization.Client;
  187. +import net.sxpbelux.mirage.domain.organization.ClientMother;
  188. +import net.sxpbelux.mirage.domain.owner.Consumer;
  189. +import net.sxpbelux.mirage.domain.owner.ConsumerMother;
  190. +
  191. +import org.junit.Before;
  192. +import org.junit.Test;
  193. +
  194. +
  195. +public class EmailRecipientFactoryTest {
  196. +
  197. + private EmailRecipientFactory factory;
  198. + private Client client;
  199. +
  200. + @Before
  201. + public void setUp() {
  202. + factory = new EmailRecipientFactoryImpl ();
  203. + client = ClientMother.createClient();
  204. + }
  205. +
  206. + @Test
  207. + public void testCreateEmailForBeneficiaryWithConsumerAddressIdenticalToBeneficiaryAddress () {
  208. + Consumer consumer = ConsumerMother.createConsumer();
  209. + consumer.setEmail(new EmailAddress("johnny.cash@sodexo.com"));
  210. + Beneficiary beneficiary = BeneficiaryMother.createBeneficiary(client, consumer);
  211. + beneficiary.setEmail(new EmailAddress("johnny.cash@sodexo.com"));
  212. + beneficiary.setLanguage(Language.EN);
  213. + EmailRecipient email = factory.createNewEmailRecipientBasedOnConsumerFirstAndBeneficiaryAfterwards(beneficiary);
  214. + assertNotNull (email);
  215. + assertEquals (Language.EN, email.getLanguage());
  216. + assertEquals (new EmailAddress("johnny.cash@sodexo.com"), email.getEmailAddress());
  217. + }
  218. +
  219. + @Test
  220. + public void testCreateEmailForBeneficiaryWithConsumerAddressAndLanguageDifferentFromBeneficiaryAddressAndLanguage () {
  221. + Consumer consumer = ConsumerMother.createConsumer();
  222. + consumer.setEmail(new EmailAddress("johnny.cash@test.com"));
  223. + consumer.setLanguage(Language.FR);
  224. +
  225. + Beneficiary beneficiary = BeneficiaryMother.createBeneficiary(client, consumer);
  226. + beneficiary.setEmail(new EmailAddress("johnny.cash@sodexo.com"));
  227. + beneficiary.setLanguage(Language.EN);
  228. +
  229. + EmailRecipient email = factory.createNewEmailRecipientBasedOnConsumerFirstAndBeneficiaryAfterwards(beneficiary);
  230. + assertNotNull (email);
  231. + assertEquals (Language.FR, email.getLanguage());
  232. + assertEquals (new EmailAddress("johnny.cash@test.com"), email.getEmailAddress());
  233. +
  234. + }
  235. +
  236. + @Test
  237. + public void testCreateEmailForBeneficiaryWithConsumerAddressAndBeneficiaryAddressNull () {
  238. + Consumer consumer = ConsumerMother.createConsumerWithoutEmailAddress();
  239. + Beneficiary beneficiary = BeneficiaryMother.createBeneficiaryWithoutEmailAddress(client, consumer);
  240. +
  241. + EmailRecipient email = factory.createNewEmailRecipientBasedOnConsumerFirstAndBeneficiaryAfterwards(beneficiary);
  242. + assertNotNull (email);
  243. + assertEquals (Language.EN, email.getLanguage());
  244. + assertNull (email.getEmailAddress());
  245. + }
  246. +}
  247. #P common-services
  248. Index: src/main/java/net/sxpbelux/mirage/service/MailSenderServiceImpl.java
  249. ===================================================================
  250. --- src/main/java/net/sxpbelux/mirage/service/MailSenderServiceImpl.java (revision 9266)
  251. +++ src/main/java/net/sxpbelux/mirage/service/MailSenderServiceImpl.java (working copy)
  252. @@ -337,7 +337,7 @@
  253. }
  254.  
  255. @Override
  256. - public void sendMailToInformBeneficiaryForBlockCard(Card card) {
  257. + public void sendMailToInformConsumerForBlockCard(Card card) {
  258. Map<String, Object> model = new HashMap<String, Object>();
  259. model.put("date", DateUtil.formatDateToDDMMYYY(DateUtil.getToday()));
  260. model.put("display_name", card.getConsumer().getDisplayName());
  261. @@ -349,7 +349,7 @@
  262. }
  263.  
  264. @Override
  265. - public void sendMailToInformBeneficiaryForPinResend(Card card) {
  266. + public void sendMailToInformConsumerForPinResend(Card card) {
  267. Map<String, Object> model = new HashMap<String, Object>();
  268. List<EmailAddress> emailAddresses = new ArrayList<EmailAddress>();
  269. emailAddresses.add(card.getConsumer().getEmail());
Add Comment
Please, Sign In to add comment