package no.uio.ifi.trackfind.backend.services;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import no.uio.ifi.trackfind.backend.services.impl.SchemaService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Collection;
import java.util.Map;

import static org.junit.Assert.assertEquals;

@RunWith(SpringRunner.class)
public class SchemaServiceTest {

    public static final String ATTRIBUTES =
            "{\n" +
                    "  \"experiments\": [\n" +
                    "    \"'@schema'\",\n" +
                    "    \"'technique'->'term_iri'\",\n" +
                    "    \"'aggregated_from'\",\n" +
                    "    \"'sample_ref'\",\n" +
                    "    \"'target'->'term_iri'\",\n" +
                    "    \"'study_ref'\",\n" +
                    "    \"'global_id'\",\n" +
                    "    \"'target'->'term_value'\",\n" +
                    "    \"'compute_protocol_description'\",\n" +
                    "    \"'technique'->'term_value'\",\n" +
                    "    \"'local_id'\",\n" +
                    "    \"'lab_protocol_description'\"\n" +
                    "  ],\n" +
                    "  \"studies\": [\n" +
                    "    \"'@schema'\",\n" +
                    "    \"'contact'->'e-mail'\",\n" +
                    "    \"'study_name'\",\n" +
                    "    \"'contact'->'orcid'\",\n" +
                    "    \"'contact'->'name'\",\n" +
                    "    \"'global_id'\",\n" +
                    "    \"'publication'\",\n" +
                    "    \"'local_id'\"\n" +
                    "  ],\n" +
                    "  \"samples\": [\n" +
                    "    \"'@schema'\",\n" +
                    "    \"'tissue_type'->'term_iri'\",\n" +
                    "    \"'biomaterial_type'\",\n" +
                    "    \"'sample_type'->'term_iri'\",\n" +
                    "    \"'phenotype'->'term_value'\",\n" +
                    "    \"'tissue_type'->'term_value'\",\n" +
                    "    \"'phenotype'->'term_iri'\",\n" +
                    "    \"'sample_type'->'term_value'\",\n" +
                    "    \"'global_id'\",\n" +
                    "    \"'local_id'\"\n" +
                    "  ],\n" +
                    "  \"tracks\": [\n" +
                    "    \"'file_format'->'term_iri'\",\n" +
                    "    \"'genome_assembly'\",\n" +
                    "    \"'experiment_ref'\",\n" +
                    "    \"'checksum'->'cs_hash'\",\n" +
                    "    \"'checksum'->'cs_method'\",\n" +
                    "    \"'local_id'\",\n" +
                    "    \"'file_format'->'term_value'\",\n" +
                    "    \"'@schema'\",\n" +
                    "    \"'file_iri'\",\n" +
                    "    \"'content_type'->'term_iri'\",\n" +
                    "    \"'label_long'\",\n" +
                    "    \"'file_name'\",\n" +
                    "    \"'global_id'\",\n" +
                    "    \"'label_short'\",\n" +
                    "    \"'content_type'->'term_value'\"\n" +
                    "  ]\n" +
                    "}";

    private Gson gson;

    private SchemaService schemaService;

    @Before
    public void setUp() {
        gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();
        schemaService = new SchemaService("->");
    }

    @Test
    public void getAttributesTest() {
        Map<String, Collection<String>> attributes = schemaService.getAttributes();
        String actual = gson.toJson(attributes);
        assertEquals(ATTRIBUTES, actual);
    }

}

@@ -635,67 +635,8 @@
 %22 +%0A
-                    %22    %5C%22'technique'-%3E'term_iri'%5C%22,%5Cn%22 +%0A
     
@@ -767,35 +767,35 @@
 'target'-%3E'term_
-iri
+url
 '%5C%22,%5Cn%22 +%0A      
@@ -874,32 +874,91 @@
 bal_id'%5C%22,%5Cn%22 +%0A
+                    %22    %5C%22'technique'-%3E'term_url'%5C%22,%5Cn%22 +%0A
                 
@@ -1842,37 +1842,37 @@
         %22    %5C%22'
-tissu
+sampl
 e_type'-%3E'term_i
@@ -1862,35 +1862,35 @@
 le_type'-%3E'term_
-iri
+url
 '%5C%22,%5Cn%22 +%0A      
@@ -1941,69 +1941,8 @@
 %22 +%0A
-                    %22    %5C%22'sample_type'-%3E'term_iri'%5C%22,%5Cn%22 +%0A
     
@@ -2099,35 +2099,35 @@
 enotype'-%3E'term_
-iri
+url
 '%5C%22,%5Cn%22 +%0A      
@@ -2222,32 +2222,93 @@
 bal_id'%5C%22,%5Cn%22 +%0A
+                    %22    %5C%22'tissue_type'-%3E'term_url'%5C%22,%5Cn%22 +%0A
                 
@@ -2433,35 +2433,36 @@
     %22    %5C%22'
-file_format
+content_type
 '-%3E'term_iri
@@ -2450,35 +2450,35 @@
 nt_type'-%3E'term_
-iri
+url
 '%5C%22,%5Cn%22 +%0A      
@@ -2568,32 +2568,93 @@
 nt_ref'%5C%22,%5Cn%22 +%0A
+                    %22    %5C%22'file_format'-%3E'term_url'%5C%22,%5Cn%22 +%0A
                 
@@ -2866,53 +2866,8 @@
 %22 +%0A
-                    %22    %5C%22'@schema'%5C%22,%5Cn%22 +%0A
     
@@ -2895,19 +2895,19 @@
 %5C%22'file_
-iri
+url
 '%5C%22,%5Cn%22 
@@ -2940,32 +2940,15 @@
  %5C%22'
-content_type'-%3E'term_iri
+@schema
 '%5C%22,

Fix tests