Example #1
0
  /**
   * Test sending of HTTP GET requests.
   *
   * @throws Exception exception
   */
  @Test
  public void postGet() throws Exception {
    // GET1 - just send a GET request
    try (final QueryProcessor qp =
        new QueryProcessor(
            _HTTP_SEND_REQUEST.args("<http:request method='get' href='" + REST_ROOT + "'/>"),
            ctx)) {
      final Value v = qp.value();
      checkResponse(v, 2, HttpURLConnection.HTTP_OK);

      assertEquals(NodeType.DOC, v.itemAt(1).type);
    }

    // GET2 - with override-media-type='text/plain'
    try (final QueryProcessor qp =
        new QueryProcessor(
            _HTTP_SEND_REQUEST.args(
                "<http:request method='get' override-media-type='text/plain'/>", REST_ROOT),
            ctx)) {
      final Value v = qp.value();
      checkResponse(v, 2, HttpURLConnection.HTTP_OK);

      assertEquals(AtomType.STR, v.itemAt(1).type);
    }

    // Get3 - with status-only='true'
    try (final QueryProcessor qp =
        new QueryProcessor(
            _HTTP_SEND_REQUEST.args("<http:request method='get' status-only='true'/>", REST_ROOT),
            ctx)) {
      checkResponse(qp.value(), 1, HttpURLConnection.HTTP_OK);
    }
  }
Example #2
0
  /** Test of removeHandlerForEvent method, of class HexEventRegister. */
  @Test
  public void testRemoveHandlerForEvent() {
    Class type = HexEvent.class;

    final Value v = new Value();
    v.value = "fix";

    HexEventHandler handler =
        new HexEventHandler() {
          @Override
          public void handle(HexEvent event) throws Exception {
            v.value = "changed";
          }
        };

    String[] names = null;
    HexEventRegister instance = HexEventRegister.getInstance();

    instance.registerHandlerForEvent(type, handler, names);

    instance.triggerEvent(new HexEvent("one"));

    assertEquals(v.value, "changed");

    v.value = "fix";

    instance.removeHandlerForEvent(type, handler.getID());

    instance.triggerEvent(new HexEvent("one"));

    assertEquals(v.value, "fix");
  }
Example #3
0
  private GeoRaster checkRasterMetadataIO(GeoRaster grSource) {
    Value v = ValueFactory.createValue(grSource);
    Value v2 = ValueFactory.createValue(v.getType(), v.getBytes());
    GeoRaster gr = v2.getAsRaster();
    assertEquals(gr.getMetadata(), grSource.getMetadata());

    return gr;
  }
Example #4
0
 /**
  * Checks the response to an HTTP request.
  *
  * @param v query result
  * @param itemsCount expected number of items
  * @param expStatus expected status
  */
 private static void checkResponse(final Value v, final int itemsCount, final int expStatus) {
   assertEquals(itemsCount, v.size());
   assertTrue(v.itemAt(0) instanceof FElem);
   final FElem response = (FElem) v.itemAt(0);
   assertNotNull(response.attributes());
   if (!eq(response.attribute(STATUS), token(expStatus))) {
     fail("Expected: " + expStatus + "\nFound: " + response);
   }
 }
Example #5
0
 /**
  * DOCUMENT ME!
  *
  * @throws IncompatibleTypesException DOCUMENT ME!
  */
 @Test
 public void testStringValueEquals() throws IncompatibleTypesException {
   Value v1 = ValueFactory.createValue("hola");
   Value v2 = ValueFactory.createValue("hola");
   Value v3 = ValueFactory.createValue("holA");
   assertTrue((v1.equals(v2)).getAsBoolean());
   assertFalse((v1.equals(v3)).getAsBoolean());
   assertFalse((v2.equals(v3)).getAsBoolean());
 }
