package de.hft.stuttgart.citydoctor2.checks.semantics;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

import de.hft.stuttgart.citydoctor2.check.CheckError;
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.check.error.PolygonWithoutSurfaceError;
import de.hft.stuttgart.citydoctor2.datastructure.BoundarySurface;
import de.hft.stuttgart.citydoctor2.datastructure.ConcretePolygon;
import de.hft.stuttgart.citydoctor2.datastructure.Geometry;
import de.hft.stuttgart.citydoctor2.datastructure.GeometryType;
import de.hft.stuttgart.citydoctor2.datastructure.Lod;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;

public class PolygonWithoutSurfaceCheckTest {

	@Test
	public void testPolygonWithoutSurface() {
		Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD2);
		Polygon poly = new ConcretePolygon();
		geom.addPolygon(poly);
		PolygonWithoutSurfaceCheck check = new PolygonWithoutSurfaceCheck();
		poly.accept(check);
		CheckResult checkResult = poly.getCheckResult(check);
		assertNotNull(checkResult);
		assertEquals(ResultStatus.ERROR, checkResult.getResultStatus());
		assertEquals(CheckId.C_SE_POLYGON_WITHOUT_SURFACE, checkResult.getCheckIdentifier());
		CheckError error = checkResult.getError();
		assertNotNull(error);
		assertEquals(ErrorId.SE_POLYGON_WITHOUT_SURFACE, error.getErrorId()); 
		assertTrue(error instanceof PolygonWithoutSurfaceError);
		PolygonWithoutSurfaceError errorCast = (PolygonWithoutSurfaceError) error;
		assertSame(poly, errorCast.getPolygon());
	}
	
	@Test
	public void testPolygonWithSurface() {
		Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD2);
		Polygon poly = new ConcretePolygon();
		BoundarySurface bs = new BoundarySurface(null);
		bs.addGeometry(geom);
		geom.addPolygon(poly);
		PolygonWithoutSurfaceCheck check = new PolygonWithoutSurfaceCheck();
		poly.accept(check);
		CheckResult checkResult = poly.getCheckResult(check);
		assertNotNull(checkResult);
		assertEquals(ResultStatus.OK, checkResult.getResultStatus());
		assertEquals(CheckId.C_SE_POLYGON_WITHOUT_SURFACE, checkResult.getCheckIdentifier());
		CheckError error = checkResult.getError();
		assertNull(error);
	}
	
	@Test
	public void testPolygonWithWrongLod() {
		Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
		Polygon poly = new ConcretePolygon();
		BoundarySurface bs = new BoundarySurface(null);
		bs.addGeometry(geom);
		geom.addPolygon(poly);
		PolygonWithoutSurfaceCheck check = new PolygonWithoutSurfaceCheck();
		poly.accept(check);
		CheckResult checkResult = poly.getCheckResult(check);
		assertNull(checkResult);
	}

}
