/** Tests the specified instance. */ @Test public void test() { final StringBuilder sb = new StringBuilder(); int fail = 0; for (final Object[] qu : queries) { final boolean correct = qu.length == 3; final String query = qu[correct ? 2 : 1].toString(); final Value cmp = correct ? (Value) qu[1] : null; final QueryProcessor qp = new QueryProcessor(query, context); try { final Value val = qp.value(); if (!correct || !new DeepCompare().equal(val, cmp)) { sb.append("[" + qu[0] + "] " + query); String s = correct && cmp.size() != 1 ? "#" + cmp.size() : ""; sb.append("\n[E" + s + "] "); if (correct) { final String cp = cmp.toString(); sb.append('\''); sb.append(cp.length() > 1000 ? cp.substring(0, 1000) + "..." : cp); sb.append('\''); } else { sb.append("error"); } final TokenBuilder types = new TokenBuilder(); for (final Item it : val) types.add(it.type.toString()).add(" "); s = val.size() == 1 ? "" : "#" + val.size(); sb.append("\n[F" + s + "] '" + val + "', " + types + details() + '\n'); ++fail; } } catch (final Exception ex) { final String msg = ex.getMessage(); if (correct || msg == null || msg.contains("mailman")) { final String cp = correct && cmp.data() != null ? cmp.toString() : "()"; sb.append( "[" + qu[0] + "] " + query + "\n[E] " + cp + "\n[F] " + (msg == null ? Util.className(ex) : msg.replaceAll("\r\n?|\n", " ")) + ' ' + details() + '\n'); ex.printStackTrace(); ++fail; } } finally { qp.close(); } } if (fail != 0) fail(fail + " Errors. [E] = expected, [F] = found:\n" + sb.toString().trim()); }
/** * Test created to check that we effectively retrieve a good representation of empty * multipolygons. indeed, a NullPointerException used to happen... * * @throws Exception */ @Test public void testGeometryCollectionStringRepresentation() throws Exception { GeometryCollection mp = gf.createMultiPolygon(new Polygon[] {}); Value val = ValueFactory.createValue(mp); String str = val.toString(); assertEquals(str, "MULTIPOLYGON EMPTY"); Polygon poly = gf.createPolygon(gf.createLinearRing(new Coordinate[] {}), new LinearRing[] {}); assertTrue(poly.isEmpty()); mp = gf.createMultiPolygon( new Polygon[] { poly, }); val = ValueFactory.createValue(mp); str = val.toString(); assertNotNull(str); Polygon polyBis = gf.createPolygon( gf.createLinearRing( new Coordinate[] { new Coordinate(0, 0, 0), new Coordinate(1, 1, 0), new Coordinate(3, 4, 0), new Coordinate(0, 0, 0), }), new LinearRing[] {}); mp = gf.createMultiPolygon(new Polygon[] {poly, polyBis}); val = ValueFactory.createValue(mp); str = val.toString(); assertNotNull(str); GeometryCollection coll = gf.createGeometryCollection( new Geometry[] { gf.createPolygon(gf.createLinearRing(new Coordinate[] {}), new LinearRing[] {}), gf.createPolygon( gf.createLinearRing( new Coordinate[] { new Coordinate(0, 0, 0), new Coordinate(1, 1, 0), new Coordinate(3, 4, 0), new Coordinate(0, 0, 0), }), new LinearRing[] {}) }); mp = gf.createGeometryCollection(new Geometry[] {poly, coll, polyBis}); val = ValueFactory.createValue(mp); str = val.toString(); assertNotNull(str); }
@Test public void testToStringFromStringCoherente() throws Exception { Value v = ValueFactory.createValue(1300.5566d); assertTrue( (v.equals(ValueFactory.createValueByType(v.toString(), Type.DOUBLE))).getAsBoolean()); v = ValueFactory.createValue(13.5f); assertTrue((v.equals(ValueFactory.createValueByType(v.toString(), Type.FLOAT))).getAsBoolean()); v = ValueFactory.createValue(1300L); assertTrue((v.equals(ValueFactory.createValueByType(v.toString(), Type.LONG))).getAsBoolean()); v = ValueFactory.createValue(false); assertTrue( (v.equals(ValueFactory.createValueByType(v.toString(), Type.BOOLEAN))).getAsBoolean()); v = ValueFactory.createValue("hola"); assertTrue( (v.equals(ValueFactory.createValueByType(v.toString(), Type.STRING))).getAsBoolean()); Calendar c = Calendar.getInstance(); // month is 0-based c.set(1980, 8, 5, 0, 0, 0); c.set(Calendar.MILLISECOND, 0); v = ValueFactory.createValue(d); assertTrue((v.equals(ValueFactory.createValueByType(v.toString(), Type.DATE))).getAsBoolean()); v = ValueFactory.createValue(15); assertTrue((v.equals(ValueFactory.createValueByType(v.toString(), Type.INT))).getAsBoolean()); v = ValueFactory.createValue((short) 13); assertTrue((v.equals(ValueFactory.createValueByType(v.toString(), Type.SHORT))).getAsBoolean()); v = ValueFactory.createValue((byte) 5); assertTrue((v.equals(ValueFactory.createValueByType(v.toString(), Type.BYTE))).getAsBoolean()); v = ValueFactory.createValue(new byte[] {4, 5, 7, 8, 3, 8}); assertTrue( (v.equals(ValueFactory.createValueByType(v.toString(), Type.BINARY))).getAsBoolean()); c.set(1970, 0, 1, 22, 45, 20); c.set(Calendar.MILLISECOND, 0); Time t = new Time(c.getTime().getTime()); v = ValueFactory.createValue(t); assertTrue((v.equals(ValueFactory.createValueByType(v.toString(), Type.TIME))).getAsBoolean()); v = ValueFactory.createValue(new Timestamp(2465)); assertTrue( (v.equals(ValueFactory.createValueByType(v.toString(), Type.TIMESTAMP))).getAsBoolean()); }