/*-
 *  Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
 * 
 *  This file is part of CityDoctor2.
 *
 *  CityDoctor2 is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  CityDoctor2 is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with CityDoctor2.  If not, see <https://www.gnu.org/licenses/>.
 */
package de.hft.stuttgart.citydoctor2.systemtest;

import static org.junit.Assert.assertEquals;

import java.io.IOException;

import org.junit.Test;

import de.hft.stuttgart.citydoctor2.check.CheckId;
import de.hft.stuttgart.citydoctor2.check.CheckResult;
import de.hft.stuttgart.citydoctor2.check.ErrorId;
import de.hft.stuttgart.citydoctor2.check.ResultStatus;
import de.hft.stuttgart.citydoctor2.datastructure.CityDoctorModel;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
import de.hft.stuttgart.citydoctor2.parser.CityGmlParseException;
import de.hft.stuttgart.citydoctor2.parser.InvalidGmlFileException;

/**
 * 
 * @author Matthias Betz
 *
 */
public class PolygonIntersectingRingsTest {
	
	@Test
	public void testSelfIntPolygon1() throws CityGmlParseException, IOException, InvalidGmlFileException {
		CityDoctorModel c = TestUtil.loadAndCheckCityModel("src/test/resources/SimpleSolid_SrefBS.gml");
		for (Polygon p : c.getBuildings().get(0).getGeometries().get(0).getPolygons()) {
			CheckResult cr = p.getCheckResult(CheckId.C_GE_P_INTERSECTING_RINGS);
			assertEquals(ResultStatus.OK, cr.getResultStatus());
		}
	}
	
	@Test
	public void testSelfIntPolygon2() throws CityGmlParseException, IOException, InvalidGmlFileException {
		CityDoctorModel c = TestUtil.loadAndCheckCityModel("src/test/resources/SimpleSolid_SrefBS-GE-gml-PO-0001-T0002.gml");
		for (Polygon p : c.getBuildings().get(0).getGeometries().get(0).getPolygons()) {
			CheckResult cr = p.getCheckResult(CheckId.C_GE_P_INTERSECTING_RINGS);
			assertEquals(ResultStatus.OK, cr.getResultStatus());
		}
	}
	
	@Test
	public void testSelfIntPolygon3() throws CityGmlParseException, IOException, InvalidGmlFileException {
		CityDoctorModel c = TestUtil.loadAndCheckCityModel("src/test/resources/SimpleSolid_SrefBS-GE-gml-PO-0001-T0001.gml");
		Polygon p = TestUtil.getPolygonById("_Simple_BD.1_PG.2", c);
		CheckResult cr = p.getCheckResult(CheckId.C_GE_P_INTERSECTING_RINGS);
		assertEquals(ResultStatus.ERROR, cr.getResultStatus());
		assertEquals(ErrorId.GE_P_INTERSECTING_RINGS, cr.getError().getErrorId());
	}
	
	@Test
	public void testSelfIntPolygon4() throws CityGmlParseException, IOException, InvalidGmlFileException {
		CityDoctorModel c = TestUtil.loadAndCheckCityModel("src/test/resources/SimpleSolid_SrefBS-GE-gml-PO-0001-T0003.gml");
		Polygon p = TestUtil.getPolygonById("_Simple_BD.1_PG.2", c);
		CheckResult cr = p.getCheckResult(CheckId.C_GE_P_INTERSECTING_RINGS);
		assertEquals(ResultStatus.ERROR, cr.getResultStatus());
		assertEquals(ErrorId.GE_P_INTERSECTING_RINGS, cr.getError().getErrorId());
	}

}
