Hi
I am trying to set up a mock test for when I am sending email to achieve 100%
coverage of my code. With the command emailSender.send(message), the message
needs to be delivered to a mock endpoint that can evaluated and asserted. It
seems that org.jvnet.mock-javamail is an option, but for the life of me I
cannot figure how to do the setup in my yml file.
This is what I have in my yml file:
spring:
profiles: mock
mail:
host: localhost
port: 25
protocol: smtp
properties.mail.smtp.auth: false
properties.mail.smtp.tls: false
properties.mail.debug: true
When I then run my test, I get:
com.sun.mail.util.MailConnectException: Couldn't connect to host, port:
localhost, 25; timeout -1;
nested exception is:
java.net.SocketException: Permission denied: connect
My testing code looks like this:
@ActiveProfiles("mock")
@RunWith(CamelSpringBootRunner.class)
@SpringBootTest(properties = {
"camel.springboot.xmlRoutes=false",
"camel.springboot.javaRoutesIncludePattern=na/com/meatco/edocExchange/alert/**"})
@MockEndpoints
@Slf4j
public class MailProcessorTest {
@Autowired
MailProcessor mailProcessor;
@Autowired
CamelContext camelContext;
@BeforeClass
public static void setUp(){
Mailbox.clearAll();
}
@Test
public void mailProcessorTest() throws Exception {
String subject = "Test";
String body = "Test Message Body";
Exchange exchange = new DefaultExchange(camelContext);
exchange.setProperty(Exchange.EXCEPTION_CAUGHT, new Exception("Test
Exception"));
mailProcessor.process(exchange);
List<Message> inbox = Mailbox.get("[email protected]");
Assert.assertTrue(inbox.size() == 1);
}
}
Can anyone help?
Louis