Last active
June 19, 2018 12:54
-
-
Save thetekst/c0e79ef2045be8642361ba1199b93458 to your computer and use it in GitHub Desktop.
SpringBoot Spock test send email
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ru.mailer.service | |
import com.icegreen.greenmail.util.GreenMail | |
import com.icegreen.greenmail.util.ServerSetup | |
import org.springframework.beans.factory.annotation.Autowired | |
import org.springframework.boot.test.context.SpringBootTest | |
import ru.mailer.mq.model.MessageDto | |
import spock.lang.Shared | |
import spock.lang.Specification | |
import javax.mail.Message | |
/** | |
* Created by Dmitry Tkachenko on 18.06.18 | |
*/ | |
@SpringBootTest | |
class EmailServiceTest extends Specification { | |
@Autowired | |
EmailService emailService | |
@Shared | |
GreenMail greenMail | |
def setupSpec() { | |
def setup = new ServerSetup(3025, "localhost", "smtp") | |
greenMail = new GreenMail(setup) | |
greenMail.start() | |
} | |
def cleanupSpec() { | |
greenMail.stop() | |
} | |
def "SendEmail"() { | |
given: | |
def messageDto = createMessageDto() | |
when: | |
emailService.sendEmail(messageDto) | |
Message[] messages = greenMail.getReceivedMessages() | |
println(messages[0].getContent()) | |
then: | |
messages.length == 1 | |
} | |
def createMessageDto() { | |
def dto = new MessageDto() | |
dto.from = '[email protected]' | |
dto.to = '[email protected]' | |
dto.subject = 'my subject' | |
dto.phone = '89999999999' | |
dto.body = 'my body' | |
dto | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment