package org.sagebionetworks.bridge.sdk.integration;

import static org.junit.Assert.assertEquals;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.sagebionetworks.bridge.sdk.ClientProvider;
import org.sagebionetworks.bridge.sdk.Session;
import org.sagebionetworks.bridge.sdk.TestUserHelper;
import org.sagebionetworks.bridge.sdk.TestUserHelper.TestUser;
import org.sagebionetworks.bridge.sdk.UserClient;
import org.sagebionetworks.bridge.sdk.models.users.SignInCredentials;
import org.sagebionetworks.bridge.sdk.models.users.UserProfile;

public class UTF8Test {
    
    private TestUser testUser;
    
    @Before
    public void before() {
        testUser = TestUserHelper.createAndSignInUser(UTF8Test.class, true);
    }
    
    @After
    public void after() {
        testUser.signOutAndDeleteUser();
    }

    @Test
    public void canSaveAndRetrieveDataStoredInRedis() {
        UserClient client = testUser.getSession().getUserClient();
        
        UserProfile profile = client.getProfile();
        profile.setFirstName("☃");
        // I understand from the source of this text that it is actualy UTF-16.
        // It should still work.
        profile.setLastName("지구상의　３대　극지라　불리는");
        client.saveProfile(profile); // should be update
        
        // Force a refresh of the Redis session cache.
        testUser.getSession().signOut();
        Session session = ClientProvider.signIn(new SignInCredentials(testUser.getEmail(), testUser.getPassword()));
        
        profile = session.getUserClient().getProfile();
        assertEquals("☃", profile.getFirstName());
        assertEquals("지구상의　３대　극지라　불리는", profile.getLastName());
    }
    
}

@@ -113,14 +113,14 @@
 nit.
-After;
+Test;%0A
 %0Aimp
@@ -131,42 +131,86 @@
 org.
-junit.Before;%0Aimport org.junit.Tes
+sagebionetworks.bridge.Tests;%0Aimport org.sagebionetworks.bridge.sdk.AdminClien
 t;%0Ai
@@ -468,32 +468,92 @@
 sdk.UserClient;%0A
+import org.sagebionetworks.bridge.sdk.models.studies.Study;%0A
 import org.sageb
@@ -703,323 +703,1042 @@
     
+@Test
 %0A    p
-rivate TestUser testUser
+ublic void canSaveAndRetrieveDataStoredInDynamo() %7B%0A        String studyId = Tests.randomIdentifier()
 ;%0A    
-%0A
     
-@Before%0A    public void before() %7B%0A        testUser = TestUserHelper.createAndSignInUser(UTF8Test.class, true);%0A    %7D
+String studyName = %22%E2%98%83%EC%A7%80%EA%B5%AC%EC%83%81%EC%9D%98%E3%80%80%EF%BC%93%EB%8C%80%E3%80%80%EA%B7%B9%EC%A7%80%EB%9D%BC%E3%80%80%EB%B6%88%EB%A6%AC%EB%8A%94%22;%0A        AdminClient adminClient = TestUserHelper.getSignedInAdmin().getSession().getAdminClient();%0A%0A        try %7B%0A            // make minimal study%0A            Study study = new Study();%0A            study.setIdentifier(studyId);%0A            study.setName(studyName);%0A%0A            // create study
 %0A    
-%0A
+  
     
-@After%0A    public void after() %7B%0A        testUser.signOutAndDeleteUser();%0A    %7D%0A%0A    @Test%0A    public void canSaveAndRetrieveDataStoredInRedis() %7B%0A
+  adminClient.createStudy(study);%0A%0A            // get study back and verify fields%0A            Study returnedStudy = adminClient.getStudy(studyId);%0A            assertEquals(studyId, returnedStudy.getIdentifier());%0A            assertEquals(studyName, returnedStudy.getName());%0A        %7D finally %7B%0A            // clean-up: delete study%0A            adminClient.deleteStudy(studyId);%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void canSaveAndRetrieveDataStoredInRedis() %7B%0A        TestUser testUser = TestUserHelper.createAndSignInUser(UTF8Test.class, true);%0A        try %7B%0A    
     
@@ -1800,33 +1800,29 @@
 ient();%0A
- 
+%0A
        
-%0A
      
-   
 UserProf
@@ -1856,32 +1856,36 @@
 file();%0A        
+    
 profile.setFirst
@@ -1899,24 +1899,28 @@
 %22);%0A        
+ 
+   
 // I underst
@@ -1983,24 +1983,28 @@
 16.%0A        
+    
 // It should
@@ -2016,32 +2016,36 @@
 l work.%0A        
+ 
+   
 profile.setLastN
@@ -2064,24 +2064,28 @@
 %E3%80%80%EA%B7%B9%EC%A7%80%EB%9D%BC%E3%80%80%EB%B6%88%EB%A6%AC%EB%8A%94%22);%0A
+    
         clie
@@ -2129,25 +2129,21 @@
  update%0A
-    
+%0A
     
-%0A
         
@@ -2197,16 +2197,20 @@
         
+   
+ 
 testUser
@@ -2230,24 +2230,28 @@
 .signOut();%0A
+    
         Sess
@@ -2359,17 +2359,13 @@
 ));%0A
-    
+%0A
     
-%0A
     
@@ -2416,32 +2416,36 @@
 file();%0A        
+    
 assertEquals(%22%E2%98%83%22
@@ -2471,32 +2471,36 @@
 ame());%0A        
+ 
+   
 assertEquals(%22%EC%A7%80%EA%B5%AC
@@ -2535,24 +2535,99 @@
 astName());%0A
+        %7D finally %7B%0A            testUser.signOutAndDeleteUser();%0A        %7D%0A
     %7D%0A    %0A%7D

add test UTF8 with Study