Example #6
0
 /** We must be able to transform specialized collections to GeometryCollectionValues */
 @Test
 public void testGeometryCollectionConversions() throws Exception {
   Value val =
       ValueFactory.createValue(
           gf.createMultiPoint(
               new Coordinate[] {new Coordinate(0, 0, 0), new Coordinate(1, 2, 3)}));
   assertTrue(val instanceof DefaultMultiPointValue);
   Value val2 = val.toType(Type.GEOMETRYCOLLECTION);
   assertTrue(val2 instanceof DefaultGeometryCollectionValue);
   // Let's be sure it's not a GeometryCollection just thanks to the inheritance
   assertFalse(val2 instanceof DefaultMultiPointValue);
   val =
       ValueFactory.createValue(
           gf.createMultiLineString(
               new LineString[] {
                 gf.createLineString(
                     new Coordinate[] {new Coordinate(0, 0, 0), new Coordinate(4, 2, 3)}),
                 gf.createLineString(
                     new Coordinate[] {new Coordinate(5, 6, 9), new Coordinate(5, 7, 1)})
               }));
   assertTrue(val instanceof DefaultMultiLineStringValue);
   val2 = val.toType(Type.GEOMETRYCOLLECTION);
   assertTrue(val2 instanceof DefaultGeometryCollectionValue);
   // Let's be sure it's not a GeometryCollection just thanks to the inheritance
   assertFalse(val2 instanceof DefaultMultiPointValue);
   val =
       ValueFactory.createValue(
           gf.createMultiPolygon(
               new Polygon[] {
                 gf.createPolygon(
                     gf.createLinearRing(
                         new Coordinate[] {
                           new Coordinate(0, 3, 0),
                           new Coordinate(9, 0, 0),
                           new Coordinate(8, 7, 0),
                           new Coordinate(0, 3, 0)
                         }),
                     null),
                 gf.createPolygon(
                     gf.createLinearRing(
                         new Coordinate[] {
                           new Coordinate(10, 3, 0),
                           new Coordinate(9, 0, 0),
                           new Coordinate(8, 7, 0),
                           new Coordinate(10, 3, 0)
                         }),
                     null)
               }));
   assertTrue(val instanceof DefaultMultiPolygonValue);
   val2 = val.toType(Type.GEOMETRYCOLLECTION);
   assertTrue(val2 instanceof DefaultGeometryCollectionValue);
   // Let's be sure it's not a GeometryCollection just thanks to the inheritance
   assertFalse(val2 instanceof DefaultMultiPointValue);
 }
Example #7
0
  @Test
  public void testAsSetAction() throws Exception {
    final Value<String> value = Value.create("1");
    assertEquals(value.get(), "1");
    TestSubscriber<String> testSubscriber = new TestSubscriber<>();
    Subscription subscribe = value.asObservable().subscribe(testSubscriber);

    value.asSetAction().call("2");

    testSubscriber.assertValueCount(2);
    testSubscriber.assertValues("1", "2");
  }
Example #8
0
  /** 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());
  }
Example #9
0
 /**
  * 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);
 }
Example #10
0
  /** Test of registerHandlerForEvent method, of class HexEventRegister. */
  @Test
  public void testRegisterHandlerForEvent_3args() {
    System.out.println("registerHandlerForEvent");
    Class type = HexEvent.class;

    final Value v = new Value();
    v.value = "fix";

    HexEventHandler handler =
        new HexEventHandler() {
          @Override
          public void handle(HexEvent event) throws Exception {
            v.value = "changed";
          }
        };

    String[] names = null;
    HexEventRegister instance = HexEventRegister.getInstance();

    instance.registerHandlerForEvent(type, handler, names);

    instance.triggerEvent(new HexEvent("one"));

    assertEquals(v.value, "changed");

    final Value v2 = new Value();
    v2.value = "fix";

    HexEventHandler handler2 =
        new HexEventHandler() {
          @Override
          public void handle(HexEvent event) throws Exception {
            v2.value = "changed";
          }
        };

    instance.registerHandlerForEvent(type, handler2, new String[] {"two"});

    instance.triggerEvent(new HexEvent("one"));

    assertEquals(v2.value, "fix");

    instance.triggerEvent(new HexEvent("two"));

    assertEquals(v2.value, "changed");
  }
Example #11
0
  @Test
  public void testBooleanComparisons() throws Exception {
    Value v1 = ValueFactory.createValue(true);
    Value v2 = ValueFactory.createValue(false);

    assertEquals(v1.compareTo(v1), 0);
    assertEquals(v2.compareTo(v2), 0);

    assertEquals(v1.compareTo(v2), 1);
    assertEquals(v2.compareTo(v1), -1);
  }
