package com.bericotech.clavin.resolver;

import static org.junit.Assert.*;

import org.apache.lucene.document.Document;
import org.junit.Test;

import com.bericotech.clavin.extractor.LocationOccurrence;
import com.bericotech.clavin.gazetteer.GeoName;
import com.bericotech.clavin.index.IndexDirectoryBuilder;

/*#####################################################################
 * 
 * CLAVIN (Cartographic Location And Vicinity INdexer)
 * ---------------------------------------------------
 * 
 * Copyright (C) 2012-2013 Berico Technologies
 * http://clavin.bericotechnologies.com
 * 
 * ====================================================================
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 * 
 * ====================================================================
 * 
 * ResolvedLocationTest.java
 * 
 *###################################################################*/

/**
 * Basic tests for the {@link ResolvedLocation} class, which
 * encapsulates a {@link GeoName} object representing the best match
 * between a given location name and gazetter record, along with some
 * information about the geographic entity resolution process.
 *
 */
public class ResolvedLocationTest {

    /**
     * Ensures proper performance of the overridden equals() method.
     */
    @Test
    public void testEquals() {
        // two identical sample gazetteer records from GeoNames.org
        String geonamesEntry = "4781530 Reston  Reston  Reston,Рестон   38.96872    -77.3411    P   PPL US      VA  059         58404   100 102 America/New_York    2011-05-14";
        String geonamesEntry2 = "478153 Reston  Reston  Reston,Рестон   38.96872    -77.3411    P   PPL US      VA  059         58404   100 102 America/New_York    2011-05-14";
        
        // create corresponding Lucene Documents for gazetteer records
        Document luceneDoc = IndexDirectoryBuilder.buildDoc("Nowhere", geonamesEntry, 999, (long)999);
        Document luceneDoc2 = IndexDirectoryBuilder.buildDoc("Nowhere", geonamesEntry2, 222, (long)999);
        
        // a bogus LocationOccurrence object for testing
        LocationOccurrence locationA = new LocationOccurrence("A", 0);
            
        // two ResolvedLocation objects created from same Lucene Doc, etc.
        ResolvedLocation resolvedLocation = new ResolvedLocation(luceneDoc, locationA, false);
        ResolvedLocation resolvedLocationDupe = new ResolvedLocation(luceneDoc, locationA, false);
        
        // an identical ResolvedLocation object created from the second Lucene doc
        ResolvedLocation resolvedLocation2 = new ResolvedLocation(luceneDoc2, locationA, false);
        
        assertTrue("ResolvedLocation == self", resolvedLocation.equals(resolvedLocation));
        assertFalse("ResolvedLocation =! null", resolvedLocation.equals(null));
        assertFalse("ResolvedLocation =! different class", resolvedLocation.equals(new Integer(0)));
        assertTrue("ResolvedLocation == dupe", resolvedLocation.equals(resolvedLocationDupe));
        assertFalse("ResolvedLocation != different geonameID", resolvedLocation.equals(resolvedLocation2));
    }

}

@@ -1948,33 +1948,34 @@
 %224781530
- 
+%5Ct
 Reston
-  
+%5Ct
 Reston
-  
+%5Ct
 Reston,%D0%A0
@@ -1975,35 +1975,34 @@
 eston,%D0%A0%D0%B5%D1%81%D1%82%D0%BE%D0%BD
-   
+%5Ct
 38.96872
     -77.3411
@@ -1985,36 +1985,34 @@
 %D0%BE%D0%BD%5Ct38.96872
-    
+%5Ct
 -77.3411
     P   PPL 
@@ -2003,60 +2003,48 @@
 3411
-    P   PPL US      VA  059         
+%5CtP%5CtPPL%5CtUS%5CtVA%5Ct059%5Ct
 58404
-   100 102 
+%5Ct100%5Ct102%5Ct
 Amer
@@ -2047,36 +2047,34 @@
 America/New_York
-    
+%5Ct
 2011-05-14%22;%0A   
@@ -2113,25 +2113,26 @@
 8153
- 
+%5Ct
 Reston
-  
+%5Ct
 Reston
-  
+%5Ct
 Rest
@@ -2144,19 +2144,18 @@
 %D1%81%D1%82%D0%BE%D0%BD
-   
+%5Ct
 38.96872
     
@@ -2154,20 +2154,18 @@
 6872
-    
+%5Ct
 -77.3411
     
@@ -2164,60 +2164,48 @@
 3411
-    P   PPL US      VA  059         
+%5CtP%5CtPPL%5CtUS%5CtVA%5Ct059%5Ct
 58404
-   100 102 
+%5Ct100%5Ct102%5Ct
 Amer
@@ -2216,20 +2216,18 @@
 New_York
-    
+%5Ct
 2011-05-

Use \t for geonames rows in tests