From 3b42a0b12efaefce12c2df73617cb0e7508355a8 Mon Sep 17 00:00:00 2001 From: geek Date: Mon, 26 Jun 2017 15:59:53 +0900 Subject: [PATCH 1/2] emailAuth DAO Test code --- .../module/email/dao/EmailAuthDAOTest.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/test/java/com/loafle/overflow/module/email/dao/EmailAuthDAOTest.java diff --git a/src/test/java/com/loafle/overflow/module/email/dao/EmailAuthDAOTest.java b/src/test/java/com/loafle/overflow/module/email/dao/EmailAuthDAOTest.java new file mode 100644 index 0000000..4241542 --- /dev/null +++ b/src/test/java/com/loafle/overflow/module/email/dao/EmailAuthDAOTest.java @@ -0,0 +1,49 @@ +package com.loafle.overflow.module.email.dao; + +import com.loafle.overflow.AppConfig; +import com.loafle.overflow.JdbcConfiguration; +import com.loafle.overflow.module.email.model.EmailAuth; +import com.loafle.overflow.module.member.model.Member; +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 java.util.List; + +import static org.junit.Assert.*; + +/** + * Created by root on 17. 6. 23. + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {AppConfig.class, JdbcConfiguration.class}) +public class EmailAuthDAOTest { + + @Autowired + private EmailAuthDAO dao; + + @Test + public void TestSaveEmailAuth() { + EmailAuth auth = new EmailAuth(); + auth.setEmailAuthKey("dbseogns1234"); + auth.setMember(new Member(1)); + + this.dao.save(auth); + } + + @Test + public void TestFindByEmailAuthKey() { + EmailAuth auth = this.dao.findByEmailAuthKey("dbseogns1234"); + assertEquals(1, auth.getId()); + } + + @Test + public void TestFindByMember() { + List auths = this.dao.findByMember(new Member((long)1)); + + assertEquals(1, auths.size()); + } + +} \ No newline at end of file From 62a72a531d3797475d400574fa5f6b2ba173ca6c Mon Sep 17 00:00:00 2001 From: geek Date: Mon, 26 Jun 2017 16:00:20 +0900 Subject: [PATCH 2/2] EmailAuth method added --- .../overflow/module/email/dao/EmailAuthDAO.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/loafle/overflow/module/email/dao/EmailAuthDAO.java b/src/main/java/com/loafle/overflow/module/email/dao/EmailAuthDAO.java index 0c636a9..54070bc 100644 --- a/src/main/java/com/loafle/overflow/module/email/dao/EmailAuthDAO.java +++ b/src/main/java/com/loafle/overflow/module/email/dao/EmailAuthDAO.java @@ -1,18 +1,23 @@ package com.loafle.overflow.module.email.dao; import com.loafle.overflow.module.email.model.EmailAuth; +import com.loafle.overflow.module.member.model.Member; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import java.util.List; + /** * Created by geek@loafle.com on 17. 6. 6. */ @Repository public interface EmailAuthDAO extends JpaRepository { -// public EmailAuth findByAuthToken(EmailAuth emailAuth); + @Query("select e from EmailAuth e where e.emailAuthKey = :authKey") + EmailAuth findByEmailAuthKey(@Param("authKey") String emailAuthKey); -// public List findByMemberId(EmailAuth emailAuth); + List findByMember(Member member); -// public EmailAuth updateEmailAuth(EmailAuth emailAuth); }