/**
Copyright 2012 Shakil Siraj (shakil.siraj@gmail.com)
Licensed 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 com.googlecode.objectify.test.dataloader.example.bookstore.dao;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Logger;
import org.apache.commons.lang.time.StopWatch;
import org.testng.Assert;
import org.testng.annotations.Test;
import com.googlecode.objectify.test.dataloader.ObjectifiedTest;
import com.googlecode.objectify.test.dataloader.annotation.Dataloader;
import com.googlecode.objectify.test.dataloader.annotation.EntitiesList;
import com.googlecode.objectify.test.dataloader.example.bookstore.PaymentType;
import com.googlecode.objectify.test.dataloader.example.bookstore.SaleRecord;
/**
* @author Shakil Siraj (shakil.siraj@gmail.com)
*
*/
@EntitiesList(classes={SaleRecord.class})
@Dataloader(config = "../xml/smooks_config.xml", file = "../xml/salerecords.xml")
public class SaleRecordsDAOTest extends ObjectifiedTest {
/**
* Log4J logger for the class.
*/
private final Logger LOGGER = Logger.getLogger(SaleRecordsDAOTest.class
.getName());
@Test(groups = { OFY_DATALOADER_GROUP })
public void testGetTotalNumberOfRecords() {
SaleRecordsDAO dao = new SaleRecordsDAO();
Assert.assertEquals(dao.getTotalNumberOfSaleRecords().intValue(), 9999);
}
@Test(groups = { OFY_DATALOADER_GROUP })
public void testGetTotalNumberOfSalesForPaymentTypeUsingBatch() throws Exception {
SaleRecordsDAO dao = new SaleRecordsDAO();
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
Date startDate = formatter.parse("01/01/2010");
Date endDate = formatter.parse("01/01/2011");
StopWatch stopWatch = new StopWatch();
stopWatch.start();
Assert.assertEquals(dao.getTotalNumberOfSalesForPaymentTypeUsingBatch(PaymentType.VISA, startDate, endDate).intValue(), 5448);
stopWatch.stop();
LOGGER.info("SaleRecordsDAOTest.testGetTotalNumberOfSalesForPaymentTypeUsingBatch - batch fetching took " + stopWatch);
}
@Test(groups = { OFY_DATALOADER_GROUP })
public void testGetTotalNumberOfSalesForPaymentTypeUsingFetchAll() throws Exception {
SaleRecordsDAO dao = new SaleRecordsDAO();
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
Date startDate = formatter.parse("01/01/2010");
Date endDate = formatter.parse("01/01/2011");
StopWatch stopWatch = new StopWatch();
stopWatch.start();
Assert.assertEquals(dao.getTotalNumberOfSalesForPaymentTypeUsingFethcAll(PaymentType.VISA, startDate, endDate).intValue(), 5448);
stopWatch.stop();
LOGGER.info("SaleRecordsDAOTest.testGetTotalNumberOfSalesForPaymentTypeUsingFetchAll - batch fetching took " + stopWatch);
}
}