package com.box.l10n.mojito.service.assetExtraction.extractor;

import com.box.l10n.mojito.okapi.filters.CSVFilter;
import net.sf.okapi.filters.xliff.XLIFFFilter;
import static org.junit.Assert.assertEquals;
import org.junit.Test;

/**
 * @author aloison
 */
public class AssetPathToFilterConfigMapperTest {

    @Test
    public void testGetFilterConfigIdFromTypeWithCSV() throws Exception {

        AssetPathToFilterConfigMapper assetPathToFilterConfigMapper = new AssetPathToFilterConfigMapper();
        String filterConfigId = assetPathToFilterConfigMapper.getFilterConfigIdFromPath("/path/to/file.csv");

        assertEquals(CSVFilter.FILTER_CONFIG_ID, filterConfigId);
    }

    @Test
    public void testGetFilterConfigIdFromTypeWithXLIFF1() throws Exception {

        AssetPathToFilterConfigMapper assetPathToFilterConfigMapper = new AssetPathToFilterConfigMapper();
        String filterConfigId = assetPathToFilterConfigMapper.getFilterConfigIdFromPath("/path/to/file.xlf");

        assertEquals(AssetPathToFilterConfigMapper.XLIFF_FILTER_CONFIG_ID, filterConfigId);
    }

    @Test
    public void testGetFilterConfigIdFromTypeWithXLIFF2() throws Exception {

        AssetPathToFilterConfigMapper assetPathToFilterConfigMapper = new AssetPathToFilterConfigMapper();
        String filterConfigId = assetPathToFilterConfigMapper.getFilterConfigIdFromPath("/path/to/file.xliff");

        assertEquals(AssetPathToFilterConfigMapper.XLIFF_FILTER_CONFIG_ID, filterConfigId);
    }

    @Test(expected = UnsupportedAssetFilterTypeException.class)
    public void testGetFilterConfigIdFromTypeWithUnsupportedType() throws Exception {

        AssetPathToFilterConfigMapper assetPathToFilterConfigMapper = new AssetPathToFilterConfigMapper();
        assetPathToFilterConfigMapper.getFilterConfigIdFromPath("/path/to/file/with/unsupported/type.ext");
    }

    @Test
    public void testXLIFFFilterConfigIdConstMatchesOkapiConfigId() throws Exception {

        String okapiConfigId = new XLIFFFilter().getName();
        assertEquals(AssetPathToFilterConfigMapper.XLIFF_FILTER_CONFIG_ID, okapiConfigId);
    }
    
    @Test
    public void testGetFilterConfigIdFromTypeWithAndroidStrings() throws Exception {

        AssetPathToFilterConfigMapper assetPathToFilterConfigMapper = new AssetPathToFilterConfigMapper();
        String filterConfigId = assetPathToFilterConfigMapper.getFilterConfigIdFromPath("/path/to/strings.xml");

        assertEquals(AssetPathToFilterConfigMapper.ANDROIDSTRINGS_FILTER_CONFIG_ID, filterConfigId);
    }
    
    @Test
    public void testGetFilterConfigIdFromTypeWithMacStrings() throws Exception {

        AssetPathToFilterConfigMapper assetPathToFilterConfigMapper = new AssetPathToFilterConfigMapper();
        String filterConfigId = assetPathToFilterConfigMapper.getFilterConfigIdFromPath("/path/to/Localizable.strings");

        assertEquals(AssetPathToFilterConfigMapper.MACSTRINGS_FILTER_CONFIG_ID, filterConfigId);
    }
    
    @Test
    public void testGetFilterConfigIdFromTypeWithResx() throws Exception {

        AssetPathToFilterConfigMapper assetPathToFilterConfigMapper = new AssetPathToFilterConfigMapper();
        String filterConfigId = assetPathToFilterConfigMapper.getFilterConfigIdFromPath("/path/to/File.resx");

        assertEquals(AssetPathToFilterConfigMapper.RESX_FILTER_CONFIG_ID, filterConfigId);
    }

    @Test
    public void testGetFilterConfigIdFromTypeWithXtb() throws Exception {

        AssetPathToFilterConfigMapper assetPathToFilterConfigMapper = new AssetPathToFilterConfigMapper();
        String filterConfigId = assetPathToFilterConfigMapper.getFilterConfigIdFromPath("/path/to/File.xtb");

        assertEquals(AssetPathToFilterConfigMapper.XTB_FILTER_CONFIG_ID, filterConfigId);
    }
}

@@ -105,24 +105,75 @@
 .CSVFilter;%0A
+import com.box.l10n.mojito.okapi.filters.POFilter;%0A
 import net.s
@@ -203,24 +203,24 @@
 LIFFFilter;%0A
-
 import stati
@@ -2160,37 +2160,33 @@
 onfigId);%0A    %7D%0A
-    
 %0A
+
     @Test%0A    pu
@@ -2585,37 +2585,33 @@
 onfigId);%0A    %7D%0A
-    
 %0A
+
     @Test%0A    pu
@@ -3022,13 +3022,9 @@
   %7D%0A
-    
 %0A
+
     
@@ -3721,24 +3721,24 @@
 ile.xtb%22);%0A%0A
-
         asse
@@ -3820,11 +3820,805 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testGetFilterConfigIdFromTypeWithProperties() throws Exception %7B%0A%0A        AssetPathToFilterConfigMapper assetPathToFilterConfigMapper = new AssetPathToFilterConfigMapper();%0A        String filterConfigId = assetPathToFilterConfigMapper.getFilterConfigIdFromPath(%22/path/to/File.properties%22);%0A%0A        assertEquals(AssetPathToFilterConfigMapper.PROPERTIES_FILTER_CONFIG_ID, filterConfigId);%0A    %7D%0A%0A    @Test%0A    public void testGetFilterConfigIdFromTypeWithPo() throws Exception %7B%0A%0A        AssetPathToFilterConfigMapper assetPathToFilterConfigMapper = new AssetPathToFilterConfigMapper();%0A        String filterConfigId = assetPathToFilterConfigMapper.getFilterConfigIdFromPath(%22/path/to/File.pot%22);%0A        assertEquals(POFilter.FILTER_CONFIG_ID, filterConfigId);%0A    %7D
 %0A%7D%0A

Add tests for PO and properties files