CheckerTest.java 4.15 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.citygml4j.builder.jaxb.CityGMLBuilderException;
28
import org.citygml4j.model.citygml.ade.ADEException;
29
30
import org.citygml4j.xml.io.writer.CityGMLWriteException;
import org.junit.Rule;
31
import org.junit.Test;
32
import org.junit.rules.TemporaryFolder;
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

import de.hft.stuttgart.citydoctor2.CityDoctorValidation;
import de.hft.stuttgart.citydoctor2.datastructure.Building;
import de.hft.stuttgart.citydoctor2.datastructure.CityDoctorModel;
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 {

48
49
50
	@Rule
	public TemporaryFolder folder = new TemporaryFolder();

51
52
53
	@Test
	public void testSchematron() throws CityGmlParseException, InvalidGmlFileException {
		ValidationConfiguration config = ValidationConfiguration.loadStandardValidationConfig();
54
55
		config.getRequirements().get(Requirement.R_SE_BS_ROOF_UNFRAGMENTED.toString()).setEnabled(false);
		config.setSchematronFilePathInGlobalParameters("src/test/resources/schematronTest.xml");
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
		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()) {
			if (!b.getGmlId().getGmlString().startsWith("UUID")) {
				// if it starts with UUID the gml id was generated by citygml4j, but the file
				// does not actually contain that gml id
				// the schematron errors cannot be assigned to buildings without gml id, so they
				// are excluded here
				assertTrue(b.containsAnyError());
			}
		}
		assertFalse(model.getGlobalErrors().isEmpty());
	}

	@Test
73
	public void testChecker() throws CityGmlParseException, IOException, InvalidGmlFileException,
74
			CityGMLBuilderException, CityGMLWriteException, ADEException {
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

		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();
		}
93
94
95
	}

	@Test
96
	public void testStreaming() throws CityGmlParseException, IOException, InvalidGmlFileException,
97
			CityGMLBuilderException, CityGMLWriteException, ADEException {
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
		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();
		}
122
123
	}
}