CheckerTest.java 3.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*-
 *  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.check;

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

import java.io.File;
import java.io.IOException;

27
import org.junit.Rule;
28
import org.junit.Test;
29
import org.junit.rules.TemporaryFolder;
30
31
32
33

import de.hft.stuttgart.citydoctor2.CityDoctorValidation;
import de.hft.stuttgart.citydoctor2.datastructure.Building;
import de.hft.stuttgart.citydoctor2.datastructure.CityDoctorModel;
Matthias Betz's avatar
Matthias Betz committed
34
import de.hft.stuttgart.citydoctor2.exceptions.CityDoctorWriteException;
35
36
37
38
39
40
41
42
43
44
45
import de.hft.stuttgart.citydoctor2.parser.CityGmlParseException;
import de.hft.stuttgart.citydoctor2.parser.CityGmlParser;
import de.hft.stuttgart.citydoctor2.parser.InvalidGmlFileException;

/**
 * 
 * @author Matthias Betz
 *
 */
public class CheckerTest {

46
47
48
	@Rule
	public TemporaryFolder folder = new TemporaryFolder();

49
50
51
	@Test
	public void testSchematron() throws CityGmlParseException, InvalidGmlFileException {
		ValidationConfiguration config = ValidationConfiguration.loadStandardValidationConfig();
52
53
		config.getRequirements().get(Requirement.R_SE_BS_ROOF_UNFRAGMENTED.toString()).setEnabled(false);
		config.setSchematronFilePathInGlobalParameters("src/test/resources/schematronTest.xml");
54
55
56
57
58
		CityDoctorModel model = CityGmlParser.parseCityGmlFile(
				"src/test/resources/SimpleSolid_SrefBS_SchematronTest.gml", config.getParserConfiguration());
		Checker checker = new Checker(config, model);
		checker.runChecks();
		for (Building b : model.getBuildings()) {
Matthias Betz's avatar
Matthias Betz committed
59
			if (b.getGmlId().getGmlString().equals("_Simple_BD.1")) {
60
				assertTrue(b.containsAnyError());
Matthias Betz's avatar
Matthias Betz committed
61
62
			} else {
				assertFalse(b.containsAnyError());
63
64
65
66
67
68
			}
		}
		assertFalse(model.getGlobalErrors().isEmpty());
	}

	@Test
Matthias Betz's avatar
Matthias Betz committed
69
	public void testChecker() throws CityGmlParseException, IOException, InvalidGmlFileException, CityDoctorWriteException {
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

		File f = folder.newFile();
		File f2 = folder.newFile();
		try {
			String[] args = new String[6];
			args[0] = "-in";
			args[1] = "src/test/resources/QA-CS-CONCOMP.gml";
			args[2] = "-xmlReport";
			args[3] = f.getAbsolutePath();
			args[4] = "-pdfReport";
			args[5] = f2.getAbsolutePath();
			CityDoctorValidation.main(args);
			assertTrue(f.exists());
			assertTrue(f2.exists());
		} finally {
			f.delete();
			f2.delete();
		}
88
89
90
	}

	@Test
Matthias Betz's avatar
Matthias Betz committed
91
	public void testStreaming() throws CityGmlParseException, IOException, InvalidGmlFileException, CityDoctorWriteException {
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
		File f = folder.newFile();
		File f2 = folder.newFile();
		File f3 = folder.newFile();
		try {
			String[] args = new String[10];
			args[0] = "-in";
			args[1] = "src/test/resources/testarea.gml";
			args[2] = "-config";
			args[3] = "src/test/resources/testConfigWithStreaming.yml";
			args[4] = "-pdfReport";
			args[5] = f.getAbsolutePath();
			args[6] = "-xmlReport";
			args[7] = f2.getAbsolutePath();
			args[8] = "-out";
			args[9] = f3.getAbsolutePath();
			CityDoctorValidation.main(args);
			assertTrue(f.exists());
			assertTrue(f2.exists());
			assertTrue(f3.exists());
		} finally {
			f.delete();
			f2.delete();
			f3.delete();
		}
116
117
	}
}