MyPlacesFeaturesWFSTRequestBuilder extends WFSTRequestBuilder { public static List<MyPlace> parseMyPlaces(String input, boolean shouldSetId) throws JSONException { JSONObject featureCollection = new JSONObject(input); String srsName = JSONHelper.optString(featureCollection, "srsName"); int srid = getSrid(srsName, 0); JSONArray features = featureCollection.getJSONArray("features"); final int n = features.length(); List<MyPlace> myPlaces = new ArrayList<>(n); for (int i = 0; i < n; i++) { JSONObject feature = features.getJSONObject(i); myPlaces.add(parseMyPlace(feature, shouldSetId, srid)); } return myPlaces; }  static List<MyPlace> parseMyPlaces(String input, boolean shouldSetId); static MyPlace parseMyPlace(JSONObject feature, boolean shouldSetId, int srid); static void getMyPlacesByCategoryId(OutputStream out, String crs,
            long categoryId); static void getMyPlacesByUserId(OutputStream out, String crs,
            String uuid); static void getMyPlacesById(OutputStream out, String crs,
            String[] ids); static void insertMyPlaces(OutputStream out, List<MyPlace> places); static void updateMyPlaces(OutputStream out, List<MyPlace> places); static void deleteMyPlaces(OutputStream out, long[] ids); static String prefixId(long id); static String[] prefixIds(long[] ids); static long removePrefixFromId(String prefixed); static long[] removePrefixFromIds(String[] prefixed);  }
@Test public void testParseMyPlaces() throws Exception { String payload = getInput(PAYLOAD); boolean shouldSetId = false; List<MyPlace> myPlaces = MyPlacesFeaturesWFSTRequestBuilder.parseMyPlaces(payload, shouldSetId); assertEquals(2, myPlaces.size()); MyPlace myPlace1 = myPlaces.get(0); assertEquals(1, myPlace1.getCategoryId()); assertEquals("id should not be set because we set shouldSetId to false", 0, myPlace1.getId()); assertEquals("name", myPlace1.getName()); assertEquals("place description", myPlace1.getDesc()); assertEquals("url", myPlace1.getLink()); assertEquals("attention text", myPlace1.getAttentionText()); assertEquals("image url", myPlace1.getImageUrl()); Geometry g = myPlace1.getGeometry(); assertEquals("Point", g.getGeometryType()); Point p = (Point) g; assertEquals(381863.4646715279, p.getX(), 0.00000001); assertEquals(6679150.155217625, p.getY(), 0.00000001); MyPlace myPlace2 = myPlaces.get(1); assertEquals(1, myPlace2.getCategoryId()); assertEquals("id should not be set because we set shouldSetId to false", 0, myPlace1.getId()); assertEquals("name2", myPlace2.getName()); assertEquals("place description2", myPlace2.getDesc()); assertEquals("url2", myPlace2.getLink()); assertEquals("attention text2", myPlace2.getAttentionText()); assertEquals("image url2", myPlace2.getImageUrl()); g = myPlace2.getGeometry(); assertEquals("MultiLineString", g.getGeometryType()); MultiLineString ml = (MultiLineString) g; assertEquals(2, ml.getNumGeometries()); LineString ls = (LineString) ml.getGeometryN(0); assertEquals(3, ls.getNumPoints()); p = ls.getPointN(0); assertEquals(381863.4646715279, p.getX(), 0.00000001); assertEquals(6679150.155217625, p.getY(), 0.00000001); p = ls.getPointN(1); assertEquals(384807.4646715279, p.getX(), 0.00000001); assertEquals(6682990.155217625, p.getY(), 0.00000001); p = ls.getPointN(2); assertEquals(386599.4646715279, p.getX(), 0.00000001); assertEquals(6678510.155217625, p.getY(), 0.00000001); ls = (LineString) ml.getGeometryN(1); assertEquals(2, ls.getNumPoints()); p = ls.getPointN(0); assertEquals(378215.4646715279, p.getX(), 0.00000001); assertEquals(6676878.155217625, p.getY(), 0.00000001); p = ls.getPointN(1); assertEquals(381639.4646715279, p.getX(), 0.00000001); assertEquals(6678318.155217625, p.getY(), 0.00000001); }
@Test public void testParseMyPlacesWithIds() throws Exception { String payload = getInput(PAYLOAD); boolean shouldSetId = true; List<MyPlace> myPlaces = MyPlacesFeaturesWFSTRequestBuilder.parseMyPlaces(payload, shouldSetId); assertEquals("ids should be set", 123L, myPlaces.get(0).getId()); assertEquals("ids larger than Integer.MAX work", 9876543210123456L, myPlaces.get(1).getId()); }