CheckableTest.java 5.75 KB
Newer Older
Matthias Betz's avatar
Matthias Betz committed
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*-
 *  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.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.junit.Test;

import de.hft.stuttgart.citydoctor2.check.error.SchematronError;
import de.hft.stuttgart.citydoctor2.datastructure.Building;
import de.hft.stuttgart.citydoctor2.datastructure.Geometry;
import de.hft.stuttgart.citydoctor2.datastructure.GeometryType;
import de.hft.stuttgart.citydoctor2.datastructure.GmlId;
import de.hft.stuttgart.citydoctor2.datastructure.Lod;

public class CheckableTest {

	@Test
	public void testValidated() {
		Checkable c = new Checkable() {

			private static final long serialVersionUID = -8913364710109207353L;

			@Override
			public GmlId getGmlId() {
				return null;
			}

			@Override
			public void prepareForChecking() {

			}

			@Override
			public void clearMetaInformation() {

			}

			@Override
			public void clearAllContainedCheckResults() {
			}

			@Override
			public Class<? extends Checkable> getCheckClass() {
				return Building.class;
			}

		};
		Check check = new Check() {

			@Override
			public Set<Requirement> appliesToRequirements() {
				return null;
			}

			@Override
			public CheckId getCheckId() {
				return null;
			}

			@Override
			public RequirementType getType() {
				return null;
			}

			@Override
			public Check createNewInstance() {
				return null;
			}

		};
		assertFalse(c.isValidated());
		c.accept(check);
		assertTrue(c.isValidated());
		c.addCheckResult(new CheckResult(CheckId.C_GE_P_HOLE_OUTSIDE, null, null));
		assertEquals(1, c.getAllCheckResults().size());
		c.clearCheckResults();
		assertFalse(c.isValidated());
		assertTrue(c.getAllCheckResults().isEmpty());
	}

	@Test
	public void testContainsError() {
		Building b = new Building();
		Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD0);
		b.addGeometry(geom);
		assertFalse(b.containsError(CheckId.C_GE_P_HOLE_OUTSIDE));
		assertFalse(b.containsAnyError());
		geom.addCheckResult(new CheckResult(CheckId.C_GE_P_HOLE_OUTSIDE, ResultStatus.ERROR,
				new SchematronError(null, null, null, null, false)));
		assertTrue(b.containsAnyError());
		assertTrue(b.containsError(CheckId.C_GE_P_HOLE_OUTSIDE));
		geom.addCheckResult(new CheckResult(CheckId.C_GE_P_INNER_RINGS_NESTED, ResultStatus.DEPENDENCIES_NOT_MET,
				new SchematronError(null, null, null, null, false)));
		assertTrue(b.containsError(CheckId.C_GE_P_INNER_RINGS_NESTED));
		geom.addCheckResult(new CheckResult(CheckId.C_GE_P_INTERIOR_DISCONNECTED, ResultStatus.OK,
				new SchematronError(null, null, null, null, false)));
		assertFalse(b.containsError(CheckId.C_GE_P_INTERIOR_DISCONNECTED));
	}

	@Test
	public void testContainsAnyErrorNoError() {
		Building b = new Building();
		b.addCheckResult(new CheckResult(CheckId.C_GE_P_HOLE_OUTSIDE, ResultStatus.OK, null));
		assertFalse(b.containsAnyError());
	}

	@Test
	public void testContainsAnyErrorError() {
		Building b = new Building();
		b.addCheckResult(new CheckResult(CheckId.C_GE_P_HOLE_OUTSIDE, ResultStatus.ERROR,
				new SchematronError(null, null, null, null, false)));
		assertTrue(b.containsAnyError());
	}
	
	@Test
	public void testContainsAnyErrorDependencyNotMetError() {
		Building b = new Building();
		b.addCheckResult(new CheckResult(CheckId.C_GE_P_HOLE_OUTSIDE, ResultStatus.DEPENDENCIES_NOT_MET,
				new SchematronError(null, null, null, null, false)));
		assertTrue(b.containsAnyError());
	}

	@Test
	public void hasDependencyNotMetErrorNoError() {
		Building b = new Building();
		b.addCheckResult(new CheckResult(CheckId.C_GE_P_HOLE_OUTSIDE, ResultStatus.OK, null));
		assertFalse(b.hasDependencyNotMetError(CheckId.C_GE_P_HOLE_OUTSIDE));
		assertFalse(b.hasDependencyNotMetError(CheckId.C_GE_P_INNER_RINGS_NESTED));
	}

	@Test
	public void hasDependencyNotMetErrorError() {
		Building b = new Building();
		b.addCheckResult(new CheckResult(CheckId.C_GE_P_HOLE_OUTSIDE, ResultStatus.ERROR,
				new SchematronError(null, null, null, null, false)));
		assertFalse(b.hasDependencyNotMetError(CheckId.C_GE_P_HOLE_OUTSIDE));
	}

	@Test
	public void testCollectAllContainedErrors() {
		Building b = new Building();
		Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD0);
		b.addGeometry(geom);
		b.addCheckResult(new CheckResult(CheckId.C_GE_P_HOLE_OUTSIDE, ResultStatus.ERROR,
				new SchematronError(null, null, null, null, false)));
		geom.addCheckResult(new CheckResult(CheckId.C_GE_P_INNER_RINGS_NESTED, ResultStatus.DEPENDENCIES_NOT_MET,
				new SchematronError(null, null, null, null, false)));
		geom.addCheckResult(new CheckResult(CheckId.C_GE_P_INTERIOR_DISCONNECTED, ResultStatus.ERROR,
				new SchematronError(null, null, null, null, false)));
		List<CheckError> errors = new ArrayList<>();
		b.collectContainedErrors(errors);
		assertEquals(2, errors.size());
	}

	@Test
	public void testCheckClass() {
		Building b = new Building();
		assertEquals(Building.class, b.getCheckClass());
	}

}