package uk.ac.ebi.spot.goci.curation.service.deposition;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import uk.ac.ebi.spot.goci.model.deposition.DepositionSampleDto;

import java.io.IOException;

import static org.junit.Assert.*;

public class DepositionSampleServiceTest {

    @Test
    public void testBuildDescription() {
        try {
            ObjectMapper mapper = new ObjectMapper();
            DepositionSampleService service = new DepositionSampleService();
            String json = "{\n" + "\t\"study_tag\": \"Study1\",\n" + "\t\"size\": 500,\n" +
                    "\t\"sample_description\": \"Sample description\",\n" +
                    "\t\"ancestry_category\": \"European\",\n" + "\t\"ancestry\": \"Italian\",\n" +
                    "\t\"ancestry_description\": \"Val Borbera\",\n" + "\t\"country_recruitement\": \"Italy\",\n" +
                    "\t\"stage\": \"discovery\"\n" + "}";
            DepositionSampleDto dto = null;
            dto = mapper.readValue(json, DepositionSampleDto.class);
            String description = service.buildDescription(dto);
            assertEquals("500 Italian ancestry individuals", description);

            json = "{\n" + "\t\"study_tag\": \"Study1\",\n" + "\t\"size\": 200,\n" +
                    "\t\"sample_description\": \"Sample description\",\n" +
                    "\t\"ancestry_category\": \"European\",\n" + "\t\"ancestry\": \"French|Spanish\",\n" +
                    "\t\"country_recruitement\": \"France|Spain\",\n" + "\t\"stage\": \"replication\"\n" +
                    "}";
            dto = mapper.readValue(json, DepositionSampleDto.class);
            description = service.buildDescription(dto);
            assertEquals("200 French, Spanish ancestry individuals", description);
            
            json = "{\n" + "\t\"study_tag\": \"Study2\",\n" + "\t\"size\": 500,\n" + "\t\"cases\": 300,\n" +
                    "\t\"controls\": 200,\n" + "\t\"sample_description\": \"Sample description\",\n" +
                    "\t\"ancestry_category\": \"Asian unspecified\",\n" +
                    "\t\"country_recruitement\": \"NR\",\n" + "\t\"stage\": \"discovery\"\n" + "}";
            dto = mapper.readValue(json, DepositionSampleDto.class);
            description = service.buildDescription(dto);
            assertEquals("300 Asian unspecified ancestry cases, 200 Asian unspecified ancestry controls", description);

            json = "{\n" + "\t\"study_tag\": \"Study1\",\n" + "\t\"size\": 200,\n" +
                    "\t\"sample_description\": \"Sample description\",\n" +
                    "\t\"ancestry_category\": \"African American or Afro-Caribbean\",\n" +
                    "\t\"country_recruitement\": \"U.S.\",\n" + "\t\"stage\": \"replication\"\n" + "}";
            dto = mapper.readValue(json, DepositionSampleDto.class);
            description = service.buildDescription(dto);
            assertEquals("200 African American or Afro-Caribbean ancestry individuals",
                    description);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
@@ -1153,25 +1153,16 @@
 Italian 
-ancestry 
 individu
@@ -1173,32 +1173,32 @@
 , description);%0A
+
 %0A            jso
@@ -1754,25 +1754,16 @@
 Spanish 
-ancestry 
 individu
@@ -2355,25 +2355,16 @@
 ecified 
-ancestry 
 cases, 2
@@ -2384,25 +2384,16 @@
 ecified 
-ancestry 
 controls
@@ -2884,32 +2884,32 @@
 scription(dto);%0A
+
             asse
@@ -2961,17 +2961,8 @@
 ean 
-ancestry 
 indi

update tests