package org.sagebionetworks.bridge.services;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.sagebionetworks.bridge.TestConstants;
import org.sagebionetworks.bridge.dao.ParticipantOption.SharingScope;
import org.sagebionetworks.bridge.models.User;
import org.sagebionetworks.bridge.models.studies.ConsentSignature;
import org.sagebionetworks.bridge.models.studies.StudyConsent;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@ContextConfiguration("classpath:test-context.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class SendEmailIntegTest {

    private static final String IMG = "iVBORw0KGgoAAAANSUhEUgAAAFAAAAAtCAIAAAC2z3vlAAAAA3NCSVQICAjb" +
            "4U/gAAABhElEQVRoge1Z0Q7DIAgsy/7/l9nDkq5pEUUOMGvvaeuqcB6gMmLm7U54VTuQjdsRfotPiej7QQn4/Z" +
            "3um0uBro62mJyei1ifdp+wFYtzxuewc72iIeewE0RC4GDntw75JSY8pK82rAiKka8/ZoVFGqKLEzonpMMoYd11" +
            "ZnZyTst8WNHyJG0C2909ZNESddZFhlA1rTW4SrdiW0T3zRaT00BTsQjZlkags43b1fAHj66vRKSwZebuDJ6tNF" +
            "thnWqCA3mEsVRNxeKIoZD2r325sDsyGgDrsN0Kq3TVLbKvcIRnoTmio+A+XNshyG7ilfdDzjnsPNzm1KerlfHJ" +
            "kxQuF3YHknBL3mi2pvmfRvwsnPIeh+tDnFUGoLB++xmcQfk6+NMgvIQzr7WiLasJc0hX9dlRds/NESAf09rrWy" +
            "uw/kddHhJOy3MmQralhGPGtImCnpZ/lGdBwYTXOUK2gCTsZDs43GkFULSAql5bc/CQ0f4uXT8+JxD7z/WCuN1t" +
            "6SH877gd4Q/1IdhFWU79+gAAAABJRU5ErkJggg==";

    @Resource
    private StudyService studyService;

    @Resource
    private SendMailViaAmazonService sendEmailService;

    @Test
    public void test() {
        ConsentSignature consent = ConsentSignature.create("Eggplant McTester", "1970-05-01", IMG, "image/png");
        User user = new User();
        user.setEmail(studyService.getStudy(TestConstants.TEST_STUDY_IDENTIFIER).getSupportEmail());
        StudyConsent studyConsent = new StudyConsent() {
            @Override
            public String getStudyKey() {
                return TestConstants.TEST_STUDY_IDENTIFIER;
            }
            @Override
            public long getCreatedOn() {
                return 0;
            }
            @Override
            public boolean getActive() {
                return true;
            }
            @Override
            public String getPath() {
                return "conf/email-templates/asthma-consent.html";
            }
            @Override
            public int getMinAge() {
                return 17;
            }
        };
        sendEmailService.sendConsentAgreement(user, consent, studyConsent, SharingScope.SPONSORS_AND_PARTNERS);
    }
}

@@ -417,23 +417,150 @@
 es.Study
-Consent
+;%0Aimport org.sagebionetworks.bridge.models.studies.StudyConsent;%0Aimport org.sagebionetworks.bridge.services.email.ConsentEmailProvider
 ;%0Aimport
@@ -1760,16 +1760,22 @@
         
+final 
 ConsentS
@@ -1783,23 +1783,25 @@
 gnature 
-consent
+signature
  = Conse
@@ -1881,16 +1881,22 @@
         
+final 
 User use
@@ -1923,22 +1923,28 @@
     
-user.setEmail(
+final Study study = 
 stud
@@ -1997,16 +1997,45 @@
 NTIFIER)
+;%0A        user.setEmail(study
 .getSupp
@@ -2736,38 +2736,78 @@
 send
-ConsentAgreement(user, consent
+Email(new ConsentEmailProvider(%0A                study, user, signature
 , st
@@ -2853,16 +2853,17 @@
 ARTNERS)
+)
 ;%0A    %7D%0A

Fix after syncing up with base