/* this test fails if the current time is between 12:00am and 3:00am*/
Calendar now = Calendar.getInstance();
int hour = now.get(Calendar.HOUR_OF_DAY);
String timeCheck = "Current time not between 12:00am and 3:00am";
String timeDescription = "Current time" + ((hour < 3) ? "" : " not") + " between 12:00am and 3:00am";
Assume.assumeThat(timeDescription, equalTo(timeCheck));
Assume is package org.junit;(public class Assume )
Friday, August 22, 2008
Thursday, August 21, 2008
ANTLR
Today i worked with some text character parsing. In our project, they have used ANTLR parser. ANTLR, ANother Tool for Language Recognition, is a language tool that provides a framework for constructing recognizers, interpreters, compilers, and translators from grammatical descriptions containing actions in a variety of target languages. ANTLR provides excellent support for tree construction, tree walking, translation, error recovery, and error reporting.
http://www.antlr.org/
We have used both Class LLkParser and Class Parser.Alos one important interface that provides is Interface AST in antlr.collections.
http://www.antlr2.org/javadoc/antlr/LLkParser.html
http://www.antlr2.org/javadoc/antlr/Parser.html#LA(int)
http://www.antlr2.org/javadoc/antlr/collections/AST.html
http://www.antlr.org/
We have used both Class LLkParser and Class Parser.Alos one important interface that provides is Interface AST in antlr.collections.
http://www.antlr2.org/javadoc/antlr/LLkParser.html
http://www.antlr2.org/javadoc/antlr/Parser.html#LA(int)
http://www.antlr2.org/javadoc/antlr/collections/AST.html
Thursday, August 14, 2008
Payment gateway
A payment gateway is an e-commerce application service provider service that authorizes payments for e-businesses, online retailers, bricks and clicks, or traditional brick and mortar. Paypal and SecurePay are two common payment gateways. Following are the list of gateways.
http://www.paymentgatewaydirectory.com/
In our project we use saferpay payment gateway. In billing-services.xml,
< bean id="billing.paymentService"
class="com.fastsearch.admomentum.billing.service.DefaultPaymentService">
. . .
< !-- this bean is defined in fast-admomentum-paymentgateway.jar -->
< property name="paymentGateway" ref="saferpayPaymentGateway" />
. . .
< /bean>
and in base-configuration.properties, there are lots of configurations.
one of them are,
# The merchant account id with Saferpay
com.fastsearch.admomentum.paymentgateway.saferpay.accountId=XXXXX-XXXXXXXXX
Wednesday, August 13, 2008
Java Unit testing
This is a simple test class i wrote to test following method.
package com.fastsearch.admomentum.common.time;
import java.io.Serializable;
import java.util.Calendar;
........
public class DateRange implements Serializable {
.....
public boolean isBetween(Calendar date) {
if (getEnd() != null) {
return (date.after(getStart()) && date.before(getEnd()))
|| date.equals(getStart()) || date.equals(getEnd());
} else {
return date.after(getStart()) || date.equals(getStart());
}
}
}
----------------------------------------------
package com.fastsearch.admomentum.common.time;
import junit.framework.TestCase;
import java.util.Calendar;
public class DateRangeUnitTest extends TestCase {
private DateRange dateRange;
public void testIsBetween()
{
assertFalse(isBetweenOutOfBoundTest());
}
private boolean isBetweenOutOfBoundTest()
{
Calendar testDate = Calendar.getInstance();
testDate.clear();
testDate.set(Calendar.YEAR,2007);
testDate.set(Calendar.MONTH,4);
testDate.set(Calendar.DATE,1);
Calendar startDate = Calendar.getInstance();
startDate.clear();
startDate.set(Calendar.YEAR,2007);
startDate.set(Calendar.MONTH,5);
startDate.set(Calendar.DATE,1);
Calendar endDate = Calendar.getInstance();
endDate.clear();
endDate.set(Calendar.YEAR,2007);
endDate.set(Calendar.MONTH,7);
endDate.set(Calendar.DATE,1);
dateRange = new DateRange(startDate, endDate);
return dateRange.isBetween(testDate);
}
}
package com.fastsearch.admomentum.common.time;
import java.io.Serializable;
import java.util.Calendar;
........
public class DateRange implements Serializable {
.....
public boolean isBetween(Calendar date) {
if (getEnd() != null) {
return (date.after(getStart()) && date.before(getEnd()))
|| date.equals(getStart()) || date.equals(getEnd());
} else {
return date.after(getStart()) || date.equals(getStart());
}
}
}
----------------------------------------------
package com.fastsearch.admomentum.common.time;
import junit.framework.TestCase;
import java.util.Calendar;
public class DateRangeUnitTest extends TestCase {
private DateRange dateRange;
public void testIsBetween()
{
assertFalse(isBetweenOutOfBoundTest());
}
private boolean isBetweenOutOfBoundTest()
{
Calendar testDate = Calendar.getInstance();
testDate.clear();
testDate.set(Calendar.YEAR,2007);
testDate.set(Calendar.MONTH,4);
testDate.set(Calendar.DATE,1);
Calendar startDate = Calendar.getInstance();
startDate.clear();
startDate.set(Calendar.YEAR,2007);
startDate.set(Calendar.MONTH,5);
startDate.set(Calendar.DATE,1);
Calendar endDate = Calendar.getInstance();
endDate.clear();
endDate.set(Calendar.YEAR,2007);
endDate.set(Calendar.MONTH,7);
endDate.set(Calendar.DATE,1);
dateRange = new DateRange(startDate, endDate);
return dateRange.isBetween(testDate);
}
}
mvn commands
- clean
mvn clean
- build
mvn install
- skip all the test
mvn install -P test-unit -Dmaven.test.skip=true
mvn install -o -P test-unit -Dmaven.test.skip=true
- run all the tests including selenium tests
mvn -Ptest-all install
- run specific tests (unit test or selenium test)
mvn install -Ptest-all -Dtest=com.fastsearch.admomentum..ClassName
mvn install -P test-all -Dtest=AdvertisementSeleniumTest
mvn install -Dtest=com.fastsearch.admomentum.common.time.DateRangeUnitTest -o -Ptest-all
- run specific tests (unit test or selenium test) with degugging
mvn install -Dtest=com.fastsearch.admomentum.admanager.webapp.selenium.campaign.CampaignSeleniumTest -o -Dmaven.surefire.debug -Ptest-all
mvn install -Dtest=com.fastsearch.admomentum.admanager.reporting.DefaultReportingServiceUnitTest -o -Dmaven.surefire.debug -Ptest-all
mvn clean
- build
mvn install
- skip all the test
mvn install -P test-unit -Dmaven.test.skip=true
mvn install -o -P test-unit -Dmaven.test.skip=true
- run all the tests including selenium tests
mvn -Ptest-all install
- run specific tests (unit test or selenium test)
mvn install -Ptest-all -Dtest=com.fastsearch.admomentum.
mvn install -P test-all -Dtest=AdvertisementSeleniumTest
mvn install -Dtest=com.fastsearch.admomentum.common.time.DateRangeUnitTest -o -Ptest-all
- run specific tests (unit test or selenium test) with degugging
mvn install -Dtest=com.fastsearch.admomentum.admanager.webapp.selenium.campaign.CampaignSeleniumTest -o -Dmaven.surefire.debug -Ptest-all
mvn install -Dtest=com.fastsearch.admomentum.admanager.reporting.DefaultReportingServiceUnitTest -o -Dmaven.surefire.debug -Ptest-all
Tuesday, August 12, 2008
Cargo
Cargo is a thin wrapper around existing containers (e.g. J2EE containers). It provides different APIs to easily manipulate containers.
Cargo provides the following APIs:
* A Java API to start/stop/configure Java Containers and deploy modules into them. Also Ant tasks, Maven 1, Maven 2 plugins. Intellij IDEA and Netbeans plugins are offered.
* A Java API to parse/create/merge J2EE Modules
Following are some containers.
* Geronimo 1.x
* JBoss 3.x
* JBoss 4.x
* Jetty 4.x
* Jetty 5.x
* Jetty 6.x
* jo 1.x
* Oc4J 9.x
* Orion 1.x
* Orion 2.x
* Resin 2.x
* Resin 3.x
* Tomcat 3.x
* Tomcat 4.x
* Tomcat 5.x
* WebLogic 8.x
Cargo provides the following APIs:
* A Java API to start/stop/configure Java Containers and deploy modules into them. Also Ant tasks, Maven 1, Maven 2 plugins. Intellij IDEA and Netbeans plugins are offered.
* A Java API to parse/create/merge J2EE Modules
Following are some containers.
* Geronimo 1.x
* JBoss 3.x
* JBoss 4.x
* Jetty 4.x
* Jetty 5.x
* Jetty 6.x
* jo 1.x
* Oc4J 9.x
* Orion 1.x
* Orion 2.x
* Resin 2.x
* Resin 3.x
* Tomcat 3.x
* Tomcat 4.x
* Tomcat 5.x
* WebLogic 8.x
Difference between 'vi' and 'vim' editors
vim is 'vi improved'
More powerful, etc
http://www.dc.turkuamk.fi/docs/soft/vim/vim_diff.html
More powerful, etc
http://www.dc.turkuamk.fi/docs/soft/vim/vim_diff.html
Thursday, August 7, 2008
Job scheduling with Quartz
Quartz is an open source job scheduling framework that provides simple but powerful mechanisms for job scheduling in Java applications. Quartz allows developers to schedule jobs by time interval or by time of day. The two fundamental units of Quartz's scheduling package are jobs and triggers. A job is an executable task that can be scheduled, while a trigger provides a schedule for a job.
Also, any singular job can have many triggers associated with it.
A CronTrigger allows for more specific scheduling than a SimpleTrigger and is still not very complex. Based on cron expressions, CronTriggers allow for calendar-like repeat intervals rather than uniform repeat intervals -- a major improvement over SimpleTriggers.
A "Cron-Expression" is a string comprised of 6 or 7 fields separated by white space. There are 6 mandatory and 1 optional fields.
Field Name
Seconds
Minutes
Hours
Day-of-month
Month
Day-of-Week
Year (Optional)
Expression Meaning
"0 0 12 * * ?" Fire at 12pm (noon) every day
useful links:
http://www-128.ibm.com/developerworks/java/library/j-quartz/
http://quartz.sourceforge.net/javadoc/org/quartz/CronTrigger.html
Also, any singular job can have many triggers associated with it.
A CronTrigger allows for more specific scheduling than a SimpleTrigger and is still not very complex. Based on cron expressions, CronTriggers allow for calendar-like repeat intervals rather than uniform repeat intervals -- a major improvement over SimpleTriggers.
A "Cron-Expression" is a string comprised of 6 or 7 fields separated by white space. There are 6 mandatory and 1 optional fields.
Field Name
Seconds
Minutes
Hours
Day-of-month
Month
Day-of-Week
Year (Optional)
Expression Meaning
"0 0 12 * * ?" Fire at 12pm (noon) every day
useful links:
http://www-128.ibm.com/developerworks/java/library/j-quartz/
http://quartz.sourceforge.net/javadoc/org/quartz/CronTrigger.html
Tuesday, August 5, 2008
Daylight saving time
Daylight saving time (DST; also summer time in British English; see Terminology) is the convention of advancing clocks so that afternoons have more daylight and mornings have less. Typically clocks are adjusted forward one hour near the start of spring and are adjusted backward in autumn.
http://en.wikipedia.org/wiki/Daylight_saving_time
In Java, there are two ways to create days. One method is using Calender object.
Calendar c = Calendar.getInstance();
c.clear();
c.set(Calendar.YEAR,2007);
c.set(Calendar.MONTH,9);
c.set(Calendar.DATE,31);
System.out.println(c.getTime());
c.add(Calendar.DATE,1);
System.out.println(c.getTime());
private List calculateIntervals(DateRange dateRange) {
Date date = dateRange.getStart().getTime();
Calendar c = Calendar.getInstance();
c.clear();
c.setTimeZone(dateRange.getStart().getTimeZone());
c.setTime(dateRange.getStart().getTime());
List dates = new ArrayList();
while (c.getTime().compareTo(dateRange.getEnd().getTime()) <= 0) {
dates.add(c.getTime());
Calendar nextDate = (Calendar) c.clone();
nextDate.add(Calendar.DATE,1);
c = nextDate;
}
return dates;
}
This timezone don't work with daylight saving time. The other way is using Date object.
private List calculateIntervals(DateRange dateRange) {
Date date = dateRange.getStart().getTime();
List dates = new ArrayList();
while (date.compareTo(dateRange.getEnd().getTime()) <= 0) {
dates.add(date);
Date nextDate = (Date) date.clone();
nextDate = DateUtils.addDays(nextDate, 1);
date = nextDate;
}
return dates;
}
This Date object time zone cater with daylight-saving time. In date object->cdate->daylightSaving parameter contains the time in milisecond that should add to the date for daylight-saving changes.
http://en.wikipedia.org/wiki/Daylight_saving_time
In Java, there are two ways to create days. One method is using Calender object.
Calendar c = Calendar.getInstance();
c.clear();
c.set(Calendar.YEAR,2007);
c.set(Calendar.MONTH,9);
c.set(Calendar.DATE,31);
System.out.println(c.getTime());
c.add(Calendar.DATE,1);
System.out.println(c.getTime());
private List
Date date = dateRange.getStart().getTime();
Calendar c = Calendar.getInstance();
c.clear();
c.setTimeZone(dateRange.getStart().getTimeZone());
c.setTime(dateRange.getStart().getTime());
List
while (c.getTime().compareTo(dateRange.getEnd().getTime()) <= 0) {
dates.add(c.getTime());
Calendar nextDate = (Calendar) c.clone();
nextDate.add(Calendar.DATE,1);
c = nextDate;
}
return dates;
}
This timezone don't work with daylight saving time. The other way is using Date object.
private List
Date date = dateRange.getStart().getTime();
List
while (date.compareTo(dateRange.getEnd().getTime()) <= 0) {
dates.add(date);
Date nextDate = (Date) date.clone();
nextDate = DateUtils.addDays(nextDate, 1);
date = nextDate;
}
return dates;
}
This Date object time zone cater with daylight-saving time. In date object->cdate->daylightSaving parameter contains the time in milisecond that should add to the date for daylight-saving changes.
Subscribe to:
Posts (Atom)