BuildingTest.java 4.3 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
/*-
 *  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.datastructure;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;

Matthias Betz's avatar
Matthias Betz committed
26
import org.citygml4j.core.model.construction.RoofSurface;
27
import org.junit.Test;
Matthias Betz's avatar
Matthias Betz committed
28
import org.xmlobjects.gml.model.basictypes.Code;
29
30

import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
Matthias Betz's avatar
Matthias Betz committed
31
import de.hft.stuttgart.citydoctor2.utils.Copy;
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

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

	@Test
	public void testCopy() {
		Building b = new Building();
		b.setGmlId(new GmlId("testId"));
		
		Vertex v1 = new Vertex(1, 0, 0);
		Vertex v2 = new Vertex(2, 0, 0);
		LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
		ConcretePolygon p = new ConcretePolygon();
		p.setExteriorRing(lr);
		lr.addVertex(v1);
		lr.addVertex(v2);
		lr.addVertex(v1);
		Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD0);
		geom.addPolygon(p);
		geom.updateEdgesAndVertices();
		b.addGeometry(geom);
		
		b.setCityGmlBuilding(createCityGmlBuilding());
		RoofSurface rs = new RoofSurface();
		rs.setId("testRoof");
		BoundarySurface surface = new BoundarySurface(SurfaceFeatureType.BUILDING, BoundarySurfaceType.ROOF, rs);
		Geometry geomSurface = new Geometry(GeometryType.MULTI_SURFACE, Lod.LOD2);
		geomSurface.addPolygon(new LinkedPolygon(p, geomSurface));
		geomSurface.updateEdgesAndVertices();
		surface.addGeometry(geomSurface);
		b.addBoundarySurface(surface);
		
Matthias Betz's avatar
Matthias Betz committed
68
		Building copy = Copy.copy(b);
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
		assertNotSame(b, copy);
		
		assertEquals(b.getGmlId(), copy.getGmlId());
		
		Geometry copyGeom = copy.getGeometries().get(0);
		assertNotSame(geom, copyGeom);
		
		Edge edge = geom.getEdges().get(0);
		Edge copyEdge = copyGeom.getEdges().get(0);
		
		assertEquals(edge, copyEdge);
		assertNotSame(edge, copyEdge);
		
		Polygon copyPolygon = copyGeom.getPolygons().get(0);
		assertNotSame(p, copyPolygon);
		
		LinearRing copyRing = copyPolygon.getExteriorRing();
		assertNotSame(lr, copyRing);
		
		BoundarySurface copyBs = copy.getBoundarySurfaces().get(0);
		assertNotSame(surface, copyBs);
		assertEquals(surface.getType(), copyBs.getType());
		assertEquals(surface.getFeatureType(), copyBs.getFeatureType());
		
		Geometry copyBsGeom = copyBs.getGeometries().get(0);
		assertNotSame(geomSurface, copyBsGeom);
		
		Polygon copyLinkedPoly = copyBsGeom.getPolygons().get(0);
		assertNotSame(geomSurface.getPolygons().get(0), copyLinkedPoly);
		LinearRing copyExtRing = copyLinkedPoly.getExteriorRing();
		assertSame(copyExtRing, copyPolygon.getExteriorRing());
		
		Vertex copyV1 = copyExtRing.getVertices().get(0);
		assertSame(copyV1, copyExtRing.getVertices().get(2));
		assertEquals(v1, copyV1);
		assertNotSame(v1, copyV1);
		assertEquals(v2, copyExtRing.getVertices().get(1));
		assertNotSame(v2, copyExtRing.getVertices().get(1));
		assertEquals(v1, copyExtRing.getVertices().get(2));
		Polygon adjacentPoly = v1.getAdjacentPolygons(geom).iterator().next();
		Polygon copyAdjacentPoly = copyV1.getAdjacentPolygons(copyGeom).iterator().next();
		assertNotNull(copyAdjacentPoly);
		assertNotSame(adjacentPoly, copyAdjacentPoly);
		
Matthias Betz's avatar
Matthias Betz committed
113
		assertEquals(b.getGmlObject().getFunctions().get(0).getValue(), copy.getGmlObject().getFunctions().get(0).getValue());
114
115
	}
	
Matthias Betz's avatar
Matthias Betz committed
116
117
118
	private org.citygml4j.core.model.building.Building createCityGmlBuilding() {
		org.citygml4j.core.model.building.Building b = new org.citygml4j.core.model.building.Building();
		b.getFunctions().add(new Code("2349"));
119
120
121
122
123
		b.setId("test");
		return b;
	}

}