Пример #1
1
  /**
   * Test importing an unsupported field e.g. datetime, the program should continue and assign null
   * value to the field.
   *
   * @throws Exception
   */
  @Test
  public void testImportUnsupportedField() throws Exception {
    ConnectionProperties p = getConnectionProperties();
    Connection cn = DatabaseConnection.getConnection(p);
    try {
      List<Field> verifiedFields = new Vector<Field>();
      String[] fields = "ListingId, Title".split(",");
      String tableName = "Listings";
      DatabaseConnection.verifyTable(p, tableName, fields, verifiedFields);

      Collection<JsonNode> importNodes = new LinkedList<JsonNode>();
      JsonNodeFactory f = JsonNodeFactory.instance;

      int listingId = 1559350;

      ObjectNode n;
      n = new ObjectNode(f);
      n.put("ListingId", listingId);
      importNodes.add(n);

      JsonArrayImporter importer = new JsonArrayImporter(p);
      importer.doImport(tableName, verifiedFields, importNodes);

      Statement st = cn.createStatement();
      ResultSet rs = st.executeQuery("SELECT ListingId, Title FROM Listings");
      assertTrue("Expected result set to contain a record", rs.next());
      assertEquals(listingId, rs.getInt("ListingId"));
      assertEquals(null, rs.getString("Title"));
    } finally {
      cn.close();
    }
  }
Пример #2
0
  public String toCreateKML() {
    this.createdNodes = removeDescendants(this.createdNodes);

    StringBuilder create = new StringBuilder();
    if (this.createdNodes != null) {
      for (Iterator iter = this.createdNodes.iterator(); iter.hasNext(); ) {
        Node newNode = (Node) iter.next();
        if (newNode.parent instanceof ObjectNode) // ie. not Kml
        // node
        {
          ObjectNode newNodeParent = (ObjectNode) newNode.parent;
          create.append(
              "<"
                  + newNodeParent.getClass().getSimpleName()
                  + " targetId=\""
                  + newNodeParent.getId()
                  + "\">\n");
          create.append(newNode.toKML());
          create.append("</" + newNodeParent.getClass().getSimpleName() + ">\n");
        } else {
          create.append(newNode.toKML());
        }
        newNode.setRecursiveNotDirty();
      }
      this.createdNodes.clear();
    }
    return create.toString();
  }
  public void testFromArray() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode root = mapper.createArrayNode();
    root.add(TEXT1);
    root.add(3);
    ObjectNode obj = root.addObject();
    obj.put(FIELD1, true);
    obj.putArray(FIELD2);
    root.add(false);

    /* Ok, ready... let's serialize using one of two alternate
     * methods: first preferred (using generator)
     * (there are 2 variants here too)
     */
    for (int i = 0; i < 2; ++i) {
      StringWriter sw = new StringWriter();
      if (i == 0) {
        JsonGenerator gen = new JsonFactory().createGenerator(sw);
        root.serialize(gen, null);
        gen.close();
      } else {
        mapper.writeValue(sw, root);
      }
      verifyFromArray(sw.toString());
    }

    // And then convenient but less efficient alternative:
    verifyFromArray(root.toString());
  }
Пример #4
0
  /**
   * Simple test to verify that byte[] values can be handled properly when converting, as long as
   * there is metadata (from POJO definitions).
   */
  public void testIssue709() throws Exception {
    byte[] inputData = new byte[] {1, 2, 3};
    ObjectNode node = MAPPER.createObjectNode();
    node.put("data", inputData);
    Issue709Bean result = MAPPER.treeToValue(node, Issue709Bean.class);
    String json = MAPPER.writeValueAsString(node);
    Issue709Bean resultFromString = MAPPER.readValue(json, Issue709Bean.class);
    Issue709Bean resultFromConvert = MAPPER.convertValue(node, Issue709Bean.class);

    // all methods should work equally well:
    Assert.assertArrayEquals(inputData, resultFromString.data);
    Assert.assertArrayEquals(inputData, resultFromConvert.data);
    Assert.assertArrayEquals(inputData, result.data);
  }
