package fi.nls.paikkatietoikkuna.terrainprofile;

import static org.junit.Assert.assertEquals;

import fi.nls.oskari.control.ActionException;
import fi.nls.oskari.service.ServiceException;
import java.io.IOException;
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import org.junit.Ignore;
import org.junit.Test;
import org.xml.sax.SAXException;

public class TerrainProfileServiceTest {

    @Test
    @Ignore("Depends on an outside API")
    public void offsetIsCorrect() throws IOException, ActionException, ParserConfigurationException, SAXException, ServiceException {
        String endPoint = "http://avoindata.maanmittauslaitos.fi/geoserver/wcs";
        String coverageId = "korkeusmalli_10m__korkeusmalli_10m";
        TerrainProfileService tps = new TerrainProfileService(endPoint, coverageId);
        double[] coordinates = new double[] {
                500002, 6822001,
                501003, 6821004,
                502006, 6823007,
                501003, 6822509,
                500502, 6823206
        };

        List<DataPoint> points = tps.getTerrainProfile(coordinates, 0);
        for (DataPoint p : points) {
            double e = p.getE();
            double n = p.getN();
            DataPoint single = tps.getTerrainProfile(new double[] { e, n }, 0).get(0);
            assertEquals(e, single.getE(), 0.0);
            assertEquals(n, single.getN(), 0.0);
            assertEquals(p.getAltitude(), single.getAltitude(), 0.0);
        }
    }

    @Ignore("Depends on an outside API")
    @Test
    public void interpolationWorks() throws IOException, ActionException, ParserConfigurationException, SAXException, ServiceException {
        String endPoint = "http://avoindata.maanmittauslaitos.fi/geoserver/wcs";
        String coverageId = "korkeusmalli_10m__korkeusmalli_10m";
        TerrainProfileService tps = new TerrainProfileService(endPoint, coverageId);
        double[] coordinates = new double[] {
                379134.03635691135, 6671587.856738007,
                378190.03635691135, 6672067.856738007,
                378014.03635691135, 6673267.856738007
        };

        List<DataPoint> points = tps.getTerrainProfile(coordinates, 100);
        for (DataPoint p : points) {
            double e = p.getE();
            double n = p.getN();
            DataPoint single = tps.getTerrainProfile(new double[] { e, n }, 0).get(0);
            assertEquals(e, single.getE(), 0.0);
            assertEquals(n, single.getN(), 0.0);
            assertEquals(p.getAltitude(), single.getAltitude(), 0.0);
        }
    }
}

@@ -1502,1096 +1502,6 @@
  %7D%0A%0A
-    @Ignore(%22Depends on an outside API%22)%0A    @Test%0A    public void interpolationWorks() throws IOException, ActionException, ParserConfigurationException, SAXException, ServiceException %7B%0A        String endPoint = %22http://avoindata.maanmittauslaitos.fi/geoserver/wcs%22;%0A        String coverageId = %22korkeusmalli_10m__korkeusmalli_10m%22;%0A        TerrainProfileService tps = new TerrainProfileService(endPoint, coverageId);%0A        double%5B%5D coordinates = new double%5B%5D %7B%0A                379134.03635691135, 6671587.856738007,%0A                378190.03635691135, 6672067.856738007,%0A                378014.03635691135, 6673267.856738007%0A        %7D;%0A%0A        List%3CDataPoint%3E points = tps.getTerrainProfile(coordinates, 100);%0A        for (DataPoint p : points) %7B%0A            double e = p.getE();%0A            double n = p.getN();%0A            DataPoint single = tps.getTerrainProfile(new double%5B%5D %7B e, n %7D, 0).get(0);%0A            assertEquals(e, single.getE(), 0.0);%0A            assertEquals(n, single.getN(), 0.0);%0A            assertEquals(p.getAltitude(), single.getAltitude(), 0.0);%0A        %7D%0A    %7D%0A
 %7D%0A

Remove test as it doesnt really test the interpolation method