Example #12
0
  @Test
  public void testTimeValuesComparisons() throws Exception {
    DateFormat dateInstance = new SimpleDateFormat("yyyy/MM/dd");
    Value v1 = ValueFactory.createValue(dateInstance.parse("2002/11/21"));
    Value v2 = ValueFactory.createValue(dateInstance.parse("2010/01/11"));

    assertEquals(v1.compareTo(v1), 0);
    assertEquals(v1.compareTo(v2), -1);
    assertEquals(v2.compareTo(v1), 1);

    v1 = ValueFactory.createValue(Time.valueOf("18:01:59"));
    v2 = ValueFactory.createValue(Time.valueOf("23:00:05"));

    assertEquals(v1.compareTo(v1), 0);
    assertEquals(v1.compareTo(v2), -1);
    assertEquals(v2.compareTo(v1), 1);

    v1 = ValueFactory.createValue(Timestamp.valueOf("2002-11-21 18:01:59"));
    v2 = ValueFactory.createValue(Timestamp.valueOf("2010-01-11 23:00:05"));

    assertEquals(v1.compareTo(v1), 0);
    assertEquals(v1.compareTo(v2), -1);
    assertEquals(v2.compareTo(v1), 1);
  }
Example #13
0
  @Test
  public void testNumericValueComparisons() throws Exception {

    Value v1 = ValueFactory.createValue(1);
    Value v2 = ValueFactory.createValue(18);
    Value v3 = ValueFactory.createValue(-5d);
    Value v4 = ValueFactory.createValue(100d);
    Value v5 = ValueFactory.createValue(18f);

    // same value
    assertEquals(v1.compareTo(v1), 0);

    // opposite comparisons
    assertEquals(v1.compareTo(v2), -1);
    assertEquals(v2.compareTo(v1), 1);

    // different types
    assertEquals(v1.compareTo(v3), 1);
    assertEquals(v2.compareTo(v4), -1);
    assertEquals(v2.compareTo(v5), 0);
  }
Example #14
0
  @Test
  public void testCreatePublish() throws Exception {

    final Value<String> value = Value.createPublish("1");
    assertEquals(value.get(), "1");
    TestSubscriber<String> testSubscriber = new TestSubscriber<>();
    Subscription subscribe = value.asObservable().subscribe(testSubscriber);

    testSubscriber.assertValueCount(0);

    value.set("2");

    testSubscriber.assertValueCount(1);
    testSubscriber.assertValues("2");

    subscribe.unsubscribe();

    testSubscriber = new TestSubscriber<>();
    value.asObservable().subscribe(testSubscriber);

    testSubscriber.assertValueCount(0);
  }
Example #15
0
 @Test
 public void testGeometryType() throws Exception {
   // We test the point
   Value val = ValueFactory.createValue(gf.createPoint(new Coordinate(2, 1)));
   assertTrue((val.getType() & Type.GEOMETRY) != 0);
   assertTrue(val.getType() == Type.POINT);
   // We test the multipoint
   val = ValueFactory.createValue(gf.createMultiPoint(new Coordinate[] {new Coordinate(2, 1)}));
   assertTrue((val.getType() & Type.GEOMETRY) != 0);
   assertTrue(val.getType() == Type.MULTIPOINT);
   // We test the LineString
   val =
       ValueFactory.createValue(
           gf.createLineString(new Coordinate[] {new Coordinate(2, 1), new Coordinate(2, 2)}));
   assertTrue((val.getType() & Type.GEOMETRY) != 0);
   assertTrue(val.getType() == Type.LINESTRING);
   // We test the MultiLineString
   val =
       ValueFactory.createValue(
           gf.createMultiLineString(
               new LineString[] {
                 gf.createLineString(new Coordinate[] {new Coordinate(2, 1), new Coordinate(2, 2)})
               }));
   assertTrue((val.getType() & Type.GEOMETRY) != 0);
   assertTrue(val.getType() == Type.MULTILINESTRING);
   // We test the Polygon
   val =
       ValueFactory.createValue(
           gf.createPolygon(
               gf.createLinearRing(
                   new Coordinate[] {
                     new Coordinate(2, 1),
                     new Coordinate(2, 2),
                     new Coordinate(4, 3),
                     new Coordinate(2, 1)
                   }),
               null));
   assertTrue((val.getType() & Type.GEOMETRY) != 0);
   assertTrue(val.getType() == Type.POLYGON);
   // We test the MultiPolygon
   val =
       ValueFactory.createValue(
           gf.createMultiPolygon(
               new Polygon[] {
                 gf.createPolygon(
                     gf.createLinearRing(
                         new Coordinate[] {
                           new Coordinate(2, 1),
                           new Coordinate(2, 2),
                           new Coordinate(4, 3),
                           new Coordinate(2, 1)
                         }),
                     null),
                 gf.createPolygon(
                     gf.createLinearRing(
                         new Coordinate[] {
                           new Coordinate(2, 1),
                           new Coordinate(2, 2),
                           new Coordinate(6, 3),
                           new Coordinate(2, 1)
                         }),
                     null)
               }));
   assertTrue((val.getType() & Type.GEOMETRY) != 0);
   assertTrue(val.getType() == Type.MULTIPOLYGON);
   // We test the GeometryCollection
   val =
       ValueFactory.createValue(
           gf.createGeometryCollection(
               new Geometry[] {
                 gf.createPolygon(
                     gf.createLinearRing(
                         new Coordinate[] {
                           new Coordinate(2, 1),
                           new Coordinate(2, 2),
                           new Coordinate(4, 3),
                           new Coordinate(2, 1)
                         }),
                     null),
                 gf.createPoint(new Coordinate(2, 1))
               }));
   assertTrue((val.getType() & Type.GEOMETRY) != 0);
   assertTrue((val.getType() & Type.GEOMETRYCOLLECTION) != 0);
 }
