package no.deichman.services.ontology;


import com.google.gson.Gson;
import org.junit.Before;
import org.junit.Test;

import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import java.util.HashMap;
import java.util.Map;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;

public class TranslationResourceTest {

    private TranslationResource translationResource;

    @Before
    public void setUp() throws Exception {
        translationResource = new TranslationResource();
    }

    @Test
    public void should_have_default_constructor() {
        assertNotNull(new TranslationResource());
    }

    @Test
    public void should_return_ok_when_getting_english_and_norwegian() {
        Response response1 = translationResource.getTranslations("en");
        assertThat(response1.getStatus(), equalTo(Status.OK.getStatusCode()));
        Response response2 = translationResource.getTranslations("no");
        assertThat(response2.getStatus(), equalTo(Status.OK.getStatusCode()));
    }

    @Test
    public void should_actually_return_some_translations_for_format_language_audience() {
        Response response = translationResource.getTranslations("no");
        Map<String, String> translations = new Gson().fromJson(response.getEntity().toString(), HashMap.class);
        assertThat(translations.get("http://data.deichman.no/format#DVD"), equalTo("DVD"));
        assertThat(translations.get("http://lexvo.org/id/iso639-3/nob"), equalTo("Norsk (bokmål)"));
        assertThat(translations.get("http://data.deichman.no/audience#juvenile"), equalTo("Barn og ungdom"));
        assertThat(translations.get("http://data.deichman.no/role#performer"), equalTo("Utøver"));
    }
}

@@ -63,16 +63,58 @@
 n.Gson;%0A
+import com.google.gson.reflect.TypeToken;%0A
 import o
@@ -229,16 +229,47 @@
 Status;%0A
+import java.lang.reflect.Type;%0A
 import j
@@ -1334,32 +1334,113 @@
 slations(%22no%22);%0A
+        Type hashMapType = new TypeToken%3CHashMap%3CString, String%3E%3E()%7B%7D.getType();%0A
         Map%3CStri
@@ -1523,21 +1523,19 @@
 (), 
-H
+h
 ashMap
-.class
+Type
 );%0A 

Fix unchecked type conversion warning