Utils { public static void setField(String value, IndexField fieldData, BoundStatement bs, int index) throws IndexParseException { try { if (value == null) { bs.setToNull(index); } else if (fieldData.getType().equals(FieldDataType.BINARY)) { bs.setBytes(index, ParseUtils.parseBase64StringAsByteBuffer(value)); } else if (fieldData.getType().equals(FieldDataType.BOOLEAN)) { bs.setBool(index, ParseUtils.parseStringAsBoolean(value)); } else if (fieldData.getType().equals(FieldDataType.DATE_TIME) || fieldData.getType().equals(FieldDataType.TIMEPOINT)) { bs.setDate(index, ParseUtils.parseStringAsDate(value)); } else if (fieldData.getType().equals(FieldDataType.DOUBLE)) { bs.setDouble(index, ParseUtils.parseStringAsDouble(value)); } else if (fieldData.getType().equals(FieldDataType.INTEGER)) { bs.setInt(index, ParseUtils.parseStringAsInt(value)); } else if (fieldData.getType().equals(FieldDataType.TEXT)) { bs.setString(index, value); } else if (fieldData.getType().equals(FieldDataType.UUID)) { bs.setUUID(index, ParseUtils.parseStringAsUUID(value)); } else if (fieldData.getType().equals(FieldDataType.LONG)) { bs.setLong(index, ParseUtils.parseStringAsLong(value)); } else { throw new IndexParseFieldException(fieldData.getField(), new Exception(fieldData.getType().toString() + " is an unsupported type. Please contact support.")); } } catch (IndexParseFieldException parseException) { throw new IndexParseException(fieldData, parseException); } }  static String calculateITableName(String databaseName, String tableName, String indexName); static String calculateITableName(Index index); static String calculateITableName(IndexIdentifier indexId); @Deprecated static void initDatabase(String cqlPath, Session session); static void initDatabase(boolean dropDb, String replicationString, Session session); static void initDatabaseSingleReplication(boolean dropDb, Session session); static void setField(String value, IndexField fieldData, BoundStatement bs, int index); static boolean setField(DBObject jsonObject, IndexField fieldData, BoundStatement bs, int index); static String join(String delimiter, Object... objects); static String join(String delimiter, Collection<? extends Object> objects); static boolean equalLists(List<String> one, List<String> two); static void writeFile(String toWrite, String fileName); static String readFile(String fileName); static List<Long> traverse1RowFile(String fileName); static final String EMPTY_STRING; }
@Test public void testSetField() throws Exception { logger.debug("setField"); DBObject object = new BasicDBObject(); BoundStatement bs = null; IndexField fieldData = new IndexField("testField"); boolean normal = Utils.setField(object, fieldData, bs, 0); assertFalse("Expected exception not thrown.", normal); fieldData = new IndexField("testField", FieldDataType.INTEGER); object.put("testField", "thisisnotaninteger"); boolean expectedExceptionThrown = false; try { Utils.setField(object, fieldData, bs, 0); } catch (IndexParseException e) { expectedExceptionThrown = true; assertTrue(e.getMessage().contains("thisisnotaninteger")); assertTrue(e.getMessage().contains("testField")); } assertTrue("Expected exception not thrown.", expectedExceptionThrown); }