diff --git a/jspringbot-config/pom.xml b/jspringbot-config/pom.xml index 921388e..870c7ce 100644 --- a/jspringbot-config/pom.xml +++ b/jspringbot-config/pom.xml @@ -45,7 +45,7 @@ org.jspringbot - jspringbot-syntax-highlight + jspringbot-pretty-logger ${project.version} diff --git a/jspringbot-csv/pom.xml b/jspringbot-csv/pom.xml index 81bdc53..e54d1ff 100644 --- a/jspringbot-csv/pom.xml +++ b/jspringbot-csv/pom.xml @@ -45,7 +45,7 @@ org.jspringbot - jspringbot-syntax-highlight + jspringbot-pretty-logger ${project.version} diff --git a/jspringbot-csv/src/main/resources/libdoc.intro b/jspringbot-csv/src/main/resources/libdoc.intro index ab7504d..620cea2 100644 --- a/jspringbot-csv/src/main/resources/libdoc.intro +++ b/jspringbot-csv/src/main/resources/libdoc.intro @@ -2,15 +2,15 @@ Contains keywords to parse and query a CSV string or resource. *Example CSV Resource (classpath:employee.csv)* -| *Name* | *Department* | *Position* | *Age* | -| Alvin | Development | CEO | 29 | -| Shiela | Development | Developer | 27 | -| Master | Development | CFO | 23 | -| Warren | Research | QA | 21 | +| *Name* | *Department* | *Position* | *Age* | +| Alvin | Development | CEO | 29 | +| Shiela | Development | Developer | 27 | +| Master | Development | CFO | 23 | +| Warren | Research | QA | 21 | *Example CSV Resource (classpath:department.csv)* -| *Name* | *Description* | +| *Name* | *Description* | | Development | This is the development department. | | Research | This is the research department. | diff --git a/jspringbot-date/pom.xml b/jspringbot-date/pom.xml index 6eda379..c2e739b 100644 --- a/jspringbot-date/pom.xml +++ b/jspringbot-date/pom.xml @@ -64,14 +64,14 @@ org.jspringbot - jspringbot-syntax-highlight + jspringbot-pretty-logger ${project.version} junit junit ${junit.version} - true + test org.mockito diff --git a/jspringbot-date/src/main/java/org/jspringbot/keyword/date/AbstractDateKeyword.java b/jspringbot-date/src/main/java/org/jspringbot/keyword/date/AbstractDateKeyword.java index dd8f01c..69fff04 100644 --- a/jspringbot-date/src/main/java/org/jspringbot/keyword/date/AbstractDateKeyword.java +++ b/jspringbot-date/src/main/java/org/jspringbot/keyword/date/AbstractDateKeyword.java @@ -18,13 +18,11 @@ package org.jspringbot.keyword.date; -import org.jspringbot.Keyword; +import org.jspringbot.syntax.AbstractHighlightKeyword; import org.springframework.beans.factory.annotation.Autowired; -public abstract class AbstractDateKeyword implements Keyword { +public abstract class AbstractDateKeyword extends AbstractHighlightKeyword { @Autowired protected DateHelper helper; - - public abstract Object execute(Object[] objects) throws Exception; } diff --git a/jspringbot-date/src/main/java/org/jspringbot/keyword/date/AddDateTimeDays.java b/jspringbot-date/src/main/java/org/jspringbot/keyword/date/AddDateTimeDays.java index ba0447d..7c60ca9 100644 --- a/jspringbot-date/src/main/java/org/jspringbot/keyword/date/AddDateTimeDays.java +++ b/jspringbot-date/src/main/java/org/jspringbot/keyword/date/AddDateTimeDays.java @@ -28,7 +28,7 @@ public class AddDateTimeDays extends AbstractDateKeyword { @Override - public Object execute(Object[] params) throws IOException { + public Object executeInternal(Object[] params) throws IOException { helper.plusDays(Integer.parseInt(String.valueOf(params[0]))); return null; diff --git a/jspringbot-date/src/main/java/org/jspringbot/keyword/date/DateHelper.java b/jspringbot-date/src/main/java/org/jspringbot/keyword/date/DateHelper.java index 058f67d..f7c2aa7 100644 --- a/jspringbot-date/src/main/java/org/jspringbot/keyword/date/DateHelper.java +++ b/jspringbot-date/src/main/java/org/jspringbot/keyword/date/DateHelper.java @@ -34,68 +34,75 @@ public class DateHelper { private String formatterPattern = "yyyy-MM-dd HH:mm:ss zz"; public void setDateTimeZone(String timeZoneId) { - - LOG.createAppender() - .appendBold("Set Date Time Zone:") - .appendProperty("Time Zone ID", timeZoneId) - .log(); + LOG.keywordAppender().appendProperty("Time Zone ID", timeZoneId); currentTimeZone = DateTimeZone.forID(timeZoneId); } public void setDateTimeFormat(String pattern) { - LOG.createAppender() - .appendBold("Set Date Time Format:") - .appendProperty("Pattern", pattern) - .log(); + LOG.keywordAppender().appendProperty("Pattern", pattern); DateTimeFormat.forPattern(pattern); } - public String printDateTime() { - DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(formatterPattern); + public void parseDateTime(String dateStr) { + parseDateTime(dateStr, formatterPattern); + } + + public void parseDateTime(String dateStr, String pattern) { + LOG.keywordAppender() + .appendProperty("Date String", dateStr) + .appendProperty("Parse Pattern", pattern); + + DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(pattern); + current = dateTimeFormatter.parseDateTime(dateStr); + + // show the log for print + printDateTime(); + } + + public String printDateTime(String pattern) { + LOG.keywordAppender() + .appendProperty("Print Pattern", formatterPattern) + .appendProperty("Print Time Zone ID", currentTimeZone.getID()); + + DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(pattern); DateTime dt = current.withZone(currentTimeZone); String formattedValue = dateTimeFormatter.print(dt); - LOG.createAppender() - .appendBold("Print Date Time:") - .appendProperty("Pattern", formatterPattern) - .appendProperty("Time Zone ID", currentTimeZone.getID()) - .appendProperty("Print", formattedValue) - .log(); + LOG.keywordAppender().appendProperty("Print Value", formattedValue); return formattedValue; } + + public String printDateTime() { + return printDateTime(formatterPattern); + } + public void resetDateTime() { current = new DateTime(); - LOG.createAppender() - .appendBold("Reset Date Time:") - .appendProperty("Pattern", formatterPattern) - .appendProperty("Time Zone ID", currentTimeZone.getID()) - .appendProperty("Print", printDateTime()) - .log(); + // show the log for print + printDateTime(); } public void plusDays(int days) { + LOG.keywordAppender().appendProperty("Added Days", days); + current = current.plusDays(days); - LOG.createAppender() - .appendBold("Add Date Time Days:") - .appendProperty("Days", days) - .appendProperty("Print", printDateTime()) - .log(); + // show the log for print + printDateTime(); } public void minusDays(int days) { + LOG.keywordAppender().appendProperty("Subtract Days", days); + current = current.minusDays(days); - LOG.createAppender() - .appendBold("Subtract Date Time Days:") - .appendProperty("Days", days) - .appendProperty("Print", printDateTime()) - .log(); + // show the log for print + printDateTime(); } } diff --git a/jspringbot-date/src/main/java/org/jspringbot/keyword/date/FormatDateTime.java b/jspringbot-date/src/main/java/org/jspringbot/keyword/date/FormatDateTime.java new file mode 100644 index 0000000..9e25845 --- /dev/null +++ b/jspringbot-date/src/main/java/org/jspringbot/keyword/date/FormatDateTime.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2012. JSpringBot. All Rights Reserved. + * + * See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The JSpringBot licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jspringbot.keyword.date; + +import org.jspringbot.Keyword; +import org.jspringbot.KeywordInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +@KeywordInfo( + name = "Format Date Time", + parameters = {"format=Default"}, + description = "Format the date time to string given the set format." +) +public class FormatDateTime implements Keyword { + + @Autowired + private PrintDateTime printer; + + @Override + public Object execute(Object[] params) throws Exception { + return printer.execute(params); + } +} diff --git a/jspringbot-date/src/main/java/org/jspringbot/keyword/date/ParseDateTime.java b/jspringbot-date/src/main/java/org/jspringbot/keyword/date/ParseDateTime.java new file mode 100644 index 0000000..914066d --- /dev/null +++ b/jspringbot-date/src/main/java/org/jspringbot/keyword/date/ParseDateTime.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2012. JSpringBot. All Rights Reserved. + * + * See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The JSpringBot licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jspringbot.keyword.date; + +import org.jspringbot.KeywordInfo; +import org.springframework.stereotype.Component; + +import java.io.IOException; + +@Component +@KeywordInfo( + name = "Parse Date Time", + parameters = {"dateString", "format=Default"}, + description = "Parses the given date time." +) +public class ParseDateTime extends AbstractDateKeyword { + + @Override + public Object executeInternal(Object[] params) throws IOException { + if(params.length > 1) { + helper.parseDateTime(String.valueOf(params[0]), String.valueOf(params[1])); + + return null; + } + + helper.parseDateTime(String.valueOf(params[0])); + + return null; + } +} diff --git a/jspringbot-date/src/main/java/org/jspringbot/keyword/date/PrintDateTime.java b/jspringbot-date/src/main/java/org/jspringbot/keyword/date/PrintDateTime.java index e5a07df..6a8b8ce 100644 --- a/jspringbot-date/src/main/java/org/jspringbot/keyword/date/PrintDateTime.java +++ b/jspringbot-date/src/main/java/org/jspringbot/keyword/date/PrintDateTime.java @@ -24,11 +24,19 @@ import java.io.IOException; @Component -@KeywordInfo(name = "Print Date Time", description = "Prints the date time to string given the set format.") +@KeywordInfo( + name = "Print Date Time", + parameters = {"format=default"}, + description = "Prints the date time to string given the set format." +) public class PrintDateTime extends AbstractDateKeyword { @Override - public Object execute(Object[] params) throws IOException { + public Object executeInternal(Object[] params) throws IOException { + if(params.length > 0) { + return helper.printDateTime(String.valueOf(params[0])); + } + return helper.printDateTime(); } } diff --git a/jspringbot-date/src/main/java/org/jspringbot/keyword/date/ResetDateTime.java b/jspringbot-date/src/main/java/org/jspringbot/keyword/date/ResetDateTime.java index 90a0ccc..9449fbe 100644 --- a/jspringbot-date/src/main/java/org/jspringbot/keyword/date/ResetDateTime.java +++ b/jspringbot-date/src/main/java/org/jspringbot/keyword/date/ResetDateTime.java @@ -28,7 +28,7 @@ public class ResetDateTime extends AbstractDateKeyword { @Override - public Object execute(Object[] params) throws IOException { + public Object executeInternal(Object[] params) throws IOException { helper.resetDateTime(); return null; diff --git a/jspringbot-date/src/main/java/org/jspringbot/keyword/date/SetDateTimeFormat.java b/jspringbot-date/src/main/java/org/jspringbot/keyword/date/SetDateTimeFormat.java index b9bdc09..7f3588c 100644 --- a/jspringbot-date/src/main/java/org/jspringbot/keyword/date/SetDateTimeFormat.java +++ b/jspringbot-date/src/main/java/org/jspringbot/keyword/date/SetDateTimeFormat.java @@ -28,7 +28,7 @@ public class SetDateTimeFormat extends AbstractDateKeyword { @Override - public Object execute(Object[] params) throws IOException { + public Object executeInternal(Object[] params) throws IOException { helper.setDateTimeFormat(String.valueOf(params[0])); return null; diff --git a/jspringbot-date/src/main/java/org/jspringbot/keyword/date/SetDateTimeZone.java b/jspringbot-date/src/main/java/org/jspringbot/keyword/date/SetDateTimeZone.java index c23f418..394e00e 100644 --- a/jspringbot-date/src/main/java/org/jspringbot/keyword/date/SetDateTimeZone.java +++ b/jspringbot-date/src/main/java/org/jspringbot/keyword/date/SetDateTimeZone.java @@ -28,7 +28,7 @@ public class SetDateTimeZone extends AbstractDateKeyword { @Override - public Object execute(Object[] params) throws IOException { + public Object executeInternal(Object[] params) throws IOException { helper.setDateTimeZone(String.valueOf(params[0])); return null; diff --git a/jspringbot-date/src/main/java/org/jspringbot/keyword/date/SubtractDateTimeDays.java b/jspringbot-date/src/main/java/org/jspringbot/keyword/date/SubtractDateTimeDays.java index 39ef0ec..67fa8d5 100644 --- a/jspringbot-date/src/main/java/org/jspringbot/keyword/date/SubtractDateTimeDays.java +++ b/jspringbot-date/src/main/java/org/jspringbot/keyword/date/SubtractDateTimeDays.java @@ -28,7 +28,7 @@ public class SubtractDateTimeDays extends AbstractDateKeyword { @Override - public Object execute(Object[] params) throws IOException { + public Object executeInternal(Object[] params) throws IOException { helper.minusDays(Integer.parseInt(String.valueOf(params[0]))); return null; diff --git a/jspringbot-date/src/test/java/org/jspringbot/keyword/date/DateHelperTest.java b/jspringbot-date/src/test/java/org/jspringbot/keyword/date/DateHelperTest.java index 83363e4..bccc944 100644 --- a/jspringbot-date/src/test/java/org/jspringbot/keyword/date/DateHelperTest.java +++ b/jspringbot-date/src/test/java/org/jspringbot/keyword/date/DateHelperTest.java @@ -24,6 +24,8 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import static junit.framework.Assert.assertNotNull; + @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"classpath:spring-date.xml"}) public class DateHelperTest { @@ -33,6 +35,6 @@ public class DateHelperTest { @Test public void testPrint() throws Exception { - System.out.println(helper.printDateTime()); + assertNotNull(helper.printDateTime()); } } diff --git a/jspringbot-db/pom.xml b/jspringbot-db/pom.xml index b9154d7..4c8cdc4 100644 --- a/jspringbot-db/pom.xml +++ b/jspringbot-db/pom.xml @@ -73,7 +73,7 @@ org.jspringbot - jspringbot-syntax-highlight + jspringbot-pretty-logger ${project.version} diff --git a/jspringbot-i18n/src/main/java/org/jspringbot/keyword/i18n/GetMessage.java b/jspringbot-i18n/src/main/java/org/jspringbot/keyword/i18n/GetI18nMessage.java similarity index 87% rename from jspringbot-i18n/src/main/java/org/jspringbot/keyword/i18n/GetMessage.java rename to jspringbot-i18n/src/main/java/org/jspringbot/keyword/i18n/GetI18nMessage.java index 8920755..b87ebf4 100644 --- a/jspringbot-i18n/src/main/java/org/jspringbot/keyword/i18n/GetMessage.java +++ b/jspringbot-i18n/src/main/java/org/jspringbot/keyword/i18n/GetI18nMessage.java @@ -22,8 +22,8 @@ import org.springframework.stereotype.Component; @Component -@KeywordInfo(name = "Get Message", description = "Get Message.", parameters = {"code"}) -public class GetMessage extends Abstracti18nKeyword { +@KeywordInfo(name = "Get i18n Message", description = "Get Message.", parameters = {"code"}) +public class GetI18nMessage extends Abstracti18nKeyword { @Override public Object execute(Object[] params) { diff --git a/jspringbot-i18n/src/main/java/org/jspringbot/keyword/i18n/SetLanguage.java b/jspringbot-i18n/src/main/java/org/jspringbot/keyword/i18n/SetI18nLanguage.java similarity index 86% rename from jspringbot-i18n/src/main/java/org/jspringbot/keyword/i18n/SetLanguage.java rename to jspringbot-i18n/src/main/java/org/jspringbot/keyword/i18n/SetI18nLanguage.java index cc48f4f..17e5a41 100644 --- a/jspringbot-i18n/src/main/java/org/jspringbot/keyword/i18n/SetLanguage.java +++ b/jspringbot-i18n/src/main/java/org/jspringbot/keyword/i18n/SetI18nLanguage.java @@ -23,8 +23,8 @@ @Component -@KeywordInfo(name = "Set Language", description = "Set Language.", parameters = {"language"}) -public class SetLanguage extends Abstracti18nKeyword { +@KeywordInfo(name = "Set i18n Language", description = "Set Language.", parameters = {"language"}) +public class SetI18nLanguage extends Abstracti18nKeyword { @Override public Object execute(Object[] params) { diff --git a/jspringbot-json/pom.xml b/jspringbot-json/pom.xml index 3bdae27..392d5e2 100644 --- a/jspringbot-json/pom.xml +++ b/jspringbot-json/pom.xml @@ -45,7 +45,7 @@ org.jspringbot - jspringbot-syntax-highlight + jspringbot-pretty-logger ${project.version} diff --git a/jspringbot-pretty-logger/pom.xml b/jspringbot-pretty-logger/pom.xml index 7cb28e9..08ab0ec 100644 --- a/jspringbot-pretty-logger/pom.xml +++ b/jspringbot-pretty-logger/pom.xml @@ -31,11 +31,11 @@ org.jspringbot - jspringbot-syntax-highlight + jspringbot-pretty-logger 1.0-SNAPSHOT jar - jspringbot-syntax-highlight + jspringbot-pretty-logger diff --git a/jspringbot-selenium/pom.xml b/jspringbot-selenium/pom.xml index 8733b3a..04aab18 100644 --- a/jspringbot-selenium/pom.xml +++ b/jspringbot-selenium/pom.xml @@ -59,7 +59,7 @@ org.jspringbot - jspringbot-syntax-highlight + jspringbot-pretty-logger ${project.version} diff --git a/jspringbot-ssh/pom.xml b/jspringbot-ssh/pom.xml index 5ab8b22..a8224c7 100644 --- a/jspringbot-ssh/pom.xml +++ b/jspringbot-ssh/pom.xml @@ -54,7 +54,7 @@ org.jspringbot - jspringbot-syntax-highlight + jspringbot-pretty-logger ${project.version} diff --git a/jspringbot-xml/pom.xml b/jspringbot-xml/pom.xml index a1d0ebe..47e483f 100644 --- a/jspringbot-xml/pom.xml +++ b/jspringbot-xml/pom.xml @@ -45,7 +45,7 @@ org.jspringbot - jspringbot-syntax-highlight + jspringbot-pretty-logger ${project.version}