"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "modules/plugin/mongodb/src/test/java/org/geotools/data/mongodb/complex/MongoComplexUtilitiesTest.java" between
geotools-24.0-project.zip and geotools-24.1-project.zip

About: GeoTools (The Open Source Java GIS Toolkit) is a Java code library which provides standards compliant methods for the manipulation of geospatial data.

MongoComplexUtilitiesTest.java  (geotools-24.0-project):MongoComplexUtilitiesTest.java  (geotools-24.1-project)
skipping to change at line 19 skipping to change at line 19
* License as published by the Free Software Foundation; * License as published by the Free Software Foundation;
* version 2.1 of the License. * version 2.1 of the License.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
*/ */
package org.geotools.data.mongodb.complex; package org.geotools.data.mongodb.complex;
import static org.junit.Assert.assertTrue;
import com.mongodb.BasicDBList; import com.mongodb.BasicDBList;
import com.mongodb.DBObject;
import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import org.junit.Test; import org.geotools.data.mongodb.MongoFeature;
import org.geotools.data.mongodb.MongoGeometryBuilder;
import org.geotools.data.mongodb.MongoTestSetup;
import org.geotools.data.mongodb.MongoTestSupport;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.feature.FeatureIterator;
import org.geotools.feature.FeatureTypes;
import org.geotools.feature.SchemaException;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer;
import org.geotools.referencing.CRS;
import org.locationtech.jts.geom.Geometry;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.TransformException;
public abstract class MongoComplexUtilitiesTest extends MongoTestSupport {
public class MongoComplexUtilitiesTest { protected MongoComplexUtilitiesTest(MongoTestSetup testSetup) {
super(testSetup);
}
/** /**
* Checks no exception occurs when an empty list is evaluated by the complex utilities get value * Checks no exception occurs when an empty list is evaluated by the complex utilities get value
* method. * method.
*/ */
@Test public void testGetValueEmptyList() throws IOException {
public void testGetValueEmptyList() {
final BasicDBList list = new BasicDBList(); final BasicDBList list = new BasicDBList();
Object value = MongoComplexUtilities.getValue(list, Collections.emptyMap Object value =
(), "path1.path2"); MongoComplexUtilities.getValue(list, Collections.emptyMap(), "pa
th1.path2", null);
// no exception thrown, the value is null
assertTrue(value == null); assertTrue(value == null);
} }
public void testFeatureAttributeValueIsReturnedFromJsonPath()
throws IOException, FactoryException, TransformException {
// test that in case of a jsonpath can be resolved against the feature,
// the feature value is picked up instead of the one from the DBObject
SimpleFeatureSource source = dataStore.getFeatureSource("ft3");
FeatureIterator<SimpleFeature> it = source.getFeatures().features();
GeometryCoordinateSequenceTransformer transformer =
new GeometryCoordinateSequenceTransformer();
CoordinateReferenceSystem original = source.getSchema().getCoordinateRef
erenceSystem();
CoordinateReferenceSystem target = CRS.decode("urn:x-ogc:def:crs:EPSG:6.
11.2:4326");
transformer.setMathTransform(CRS.findMathTransform(original, target, fal
se));
while (it.hasNext()) {
SimpleFeature f = it.next();
// transforming the geometry so that the SimpleFeature geometry will
be different from
// the one in the DBObject
Geometry geom = transformer.transform((Geometry) f.getDefaultGeometr
y());
f.setDefaultGeometry(geom);
Geometry geometry2 = (Geometry) MongoComplexUtilities.getValue(f, "g
eometry");
assertEquals(geom, geometry2);
MongoFeature mongoFeature = (MongoFeature) f;
Geometry dbGeom =
new MongoGeometryBuilder()
.toGeometry((DBObject) mongoFeature.getMongoObject()
.get("geometry"));
assertFalse(geometry2.equals(dbGeom));
}
}
public void testReprojectedValuesNotIgnored()
throws IOException, FactoryException, TransformException, SchemaExce
ption {
SimpleFeatureSource source = dataStore.getFeatureSource("ft3");
FeatureIterator<SimpleFeature> it = source.getFeatures().features();
GeometryCoordinateSequenceTransformer transformer =
new GeometryCoordinateSequenceTransformer();
CoordinateReferenceSystem original = source.getSchema().getCoordinateRef
erenceSystem();
CoordinateReferenceSystem target = CRS.decode("urn:x-ogc:def:crs:EPSG:6.
11.2:4326");
transformer.setMathTransform(CRS.findMathTransform(original, target, fal
se));
SimpleFeatureType ft = FeatureTypes.transform(source.getSchema(), target
);
while (it.hasNext()) {
SimpleFeature f = it.next();
Geometry geom = transformer.transform((Geometry) f.getDefaultGeometr
y());
f.setDefaultGeometry(geom);
// Mocking the case when a feature is reprojected
// and the MongoFeature in userData is copied in the newly built fea
ture
SimpleFeature rep = SimpleFeatureBuilder.build(ft, f.getAttributes()
, f.getID());
if (f.hasUserData()) {
rep.getUserData().putAll(f.getUserData());
}
Geometry geometry2 = (Geometry) MongoComplexUtilities.getValue(rep,
"geometry");
assertEquals(geom, geometry2);
}
}
} }
 End of changes. 7 change blocks. 
8 lines changed or deleted 97 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)