package org.geotools.mif;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;

import org.geotools.referencing.CRS;
import org.junit.Test;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.NoSuchAuthorityCodeException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.TransformException;

public class MIFHeaderTest {

    @Test
    public void testHeaderParsing() throws URISyntaxException, IOException, NoSuchAuthorityCodeException, FactoryException, TransformException {
        File mif = new File(getClass().getResource("kenro_alue_maarajat.MIF").toURI());
        MIFDataStore store = new MIFDataStore(mif, null);
        MIFHeader header = store.readHeader();
        assertEquals(750, header.getVersion());
        assertEquals(StandardCharsets.ISO_8859_1, header.getCharset());
        assertEquals(",", header.getDelimiter());

        assertEquals(8, header.getColumns().length);
        int i = 0;
        assertEquals("id", header.getColumns()[i++].getName());
        assertEquals("aineisto_id", header.getColumns()[i++].getName());
        assertEquals("aluekoodi", header.getColumns()[i++].getName());
        assertEquals("nimi", header.getColumns()[i++].getName());
        assertEquals("nimi_se", header.getColumns()[i++].getName());
        assertEquals("www_osoite", header.getColumns()[i++].getName());
        assertEquals("modify_user", header.getColumns()[i++].getName());
        assertEquals("modify_time", header.getColumns()[i++].getName());
    }

    @Test
    public void testCoordSysWithExplicitBoundsTypeCode() throws URISyntaxException, IOException, NoSuchAuthorityCodeException, FactoryException, TransformException {
        File mif = new File(getClass().getResource("has_explicit_bounds.mif").toURI());
        MIFDataStore store = new MIFDataStore(mif, null);
        MIFHeader header = store.readHeader();
        assertEquals(750, header.getVersion());
        assertEquals(StandardCharsets.ISO_8859_1, header.getCharset());
        CoordinateReferenceSystem actual = header.getCoordSys();
        CoordinateReferenceSystem expected = CRS.decode("EPSG:3067", true);
        assertTrue(CRS.equalsIgnoreMetadata(expected, actual));
    }

}

@@ -53,24 +53,29 @@
 ssert.assert
+Array
 Equals;%0Aimpo
@@ -107,20 +107,22 @@
 t.assert
-True
+Equals
 ;%0A%0Aimpor
@@ -476,16 +476,72 @@
 System;%0A
+import org.opengis.referencing.operation.MathTransform;%0A
 import o
@@ -2349,44 +2349,55 @@
     
-CoordinateReferenceSystem expected =
+MathTransform t = CRS.findMathTransform(actual,
  CRS
@@ -2422,16 +2422,17 @@
 %22, true)
+)
 ;%0A      
@@ -2437,61 +2437,210 @@
     
-assertTrue(CRS.equalsIgnoreMetadata(expected, actual)
+double%5B%5D src = new double%5B2%5D;%0A        double%5B%5D dst = new double%5B2%5D;%0A        src%5B0%5D = 357517.2;%0A        src%5B1%5D = 6860602.8;%0A        t.transform(src, 0, dst, 0, 1);%0A        assertArrayEquals(src, dst, 0.0
 );%0A 

Fix test because CRS.equalsIgnoreMetadata actually returns false, instead "prove it" by transforming a coordinate and making sure it doesnt actually change