/*-
 *  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 static org.junit.Assert.assertNotNull;

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.Checker;
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.Geometry;
import de.hft.stuttgart.citydoctor2.parser.CityGmlParseException;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import de.hft.stuttgart.citydoctor2.parser.CityGmlParser;
import de.hft.stuttgart.citydoctor2.parser.InvalidGmlFileException;

/**
 * 
 * @author Matthias Betz
 *
 */
public class ConCompCheckTest extends TestCleanUp {
	
	@Test
	public void testConComp1() throws CityGmlParseException, IOException, InvalidGmlFileException {
		ParserConfiguration config = new ParserConfiguration(8, false);
		CityDoctorModel m = CityGmlParser.parseCityGmlFile("src/test/resources/QA-CS-CONCOMP.gml", config);
		Checker c = new Checker(m);
		c.runChecks();
		
		Geometry geom = m.getBuildings().get(0).getGeometries().get(0);
		CheckResult cr = geom.getCheckResult(CheckId.C_GE_S_MULTIPLE_CONNECTED_COMPONENTS);
		assertNotNull(cr);
		assertEquals(ResultStatus.ERROR, cr.getResultStatus());
		assertEquals(ErrorId.GE_S_MULTIPLE_CONNECTED_COMPONENTS, cr.getError().getErrorId());
	}
	
	@Test
	public void testConComp2() throws CityGmlParseException, IOException, InvalidGmlFileException {
		ParserConfiguration config = new ParserConfiguration(8, false);
		CityDoctorModel m = CityGmlParser.parseCityGmlFile("src/test/resources/QA-CS-CONCOMPGK.gml", config);
		Checker c = new Checker(m);
		c.runChecks();

		Geometry geom = m.getBuildings().get(0).getGeometries().get(0);
		CheckResult cr = geom.getCheckResult(CheckId.C_GE_S_MULTIPLE_CONNECTED_COMPONENTS);
		assertNotNull(cr);
		assertEquals(ResultStatus.ERROR, cr.getResultStatus());
		assertEquals(ErrorId.GE_S_MULTIPLE_CONNECTED_COMPONENTS, cr.getError().getErrorId());
	}

}