Example #16
0
  @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());
  }
Example #17
0
 private void checkConversions(Value value, Set<Integer> a) {
   for (int i = 0; i < 13; i++) {
     switch (i) {
       case 0:
         if (a.contains(i)) {
           value.getAsBinary();
         } else {
           try {
             value.getAsBinary();
             fail();
           } catch (IncompatibleTypesException e) {
           }
         }
         break;
       case 1:
         if (a.contains(i)) {
           value.getAsBoolean();
         } else {
           try {
             value.getAsBoolean();
             fail();
           } catch (IncompatibleTypesException e) {
           }
         }
         break;
       case 2:
         if (a.contains(i)) {
           value.getAsByte();
         } else {
           try {
             value.getAsByte();
             fail();
           } catch (IncompatibleTypesException e) {
           }
         }
         break;
       case 3:
         if (a.contains(i)) {
           value.getAsDate();
         } else {
           try {
             value.getAsDate();
             fail();
           } catch (IncompatibleTypesException e) {
           }
         }
         break;
       case 4:
         if (a.contains(i)) {
           value.getAsDouble();
         } else {
           try {
             value.getAsDouble();
             fail();
           } catch (IncompatibleTypesException e) {
           }
         }
         break;
       case 5:
         if (a.contains(i)) {
           value.getAsFloat();
         } else {
           try {
             value.getAsFloat();
             fail();
           } catch (IncompatibleTypesException e) {
           }
         }
         break;
       case 6:
         if (a.contains(i)) {
           value.getAsGeometry();
         } else {
           try {
             value.getAsGeometry();
             fail();
           } catch (IncompatibleTypesException e) {
           }
         }
         break;
       case 7:
         if (a.contains(i)) {
           value.getAsInt();
         } else {
           try {
             value.getAsInt();
             fail();
           } catch (IncompatibleTypesException e) {
           }
         }
         break;
       case 8:
         if (a.contains(i)) {
           value.getAsLong();
         } else {
           try {
             value.getAsLong();
             fail();
           } catch (IncompatibleTypesException e) {
           }
         }
         break;
       case 9:
         if (a.contains(i)) {
           value.getAsShort();
         } else {
           try {
             value.getAsShort();
             fail();
           } catch (IncompatibleTypesException e) {
           }
         }
         break;
       case 10:
         if (a.contains(i)) {
           value.getAsString();
         } else {
           try {
             value.getAsString();
             fail();
           } catch (IncompatibleTypesException e) {
           }
         }
         break;
       case 11:
         if (a.contains(i)) {
           value.getAsTime();
         } else {
           try {
             value.getAsTime();
             fail();
           } catch (IncompatibleTypesException e) {
           }
         }
         break;
       case 12:
         if (a.contains(i)) {
           value.getAsTimestamp();
         } else {
           try {
             value.getAsTimestamp();
             fail();
           } catch (IncompatibleTypesException e) {
           }
         }
         break;
       case 13:
         if (a.contains(i)) {
           value.getAsValueCollection();
         } else {
           try {
             value.getAsValueCollection();
             fail();
           } catch (IncompatibleTypesException e) {
           }
         }
     }
   }
 }
