From a04de6d9280f7ba15ef989f4e9562a52fc734c1c Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Sun, 6 Jul 2014 17:40:45 +0200 Subject: [PATCH] =?UTF-8?q?Implementovan=C3=BD=20parser=20na=20=C5=A1ablon?= =?UTF-8?q?y=20e-mail=C5=AF.=20Rozchozeny=20unit=20testy.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 5 ++ .../isspst/mail/EntityMessageBuilder.java | 59 +++++++++++++++++++ .../info/bukova/isspst/mail/MailMessage.java | 12 ++++ .../bukova/isspst/mail/MessageBuilder.java | 8 +++ .../isspst/ui/settings/GlobalSettingsVM.java | 2 +- .../webapp/WEB-INF/spring/mail-services.xml | 2 + src/test/java/WEB-INF/jdbc.properties | 5 ++ src/test/java/WEB-INF/ldap.properties | 2 + src/test/java/WEB-INF/mail.properties | 7 +++ .../isspst/mail/MessageBuilderTest.java | 35 +++++++++++ src/test/resources/test-context.xml | 13 ++++ 11 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 src/main/java/info/bukova/isspst/mail/EntityMessageBuilder.java create mode 100644 src/main/java/info/bukova/isspst/mail/MessageBuilder.java create mode 100644 src/test/java/WEB-INF/jdbc.properties create mode 100644 src/test/java/WEB-INF/ldap.properties create mode 100644 src/test/java/WEB-INF/mail.properties create mode 100644 src/test/java/info/bukova/isspst/mail/MessageBuilderTest.java create mode 100644 src/test/resources/test-context.xml diff --git a/pom.xml b/pom.xml index fe4a45d7..a39e85ea 100644 --- a/pom.xml +++ b/pom.xml @@ -80,6 +80,11 @@ spring-security-ldap ${org.springframework-version} + + org.springframework + spring-test + ${org.springframework-version} + diff --git a/src/test/java/WEB-INF/jdbc.properties b/src/test/java/WEB-INF/jdbc.properties new file mode 100644 index 00000000..4e3ec948 --- /dev/null +++ b/src/test/java/WEB-INF/jdbc.properties @@ -0,0 +1,5 @@ +jdbc.driverClassName=com.mysql.jdbc.Driver +jdbc.dialect=org.hibernate.dialect.MySQLDialect +jdbc.databaseurl=jdbc:mysql://127.0.0.1:3306/isspst?characterEncoding=latin2&autoReconnect=true +jdbc.username=isspst +jdbc.password=xsacfgd \ No newline at end of file diff --git a/src/test/java/WEB-INF/ldap.properties b/src/test/java/WEB-INF/ldap.properties new file mode 100644 index 00000000..4060b43d --- /dev/null +++ b/src/test/java/WEB-INF/ldap.properties @@ -0,0 +1,2 @@ +ldap.server=ldap://localhost:3089 +ldap.userDNPattern=uid=\{0\},OU=people,DC=bukova,DC=info \ No newline at end of file diff --git a/src/test/java/WEB-INF/mail.properties b/src/test/java/WEB-INF/mail.properties new file mode 100644 index 00000000..260c67ee --- /dev/null +++ b/src/test/java/WEB-INF/mail.properties @@ -0,0 +1,7 @@ +mail.from=josef.rokos@gmail.com +mail.host=smtp.gmail.com +mail.port=587 +mail.useauth=true +mail.usessl=true +mail.username=josef.rokos@gmail.com +mail.password=XXXXX \ No newline at end of file diff --git a/src/test/java/info/bukova/isspst/mail/MessageBuilderTest.java b/src/test/java/info/bukova/isspst/mail/MessageBuilderTest.java new file mode 100644 index 00000000..62f98d88 --- /dev/null +++ b/src/test/java/info/bukova/isspst/mail/MessageBuilderTest.java @@ -0,0 +1,35 @@ +package info.bukova.isspst.mail; + +import info.bukova.isspst.data.Material; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import static org.junit.Assert.*; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = {"classpath:/test-context.xml"}) +public class MessageBuilderTest { + + @Autowired + private MessageBuilder messageBuilder; + + @Test + public void buildTest() { + MailMessage template = new MailMessage(); + Material data = new Material(); + data.setCode("pokus"); + data.setDescription("popisek"); + + template.setSubject("predmet"); + template.setText("pokusnej text [code] s popiskem [description]"); + + MailMessage replaced = messageBuilder.buildMessage(template, data); + + assertEquals("pokusnej text pokus s popiskem popisek", replaced.getText()); + } + +} diff --git a/src/test/resources/test-context.xml b/src/test/resources/test-context.xml new file mode 100644 index 00000000..aa00b5ff --- /dev/null +++ b/src/test/resources/test-context.xml @@ -0,0 +1,13 @@ + + + + + + + + + + +