Пример #5
0
 /**
  * Executes this field expression.
  *
  * @param context AspContext under which to evaluate the expression.
  * @return return value of this expression
  * @throws AspException If an error occurs
  * @see Node#execute(AspContext)
  */
 public Object execute(AspContext context) throws AspException {
   if (DBG.isDebugEnabled()) DBG.debug("execute");
   Object value = expr.execute(context);
   while (value instanceof SimpleReference && !(value instanceof ObjectNode)) {
     if (DBG.isDebugEnabled()) DBG.debug("De-referencing " + value);
     value = ((SimpleReference) value).getValue();
   }
   if (value instanceof ObjectNode) {
     ObjectNode obj = (ObjectNode) value;
     if (DBG.isDebugEnabled()) DBG.debug("Get field of " + ident + " from " + obj);
     return Types.coerceToNode(obj.getField(ident));
   } else {
     throw new AspException("Invalid class for field get: " + value.getClass().getName());
   }
 }
Пример #6
0
 public void setRecursiveNotDirty() {
   super.setRecursiveNotDirty();
   this.isListItemTypeDirty = false;
   this.isBgColorDirty = false;
   if (this.itemIcon != null && this.itemIcon.isDirty()) {
     this.itemIcon.setRecursiveNotDirty();
   }
 }
  public void testFromMap() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode root = mapper.createObjectNode();
    root.put(FIELD4, TEXT2);
    root.put(FIELD3, -1);
    root.putArray(FIELD2);
    root.put(FIELD1, DOUBLE_VALUE);

    /* Let's serialize using one of two alternate methods:
     * first preferred (using generator)
     * (there are 2 variants here too)
     */
    for (int i = 0; i < 2; ++i) {
      StringWriter sw = new StringWriter();
      if (i == 0) {
        JsonGenerator gen = new JsonFactory().createGenerator(sw);
        root.serialize(gen, null);
        gen.close();
      } else {
        mapper.writeValue(sw, root);
      }
      verifyFromMap(sw.toString());
    }

    // And then convenient but less efficient alternative:
    verifyFromMap(root.toString());
  }
Пример #8
0
  /**
   * Test importing string, int, and decimal values work successfully
   *
   * @throws Exception
   */
  @Test
  public void testImportSimple() throws Exception {
    ConnectionProperties p = getConnectionProperties();
    Connection cn = DatabaseConnection.getConnection(p);
    try {
      List<Field> verifiedFields = new Vector<Field>();
      String[] fields = "ListingId, Title, StartPrice".split(",");
      String tableName = "Listings";
      DatabaseConnection.verifyTable(p, tableName, fields, verifiedFields);

      Collection<JsonNode> importNodes = new LinkedList<JsonNode>();
      JsonNodeFactory f = JsonNodeFactory.instance;

      int listingId = 1559350;
      String title = "Product Pro1-Beta-0066";
      BigDecimal startPrice = BigDecimal.valueOf(20.64);

      ObjectNode n;
      n = new ObjectNode(f);
      n.put("ListingId", listingId);
      n.put("Title", title);
      n.put("StartPrice", startPrice);
      importNodes.add(n);

      JsonArrayImporter importer = new JsonArrayImporter(p);
      importer.doImport(tableName, verifiedFields, importNodes);

      Statement st = cn.createStatement();
      ResultSet rs = st.executeQuery("SELECT ListingId, Title, StartPrice FROM Listings");
      assertTrue("Expected result set to contain a record", rs.next());
      assertEquals(listingId, rs.getInt("ListingId"));
      assertEquals(title, rs.getString("Title"));
      assertEquals(startPrice, rs.getBigDecimal("StartPrice"));
      assertFalse("Expect result set to only contain one record", rs.next());
    } finally {
      cn.close();
    }
  }