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

import org.citygml4j.model.citygml.building.RoofSurface;
import org.citygml4j.model.gml.basicTypes.Code;
import org.junit.Test;

import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;

/**
 * 
 * @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);
		
		Building copy = b.copy();
		assertNotSame(b, copy);
		
		assertEquals(b.getGmlId(), copy.getGmlId());
		assertNotSame(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);
		
		assertNotSame(b.getGmlObject(), copy.getGmlObject());
		assertEquals(b.getGmlObject().getFunction().get(0).getValue(), copy.getGmlObject().getFunction().get(0).getValue());
	}
	
	private org.citygml4j.model.citygml.building.Building createCityGmlBuilding() {
		org.citygml4j.model.citygml.building.Building b = new org.citygml4j.model.citygml.building.Building();
		b.addFunction(new Code("2349"));
		b.setId("test");
		return b;
	}

}