<commit_before>package th.or.nectec.tanrabad.survey.service.json;

import com.bluelinelabs.logansquare.LoganSquare;
import org.joda.time.DateTime;
import org.junit.Test;
import th.or.nectec.tanrabad.entity.Building;
import th.or.nectec.tanrabad.entity.Survey;
import th.or.nectec.tanrabad.entity.User;
import th.or.nectec.tanrabad.entity.field.Location;
import th.or.nectec.tanrabad.entity.lookup.ContainerType;
import th.or.nectec.tanrabad.survey.utils.ResourceFile;

import java.util.UUID;

import static org.junit.Assert.assertEquals;

public class JsonSurveyTest {

    @Test
    public void testParseToJsonString() throws Exception {
        JsonSurvey jsonSurvey = LoganSquare.parse(ResourceFile.read("survey.json"), JsonSurvey.class);

        assertEquals("6af5225b-5642-10fb-a3a0-4e000a842583", jsonSurvey.surveyID.toString());
        assertEquals(5, jsonSurvey.personCount);
        assertEquals(39.745675, jsonSurvey.location.getLatitude(), 0);
        assertEquals(-73.150055, jsonSurvey.location.getLongitude(), 0);
        assertEquals("2015-01-11T03:00:00.000Z", jsonSurvey.createTimestamp);
        assertEquals("dcp-user", jsonSurvey.surveyor);

        assertEquals(1, jsonSurvey.details.get(0).containerLocationID);
        assertEquals(1, jsonSurvey.details.get(0).containerType);
        assertEquals(24, jsonSurvey.details.get(0).containerCount);
        assertEquals(10, jsonSurvey.details.get(0).containerHaveLarva);
    }

    @Test
    public void testParseSurveyDataToJsonString() throws Exception {
        Survey survey = new Survey.Builder(UUID.fromString("1619f46f-6a70-4049-82ec-69dad861a5c6"), stubUser())
                .addIndoorDetail(UUID.fromString("772c4938-b910-11e5-a0c5-aabbccddeeff"), new ContainerType(1, "น้ำใช้"), 10, 5)
                .addOutdoorDetail(UUID.fromString("772c4938-b917-11e5-a0c5-aabbccddeeff"), new ContainerType(2, "น้ำดื่ม"), 7, 5)
                .setBuilding(stubBuilding())<commit_msg>เปลี่ยนชื่อmethodจาก testParseToJsonString เป็น testParseFromJsonString เพื่อให้ตรงกับการทำงานภายใน method<commit_after>package th.or.nectec.tanrabad.survey.service.json;

import com.bluelinelabs.logansquare.LoganSquare;
import org.joda.time.DateTime;
import org.junit.Test;
import th.or.nectec.tanrabad.entity.Building;
import th.or.nectec.tanrabad.entity.Survey;
import th.or.nectec.tanrabad.entity.User;
import th.or.nectec.tanrabad.entity.field.Location;
import th.or.nectec.tanrabad.entity.lookup.ContainerType;
import th.or.nectec.tanrabad.survey.utils.ResourceFile;

import java.util.UUID;

import static org.junit.Assert.assertEquals;

public class JsonSurveyTest {

    @Test
    public void testParseFromJsonString() throws Exception {
        JsonSurvey jsonSurvey = LoganSquare.parse(ResourceFile.read("survey.json"), JsonSurvey.class);

        assertEquals("6af5225b-5642-10fb-a3a0-4e000a842583", jsonSurvey.surveyID.toString());
        assertEquals(5, jsonSurvey.personCount);
        assertEquals(39.745675, jsonSurvey.location.getLatitude(), 0);
        assertEquals(-73.150055, jsonSurvey.location.getLongitude(), 0);
        assertEquals("2015-01-11T03:00:00.000Z", jsonSurvey.createTimestamp);
        assertEquals("dcp-user", jsonSurvey.surveyor);

        assertEquals(1, jsonSurvey.details.get(0).containerLocationID);
        assertEquals(1, jsonSurvey.details.get(0).containerType);
        assertEquals(24, jsonSurvey.details.get(0).containerCount);
        assertEquals(10, jsonSurvey.details.get(0).containerHaveLarva);
    }

    @Test
    public void testParseSurveyDataToJsonString() throws Exception {
        Survey survey = new Survey.Builder(UUID.fromString("1619f46f-6a70-4049-82ec-69dad861a5c6"), stubUser())
                .addIndoorDetail(UUID.fromString("772c4938-b910-11e5-a0c5-aabbccddeeff"), new ContainerType(1, "น้ำใช้"), 10, 5)
                .addOutdoorDetail(UUID.fromString("772c4938-b917-11e5-a0c5-aabbccddeeff"), new ContainerType(2, "น้ำดื่ม"), 7, 5)
                .setBuilding(stubBuilding())
{'fraction_non_alphanumeric': 0.12808988764044943, 'fraction_numerical': 0.06392009987515605, 'mean_word_length': 4.398921832884097, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '985576', 'n_tokens_mistral': 1537, 'n_tokens_neox': 1417, 'n_words': 172}