DomainParameterParser { public static Map<String, Object> parseParameters(final String parameters) { final Map<String, Object> parameterMap; if (parameters == null || parameters.isEmpty()) { log.debug("parameters null or empty, nothing to map!"); parameterMap = new HashMap<>(); } else { final List<String> parameterList = splitParameters(parameters); parameterMap = evaluateParameters(parameterList); } return parameterMap; } private  DomainParameterParser(); static String parseParameterMapToString(final Map<String, Object> parametersMap); static void parseParameterEntryToString(final StringBuilder stringBuilder, final Entry<String, Object> entry); static JobParameters parseParametersToJobParameters(final String parameters); static Map<String, Object> parseParameters(final String parameters); static String parseJobParametersToString(final JobParameters jobParameters); static Entry<String, Object> generateParameterEntry(final String parameter); static Object createValueInstance(final String type, final String valueString); static Date parseDate(final String dateString); static String parseDate(final Date date); static final String DATE_FORMAT_WITH_TIMESTAMP; static final String DATE_FORMAT; }
@Test public void parseParametersTest() { final SimpleDateFormat simpleDateFormat = new SimpleDateFormat( DomainParameterParser.DATE_FORMAT_WITH_TIMESTAMP); final String parameters = "testS(String)=56788,testL(Long)=56,testD(date)=2015/03/27 23:19:24:120"; final Map<String, Object> parameterMap = DomainParameterParser .parseParameters(parameters); assertThat(parameterMap).isNotNull(); assertThat(parameterMap).isNotEmpty(); assertThat(parameterMap.containsKey("testS")).isTrue(); assertThat(parameterMap.containsKey("testL")).isTrue(); assertThat(parameterMap.containsKey("testD")).isTrue(); final String stringValue = (String) parameterMap.get("testS"); final Long longValue = (Long) parameterMap.get("testL"); final Date dateValue = (Date) parameterMap.get("testD"); assertThat(stringValue).isEqualTo("56788"); assertThat(longValue).isEqualTo(56L); assertThat(simpleDateFormat.format(dateValue)).isEqualTo( "2015/03/27 23:19:24:120"); }
@Test public void parseParametersUrlTest() { final String parameters = "targetDirectory(String)=./import/diff/," + "emailFile(String)=email.txt," + "currentFile(String)=./import/current/email_current.txt," + "lastWeekFile(String)=./import/archive/email_last_week.txt," + "pathToTempFolder(String)=./import/temp/," + "emailUrl(String)=https: "emailZipFile(String)=./import/zip/email.zip," + "maxLineCount(Long)=20000"; final Map<String, Object> parameterMap = DomainParameterParser.parseParameters(parameters); assertThat(parameterMap).hasSize(8); }
@Test public void parseParametersNullTest() { final Map<String, Object> parameterMap = DomainParameterParser .parseParameters(null); assertThat(parameterMap).isNotNull(); assertThat(parameterMap).isEmpty(); }