Skip to content

Commit 2400c44

Browse files
committed
add more geo tests, fix the way json-property elements are serialized
1 parent 486e269 commit 2400c44

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

src/main/java/com/marklogic/client/query/StructuredQueryBuilder.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,10 +1814,9 @@ void innerSerialize(XMLStreamWriter serializer) throws Exception {
18141814
serializer.writeEndElement();
18151815
}
18161816
}
1817-
class JSONPropertyImpl extends ElementImpl implements JSONProperty {
1817+
class JSONPropertyImpl extends IndexImpl implements JSONProperty {
18181818
String name;
18191819
JSONPropertyImpl(String name) {
1820-
super(name);
18211820
this.name = name;
18221821
}
18231822
@Override
@@ -1848,12 +1847,20 @@ class GeoElementImpl extends IndexImpl implements GeospatialIndex {
18481847
}
18491848
@Override
18501849
void innerSerialize(XMLStreamWriter serializer) throws Exception {
1851-
if (parent != null) {
1850+
if (parent != null && parent instanceof ElementImpl) {
18521851
ElementImpl parentImpl = (ElementImpl) parent;
18531852
serializeNamedIndex(serializer, "parent", parentImpl.qname, parentImpl.name);
1853+
} else if (parent != null && parent instanceof IndexImpl) {
1854+
IndexImpl parentImpl = (IndexImpl) parent;
1855+
parentImpl.innerSerialize(serializer);
1856+
}
1857+
if ( element instanceof ElementImpl ) {
1858+
ElementImpl elementImpl = (ElementImpl) element;
1859+
serializeNamedIndex(serializer, "element", elementImpl.qname, elementImpl.name);
1860+
} else if ( element instanceof IndexImpl ) {
1861+
IndexImpl indexImpl = (IndexImpl) element;
1862+
indexImpl.innerSerialize(serializer);
18541863
}
1855-
ElementImpl elementImpl = (ElementImpl) element;
1856-
serializeNamedIndex(serializer, "element", elementImpl.qname, elementImpl.name);
18571864
}
18581865
}
18591866
class GeoElementPairImpl extends IndexImpl implements GeospatialIndex {

src/test/java/com/marklogic/client/test/BulkReadWriteTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ public static City newCity(String line, Map<String, Country> countries) {
300300
.setAlternateNames( fields[3].split(",") );
301301
if ( !fields[4].equals("") ) city.setLatitude( Double.parseDouble(fields[4]) );
302302
if ( !fields[5].equals("") ) city.setLongitude( Double.parseDouble(fields[5]) );
303+
if ( !fields[4].equals("") && !fields[5].equals("") ) {
304+
city.setLatLong( fields[4] + " " + fields[5] );
305+
}
303306
if ( !fields[14].equals("") ) city.setPopulation( Long.parseLong(fields[14]) );
304307
if ( !fields[16].equals("") ) city.setElevation( Integer.parseInt(fields[16]) );
305308
if ( !fields[8].equals("") ) {

src/test/java/com/marklogic/client/test/City.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class City {
2727
private String[] alternateNames;
2828
private double latitude;
2929
private double longitude;
30+
private String latLong;
3031
private String countryIsoCode;
3132
private String countryName;
3233
private String continent;
@@ -90,6 +91,15 @@ public City setLongitude(double longitude) {
9091
return this;
9192
}
9293

94+
public String getLatLong() {
95+
return latLong;
96+
}
97+
98+
public City setLatLong(String latLong) {
99+
this.latLong = latLong;
100+
return this;
101+
}
102+
93103
public String getCountryIsoCode() {
94104
return countryIsoCode;
95105
}

src/test/java/com/marklogic/client/test/PojoFacadeTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,38 @@ public void testC_QueryPojos() throws Exception {
132132
assertEquals("Failed to find number of records expected", 11, numRead);
133133
assertEquals("PojoPage failed to report number of records expected", numRead, page.size());
134134

135+
query = qb.geospatial(
136+
qb.geoField("latLong"),
137+
qb.circle(-34, -58, 1)
138+
);
139+
page = repository.search(query, 1);
140+
iterator = page.iterator();
141+
numRead = 0;
142+
while ( iterator.hasNext() ) {
143+
City city = iterator.next();
144+
numRead++;
145+
}
146+
// this currently doesn't work even in the cts:search layer
147+
// when this works we'll find out how many we expect
148+
assertEquals("Failed to find number of records expected", -1, numRead);
149+
assertEquals("PojoPage failed to report number of records expected", numRead, page.size());
150+
151+
query = qb.geospatial(
152+
qb.geoPath("latLong"),
153+
qb.circle(-34, -58, 100)
154+
);
155+
page = repository.search(query, 1);
156+
iterator = page.iterator();
157+
numRead = 0;
158+
while ( iterator.hasNext() ) {
159+
City city = iterator.next();
160+
numRead++;
161+
}
162+
// this currently doesn't work even in the cts:search layer
163+
// when this works we'll find out how many we expect
164+
assertEquals("Failed to find number of records expected", -1, numRead);
165+
assertEquals("PojoPage failed to report number of records expected", numRead, page.size());
166+
135167
query = qb.geospatial(
136168
qb.geoPair("latitude", "longitude"),
137169
qb.circle(-34, -58, 100)

0 commit comments

Comments
 (0)