package org.sagebionetworks.bridge.services;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import javax.annotation.Resource;

import org.apache.commons.codec.binary.Base64;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.sagebionetworks.bridge.TestUserAdminHelper;
import org.sagebionetworks.bridge.TestUserAdminHelper.TestUser;
import org.sagebionetworks.bridge.exceptions.EntityNotFoundException;
import org.sagebionetworks.bridge.models.studies.ConsentSignature;
import org.sagebionetworks.bridge.models.studies.Study;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.stormpath.sdk.account.Account;
import com.stormpath.sdk.client.Client;

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

    @Resource
    private AccountEncryptionService accountEncryptionService;

    @Resource
    private TestUserAdminHelper helper;

    @Resource
    private Client stormpathClient;

    private TestUser testUser;

    @Before
    public void before() {
        testUser = helper.createUser(AccountEncryptionServiceImplTest.class, true, false);
    }

    @After
    public void after() {
        helper.deleteUser(testUser);
    }

    @Test
    public void testConsentSignature() {
        Study study = testUser.getStudy();
        Account account = stormpathClient.getResource(testUser.getUser().getStormpathHref(), Account.class);
        ConsentSignature consentSignature = ConsentSignature.create("Test User", "1977-07-29",
                Base64.encodeBase64String("some image".getBytes()), "image/png");
        accountEncryptionService.putConsentSignature(study, account, consentSignature);
        ConsentSignature signature = accountEncryptionService.getConsentSignature(study, account);
        assertNotNull(signature);
        assertEquals(consentSignature.getName(), signature.getName());
        assertEquals(consentSignature.getBirthdate(), signature.getBirthdate());
        assertEquals(consentSignature.getImageData(), signature.getImageData());
        assertEquals(consentSignature.getImageMimeType(), signature.getImageMimeType());
    }

    @Test(expected = EntityNotFoundException.class)
    public void testConsentSignatureEntityNotFoundException() {
        Study study = testUser.getStudy();
        Account account = stormpathClient.getResource(testUser.getUser().getStormpathHref(), Account.class);
        accountEncryptionService.getConsentSignature(study, account);
    }
}

@@ -129,16 +129,96 @@
 NotNull;
+%0Aimport static org.junit.Assert.assertTrue;%0Aimport static org.junit.Assert.fail;
 %0A%0Aimport
@@ -2422,24 +2422,363 @@
 imeType());%0A
+        accountEncryptionService.removeConsentSignature(study, account);%0A        try %7B%0A            accountEncryptionService.getConsentSignature(study, account);%0A            fail(%22EntityNotFoundException expected.%22);%0A        %7D catch (EntityNotFoundException e) %7B%0A            assertTrue(%22EntityNotFoundException expected.%22, true);%0A        %7D%0A
     %7D%0A%0A    @

Add a test case for remove()