OptionsBuilder { public static void checkParameters(String type) { checkDelimiters(type); String project = DshipContext.INSTANCE.get(Constants.TABLE_PROJECT); if (project != null && (project.trim().isEmpty())) { throw new IllegalArgumentException("Project is empty.\nType 'tunnel help " + type + "' for usage."); } boolean isc = false; String c = DshipContext.INSTANCE.get(Constants.CHARSET); try { isc = Charset.isSupported(c); } catch (IllegalCharsetNameException e) { } isc = isc || Constants.IGNORE_CHARSET.equals(c); if (c == null || c.isEmpty() || !isc) { throw new IllegalArgumentException("Unsupported encoding: '" + c + "'\nType 'tunnel help " + type + "' for usage."); } try { new SimpleDateFormat(DshipContext.INSTANCE.get(Constants.DATE_FORMAT_PATTERN)); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Unsupported date format pattern '" + DshipContext.INSTANCE.get(Constants.DATE_FORMAT_PATTERN) + "'"); } String sct = DshipContext.INSTANCE.get(Constants.SESSION_CREATE_TIME); if (sct == null) { throw new IllegalArgumentException(Constants.ERROR_INDICATOR + "create time is null."); } String cp = DshipContext.INSTANCE.get(Constants.COMPRESS); if (cp == null) { throw new IllegalArgumentException(Constants.ERROR_INDICATOR + "compress info is null."); } int threads; try { threads = Integer.parseInt(DshipContext.INSTANCE.get(Constants.THREADS)); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( Constants.THREADS + " " + DshipContext.INSTANCE.get(Constants.THREADS) + " Invalid."); } if (threads <= 0) { throw new IllegalArgumentException(Constants.THREADS + " argument must > 0."); } if (threads > 1 && "true".equalsIgnoreCase(DshipContext.INSTANCE.get(Constants.HEADER))) { throw new IllegalArgumentException("Do not support write header in multi-threads."); } String table = DshipContext.INSTANCE.get(Constants.TABLE); if ("download".equals(type)) { if (com.aliyun.odps.utils.StringUtils.isNullOrEmpty(table) && com.aliyun.odps.utils.StringUtils .isNullOrEmpty(DshipContext.INSTANCE.get(Constants.INSTANE_ID))) { throw new IllegalArgumentException("Table or instanceId is null.\nType 'tunnel help " + type + "' for usage."); } String limit = DshipContext.INSTANCE.get(Constants.LIMIT); if (limit != null) { try { if (Long.valueOf(limit) <= 0) { throw new IllegalArgumentException(Constants.LIMIT + " argument must > 0."); } } catch (NumberFormatException e) { throw new IllegalArgumentException(Constants.LIMIT + " " + limit + " Invalid."); } } String exponential = DshipContext.INSTANCE.get(Constants.EXPONENTIAL); if (exponential != null && !(exponential.equalsIgnoreCase("true") || exponential.equalsIgnoreCase("false"))) { throw new IllegalArgumentException( "Invalid parameter : exponential format in double expected 'true' or 'false', found '" + exponential + "'\nType 'tunnel help " + type + "' for usage."); } String columnNames = DshipContext.INSTANCE.get(Constants.COLUMNS_NAME); String columnIndexes = DshipContext.INSTANCE.get(Constants.COLUMNS_INDEX); if (columnNames != null && columnIndexes != null) { throw new IllegalArgumentException(String.format( "Invalid parameter, these two params cannot be used together: %s and %s ", Constants.COLUMNS_INDEX, Constants.COLUMNS_NAME)); } if (columnIndexes != null) { for (String index : columnIndexes.split(",")) { if (!StringUtils.isNumeric(index.trim())) { throw new IllegalArgumentException("Invalid parameter, columns indexes expected numeric, found " + columnIndexes); } } } } if ("upload".equals(type)) { if (com.aliyun.odps.utils.StringUtils.isNullOrEmpty(table)) { throw new IllegalArgumentException("Table is null.\nType 'tunnel help " + type + "' for usage."); } String scan = DshipContext.INSTANCE.get(Constants.SCAN); if (scan == null || !(scan.equals("true") || scan.equals("false") || scan.equals("only"))) { throw new IllegalArgumentException("-scan, expected:(true|false|only), actual: '" + scan + "'\nType 'tunnel help " + type + "' for usage."); } String dbr = DshipContext.INSTANCE.get(Constants.DISCARD_BAD_RECORDS); if (dbr == null || !(dbr.equals("true") || dbr.equals("false"))) { throw new IllegalArgumentException( "Invalid parameter : discard bad records expected 'true' or 'false', found '" + dbr + "'\nType 'tunnel help " + type + "' for usage."); } String ss = DshipContext.INSTANCE.get(Constants.STRICT_SCHEMA); if (ss == null || !(ss.equals("true") || ss.equals("false"))) { throw new IllegalArgumentException( "Invalid parameter : strict schema expected 'true' or 'false', found '" + ss + "'\nType 'tunnel help " + type + "' for usage."); } String bs = DshipContext.INSTANCE.get(Constants.BLOCK_SIZE); if (bs != null) { try { Long.valueOf(bs); } catch (NumberFormatException e) { throw new IllegalArgumentException( "Illegal number 'block-size', please check config file."); } } String mbr = DshipContext.INSTANCE.get(Constants.MAX_BAD_RECORDS); if (mbr != null) { try { Long.valueOf(mbr); } catch (NumberFormatException e) { throw new IllegalArgumentException( "Illegal number 'max-bad-records', please check config file."); } } String path = DshipContext.INSTANCE.get(Constants.RESUME_PATH); File sFile = new File(path); if (!sFile.exists()) { throw new IllegalArgumentException("Upload File not found: '" + path + "'\nType 'tunnel help " + type + "' for usage."); } } }  static void buildUploadOption(String[] args); static void buildDownloadOption(String[] args); static void buildResumeOption(String[] args); static void buildShowOption(String[] args); static void buildPurgeOption(String[] args); static void buildHelpOption(String[] args); static void checkParameters(String type); static Options getGlobalOptions(); static Options getUploadOptions(); static Options getDownloadOptions(); static Options getResumeOptions(); static Options getShowOptions(); static Options getConfigOptions(); static Options getPurgeOptions();  }
@Test(expected = IllegalArgumentException.class) public void testCheckParameters() throws Exception { OptionsBuilder.buildUploadOption( new String[]{"upload", "src/test/resources/many_record.txt", TEST_TABLE_NAME}); DshipContext.INSTANCE.put(Constants.THREADS, "1"); try { OptionsBuilder.checkParameters("upload"); } catch (IllegalArgumentException e) { Assert.assertTrue(e.getMessage().contains("Record delimiter is null")); throw e; } Assert.assertTrue(false); }