|
| 1 | +/* |
| 2 | + Copyright 2025 Jose Morales contact@josdem.io |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package com.josdem.jmailer.config; |
| 18 | + |
| 19 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 20 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 21 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 22 | + |
| 23 | +import lombok.extern.slf4j.Slf4j; |
| 24 | +import org.junit.jupiter.api.BeforeEach; |
| 25 | +import org.junit.jupiter.api.DisplayName; |
| 26 | +import org.junit.jupiter.api.Test; |
| 27 | +import org.junit.jupiter.api.TestInfo; |
| 28 | +import org.mockito.Mock; |
| 29 | +import org.mockito.MockitoAnnotations; |
| 30 | +import org.springframework.mail.javamail.JavaMailSender; |
| 31 | + |
| 32 | +@Slf4j |
| 33 | +class TemplateConfigTest { |
| 34 | + |
| 35 | + private TemplateConfig templateConfig; |
| 36 | + |
| 37 | + @Mock private JavaMailSender defaultMailSender; |
| 38 | + |
| 39 | + @Mock private JavaMailSender vetlogMailSender; |
| 40 | + |
| 41 | + @BeforeEach |
| 42 | + void setUp() { |
| 43 | + MockitoAnnotations.openMocks(this); |
| 44 | + templateConfig = new TemplateConfig(defaultMailSender, vetlogMailSender); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + @DisplayName("getting a template strategies") |
| 49 | + void shouldGetTemplateStrategies(TestInfo testInfo) { |
| 50 | + log.info(testInfo.getDisplayName()); |
| 51 | + var templateStrategy = templateConfig.templateStrategy(); |
| 52 | + assertNotNull(templateStrategy); |
| 53 | + assertEquals(8, templateStrategy.size()); |
| 54 | + assertTrue(templateStrategy.containsKey("welcome.ftl")); |
| 55 | + assertTrue(templateStrategy.containsKey("welcome_es.ftl")); |
| 56 | + assertTrue(templateStrategy.containsKey("adoption.ftl")); |
| 57 | + assertTrue(templateStrategy.containsKey("adoption_es.ftl")); |
| 58 | + assertTrue(templateStrategy.containsKey("forgotPassword.ftl")); |
| 59 | + assertTrue(templateStrategy.containsKey("forgotPassword_es.ftl")); |
| 60 | + assertTrue(templateStrategy.containsKey("message.ftl")); |
| 61 | + assertTrue(templateStrategy.containsKey("register.ftl")); |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + @DisplayName("getting a default client") |
| 66 | + void shouldGetDefaultClient(TestInfo testInfo) { |
| 67 | + log.info(testInfo.getDisplayName()); |
| 68 | + var templateStrategy = templateConfig.templateStrategy(); |
| 69 | + var defaultClient = templateStrategy.get("message.ftl"); |
| 70 | + assertNotNull(defaultClient); |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + @DisplayName("getting a vetlog client") |
| 75 | + void shouldGetVetlogClient(TestInfo testInfo) { |
| 76 | + log.info(testInfo.getDisplayName()); |
| 77 | + var templateStrategy = templateConfig.templateStrategy(); |
| 78 | + var vetlogClient = templateStrategy.get("welcome.ftl"); |
| 79 | + assertNotNull(vetlogClient); |
| 80 | + } |
| 81 | +} |
0 commit comments