DATACMNS-482 - Added serialization support for Geospatial Types.
Added Serializable marker interface to Shape to make all geospatial types serializable. Changed equals implementation in GeoResults to use equals(…) instead of reference equality. Original pull request: #77.
This commit is contained in:
committed by
Oliver Gierke
parent
9bd8e4db81
commit
a30068c02d
@@ -19,6 +19,7 @@ import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.util.SerializationUtils;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link Box}.
|
||||
@@ -61,4 +62,14 @@ public class BoxUnitTests {
|
||||
|
||||
assertThat(first.toString(), is("Box [Point [x=1.000000, y=1.000000], Point [x=2.000000, y=2.000000]]"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-482
|
||||
*/
|
||||
@Test
|
||||
public void testSerialization() {
|
||||
|
||||
Box serialized = (Box) SerializationUtils.deserialize(SerializationUtils.serialize(first));
|
||||
assertThat(serialized, is(first));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.util.SerializationUtils;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link Circle}.
|
||||
@@ -70,4 +71,16 @@ public class CircleUnitTests {
|
||||
|
||||
assertThat(new Circle(1, 1, 1).toString(), is("Circle: [center=Point [x=1.000000, y=1.000000], radius=1.0]"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-482
|
||||
*/
|
||||
@Test
|
||||
public void testSerialization() {
|
||||
|
||||
Circle circle = new Circle(1, 1, 1);
|
||||
|
||||
Circle serialized = (Circle) SerializationUtils.deserialize(SerializationUtils.serialize(circle));
|
||||
assertThat(serialized, is(circle));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import static org.junit.Assert.*;
|
||||
import static org.springframework.data.geo.Metrics.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.util.SerializationUtils;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link Distance}.
|
||||
@@ -124,4 +125,16 @@ public class DistanceUnitTests {
|
||||
assertThat(new Distance(6.21371256214785, MILES).in(KILOMETERS).toString(),
|
||||
is(new Distance(10, KILOMETERS).toString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-482
|
||||
*/
|
||||
@Test
|
||||
public void testSerialization() {
|
||||
|
||||
Distance dist = new Distance(10, KILOMETERS);
|
||||
|
||||
Distance serialized = (Distance) SerializationUtils.deserialize(SerializationUtils.serialize(dist));
|
||||
assertThat(serialized, is(dist));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.util.SerializationUtils;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link GeoResult}.
|
||||
@@ -64,4 +65,17 @@ public class GeoResultUnitTests {
|
||||
public void rejectsNullContent() {
|
||||
new GeoResult(null, new Distance(2.5));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-482
|
||||
*/
|
||||
@Test
|
||||
public void testSerialization() {
|
||||
|
||||
GeoResult<String> result = new GeoResult<String>("test", new Distance(2));
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
GeoResult<String> serialized = (GeoResult<String>) SerializationUtils.deserialize(SerializationUtils.serialize(result));
|
||||
assertThat(serialized, is(result));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import static org.junit.Assert.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.util.SerializationUtils;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link GeoResults}.
|
||||
@@ -43,4 +44,20 @@ public class GeoResultsUnitTests {
|
||||
|
||||
assertThat(geoResults.getAverageDistance(), is(new Distance(3.5)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-482
|
||||
*/
|
||||
@Test
|
||||
public void testSerialization() {
|
||||
|
||||
GeoResult<String> result = new GeoResult<String>("test", new Distance(2));
|
||||
@SuppressWarnings("unchecked")
|
||||
GeoResults<String> geoResults = new GeoResults<String>(Arrays.asList(result));
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
GeoResults<String> serialized = (GeoResults<String>) SerializationUtils.deserialize(SerializationUtils
|
||||
.serialize(geoResults));
|
||||
assertThat(serialized, is(geoResults));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.util.SerializationUtils;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link Point}.
|
||||
@@ -55,4 +56,15 @@ public class PointUnitTests {
|
||||
assertThat(new Point(1.5, 1.5).toString(), is("Point [x=1.500000, y=1.500000]"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-482
|
||||
*/
|
||||
@Test
|
||||
public void testSerialization() {
|
||||
|
||||
Point point = new Point(1.5, 1.5);
|
||||
|
||||
Point serialized = (Point) SerializationUtils.deserialize(SerializationUtils.serialize(point));
|
||||
assertThat(serialized, is(point));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.util.SerializationUtils;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link Polygon}.
|
||||
@@ -73,4 +74,16 @@ public class PolygonUnitTests {
|
||||
assertThat(new Polygon(third, second, first).toString(),
|
||||
is("Polygon: [Point [x=3.000000, y=3.000000],Point [x=2.000000, y=2.000000],Point [x=1.000000, y=1.000000]]"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-482
|
||||
*/
|
||||
@Test
|
||||
public void testSerialization() {
|
||||
|
||||
Polygon polygon = new Polygon(third, second, first);
|
||||
|
||||
Polygon serialized = (Polygon) SerializationUtils.deserialize(SerializationUtils.serialize(polygon));
|
||||
assertThat(serialized, is(polygon));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user