Example #18
0
 private void checkIO(Value v) throws IncompatibleTypesException {
   Value v2 = ValueFactory.createValue(v.getType(), v.getBytes());
   assertTrue((v2.equals(v)).getAsBoolean());
 }
Example #19
0
 private void checkDifferent(Value p1, Value p2) {
   assertFalse(p1.equals(p2).getAsBoolean());
   assertTrue(p1.equals(p1).getAsBoolean());
 }
Example #20
0
  @Test
  public void testNullOperations() throws Exception {
    Value nullv = ValueFactory.createNullValue();
    Value numv = ValueFactory.createValue(4d);
    Value strv = ValueFactory.createValue("s");
    Value falsev = numv.less(numv);
    Value truev = numv.equals(numv);

    assertTrue(nullv.multiply(numv).isNull());
    assertTrue(numv.multiply(nullv).isNull());
    assertTrue(nullv.sum(numv).isNull());
    assertTrue(numv.sum(nullv).isNull());

    assertTrue(strv.matches(nullv).isNull());
    assertTrue(nullv.matches(strv).isNull());
    assertTrue(falsev.or(nullv).isNull());
    assertTrue(nullv.or(falsev).isNull());
    assertTrue(truev.and(nullv).isNull());
    assertTrue(nullv.and(truev).isNull());
    assertTrue(numv.greaterEqual(nullv).isNull());
    assertTrue(numv.equals(nullv).isNull());
    assertTrue(numv.notEquals(nullv).isNull());
    assertTrue(numv.less(nullv).isNull());
    assertTrue(numv.lessEqual(nullv).isNull());
    assertTrue(nullv.greaterEqual(numv).isNull());
    assertTrue(nullv.equals(numv).isNull());
    assertTrue(nullv.notEquals(numv).isNull());
    assertTrue(nullv.less(numv).isNull());
    assertTrue(nullv.lessEqual(numv).isNull());
  }
Example #21
0
  /** Tests the NullValues operations */
  @Test
  public void testNullValueOperations() throws Exception {
    Value n = ValueFactory.createNullValue();

    ValueCollection b = ValueFactory.createValue(new Value[0]);
    assertTrue((b.equals(n)).isNull());
    assertTrue(b.notEquals(n).isNull());

    Value v = ValueFactory.createValue(true);
    v.and(n);
    v.or(n);
    // SQL UNKNOWN
    assertNull((v.equals(n)).getAsBoolean());
    assertNull((v.notEquals(n)).getAsBoolean());

    Value i = ValueFactory.createValue(1);
    i.equals(n);
    i.notEquals(n);
    assertTrue((i.less(n)).isNull());
    assertTrue((i.lessEqual(n)).isNull());
    assertTrue((i.greater(n)).isNull());
    assertTrue((i.greaterEqual(n)).isNull());

    Value s = ValueFactory.createValue("test");
    assertTrue((s.equals(n)).isNull());
    assertTrue((s.notEquals(n)).isNull());
    assertTrue((s.less(n)).isNull());
    assertTrue((s.lessEqual(n)).isNull());
    assertTrue((s.greater(n)).isNull());
    assertTrue((s.greaterEqual(n)).isNull());
    s.matches(n);

    Value d = ValueFactory.createValue(new Date());
    assertTrue((d.equals(n)).isNull());
    assertTrue((d.notEquals(n)).isNull());
    assertTrue((d.less(n)).isNull());
    assertTrue((d.lessEqual(n)).isNull());
    assertTrue((d.greater(n)).isNull());
    assertTrue((d.greaterEqual(n)).isNull());

    Value t = ValueFactory.createValue(new Time(12));
    assertTrue((t.equals(n)).isNull());
    assertTrue((t.notEquals(n)).isNull());
    assertTrue((t.less(n)).isNull());
    assertTrue((t.lessEqual(n)).isNull());
    assertTrue((t.greater(n)).isNull());
    assertTrue((t.greaterEqual(n)).isNull());

    Value ts = ValueFactory.createValue(new Timestamp(12));
    assertTrue((ts.equals(n)).isNull());
    assertTrue((ts.notEquals(n)).isNull());
    assertTrue((ts.less(n)).isNull());
    assertTrue((ts.lessEqual(n)).isNull());
    assertTrue((ts.greater(n)).isNull());
    assertTrue((ts.greaterEqual(n)).isNull());

    assertTrue((n.equals(n)).isNull());
    assertTrue((n.notEquals(n)).isNull());
    assertTrue((n.less(n)).isNull());
    assertTrue((n.lessEqual(n)).isNull());
    assertTrue((n.greater(n)).isNull());
    assertTrue((n.greaterEqual(n)).isNull());
    n.matches(n);
  }
Example #22
0
 @Test
 public void testGeometryConversions() throws Exception {
   // Let's test with a PointValue
   Value pt = ValueFactory.createValue(gf.createPoint(new Coordinate(0, 0, 0)));
   assertTrue(pt instanceof DefaultPointValue);
   Value mpt = pt.toType(Type.MULTIPOINT);
   assertTrue(mpt instanceof DefaultMultiPointValue);
   Value gpt = pt.toType(Type.GEOMETRY);
   assertTrue(gpt instanceof DefaultPointValue);
   Value gcpt = pt.toType(Type.GEOMETRYCOLLECTION);
   assertTrue(gcpt instanceof DefaultGeometryCollectionValue);
   assertFalse(gcpt instanceof DefaultMultiPointValue);
   // We shall not be able to cast to a Line or a Polygon.
   try {
     gcpt = pt.toType(Type.POLYGON);
     fail();
   } catch (IncompatibleTypesException i) {
   }
   try {
     gcpt = pt.toType(Type.LINESTRING);
     fail();
   } catch (IncompatibleTypesException i) {
   }
   // LineString time!!!
   pt =
       ValueFactory.createValue(
           gf.createLineString(
               new Coordinate[] {new Coordinate(0, 0, 0), new Coordinate(0, 1, 0)}));
   assertTrue(pt instanceof DefaultLineStringValue);
   mpt = pt.toType(Type.MULTILINESTRING);
   assertTrue(mpt instanceof DefaultMultiLineStringValue);
   gpt = pt.toType(Type.GEOMETRY);
   assertTrue(gpt instanceof DefaultLineStringValue);
   gcpt = pt.toType(Type.GEOMETRYCOLLECTION);
   assertTrue(gcpt instanceof DefaultGeometryCollectionValue);
   assertFalse(gcpt instanceof DefaultMultiPointValue);
   // We shall not be able to cast to a Line or a Polygon.
   try {
     gcpt = pt.toType(Type.POLYGON);
     fail();
   } catch (IncompatibleTypesException i) {
   }
   try {
     gcpt = pt.toType(Type.POINT);
     fail();
   } catch (IncompatibleTypesException i) {
   }
   // Let's test with a PolygonValue
   pt =
       ValueFactory.createValue(
           gf.createPolygon(
               gf.createLinearRing(
                   new Coordinate[] {
                     new Coordinate(0, 0, 0),
                     new Coordinate(0, 1, 0),
                     new Coordinate(1, 1, 0),
                     new Coordinate(0, 0, 0)
                   }),
               null));
   assertTrue(pt instanceof DefaultPolygonValue);
   mpt = pt.toType(Type.MULTIPOLYGON);
   assertTrue(mpt instanceof DefaultMultiPolygonValue);
   gpt = pt.toType(Type.GEOMETRY);
   assertTrue(gpt instanceof DefaultPolygonValue);
   gcpt = pt.toType(Type.GEOMETRYCOLLECTION);
   assertTrue(gcpt instanceof DefaultGeometryCollectionValue);
   assertFalse(gcpt instanceof DefaultMultiPolygonValue);
   // We shall not be able to cast to a Line or a Polygon.
   try {
     gcpt = pt.toType(Type.POINT);
     fail();
   } catch (IncompatibleTypesException i) {
   }
   try {
     gcpt = pt.toType(Type.LINESTRING);
     fail();
   } catch (IncompatibleTypesException i) {
   }
 }