Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gov.bsp.lcmis.internal.test;
- import java.math.BigDecimal;
- import java.util.ArrayList;
- import java.util.List;
- import javax.naming.NamingException;
- import org.junit.BeforeClass;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.ApplicationContextAware;
- import org.springframework.jdbc.datasource.DriverManagerDataSource;
- import org.springframework.mock.jndi.SimpleNamingContextBuilder;
- import org.springframework.test.context.ActiveProfiles;
- import org.springframework.test.context.ContextConfiguration;
- import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
- import org.springframework.test.context.web.WebAppConfiguration;
- import com.ibm.icu.impl.Assert;
- import gov.bsp.lcmis.internal.rates.domain.ELRates;
- import gov.bsp.lcmis.internal.report.domain.ComputedRvcReportItem;
- import gov.bsp.lcmis.internal.report.domain.ElReleaseValue;
- import gov.bsp.lcmis.internal.report.domain.PromissoryNote;
- import gov.bsp.lcmis.internal.utilities.DateConverter;
- import gov.bsp.lcmis.internal.utilities.domain.ELRvcReportItemProcessorRateAdapter;
- @RunWith(SpringJUnit4ClassRunner.class)
- @WebAppConfiguration
- @ContextConfiguration(value = "file:src/main/webapp/WEB-INF/dispatcher-servlet.xml")
- @ActiveProfiles("test")
- public class ReusableUnitTest implements ApplicationContextAware {
- private ApplicationContext applicationContext;
- private static Logger log = LoggerFactory.getLogger(ReusableUnitTest.class);
- /**
- * SET THE DATABASE CREDS and URL
- */
- private static String url = "jdbc:db2://localhost:50000/mydb2";
- private static String username = "db2admin";
- private static String password = "password123";
- /**
- * Note to Architect : please setup an environment dependent datasource
- * to remove the need for commenting and uncommenting the @Test method.
- */
- @BeforeClass
- public static void setupClass() {
- //create the datasource
- DriverManagerDataSource datasource = new DriverManagerDataSource(url, username, password);
- datasource.setDriverClassName("com.ibm.db2.jcc.DB2Driver");
- //bind to a jndi string
- SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
- builder.bind("lcmisbsp", datasource);
- builder.bind("${lcmissequencebsp.jndi.name}", datasource);
- builder.bind("${cfas.jndi.name}", datasource);
- builder.bind("${ops.jndi.name}", datasource);
- try {
- builder.activate();
- } catch (IllegalStateException | NamingException e) {
- log.error("Error setting up test class, ", e);
- }
- }
- @Test
- public void test() {
- try {
- log.info("MCI >> ReusableUnitTest");
- PromissoryNote rvb = new PromissoryNote();
- rvb.setOutstandingPrincipal(BigDecimal.TEN);
- DateConverter conv = new DateConverter();
- rvb.setLoanGrantedDate(conv.convertStringToDate("12/12/2005"));
- rvb.setPnGrantedDate(conv.convertStringToDate("12/12/2005"));
- rvb.setPnMaturityDate(conv.convertStringToDate("06/22/2007"));
- ELRates elRate = new ELRates();
- elRate.setRate(new BigDecimal("0.6"));
- elRate.setFromDate(conv.convertStringToDate("09/05/2005"));
- ELRates elRate2 = new ELRates();
- elRate2.setRate(new BigDecimal("0.7"));
- elRate2.setFromDate(conv.convertStringToDate("10/06/2006"));
- List<ELRvcReportItemProcessorRateAdapter> rates = new ArrayList<ELRvcReportItemProcessorRateAdapter>();
- rates.add(elRate);
- rates.add(elRate2);
- ElReleaseValue erv = applicationContext.getBean("elReleaseValue", ElReleaseValue.class);
- erv.setPn(rvb);
- erv.setRates(rates);
- erv.of(rvb).at(conv.convertStringToDate("01/15/2010"));
- Assert.assrt(erv != null);
- log.info("list size: " + erv.getComputedRvcReportList().size());
- for (ComputedRvcReportItem item : erv.getComputedRvcReportList()) {
- log.info(new StringBuilder("accrued interest income: ").append(item.getAir())
- .append(" | interest income: ").append(item.getInterestIncome())
- .append(" | liquidated damages: ").append(item.getLiquidatedDamages())
- .append(" | computation rate: ").append(item.getComputationRate())
- .append(" | repricing rate: ").append(item.getRepricingRate())
- .append(" | ld rate: ").append(item.getLdRate())
- .append("from date: " + item.getValueTerm().getFromDate() + " | to date: " + item.getValueTerm().getToDate())
- .toString());
- }
- } catch (Exception e) {
- log.error("Error found. ", e);
- }
- log.info("MCO >> ReusableUnitTest");
- }
- // public static void main(String[] args) {
- // try {
- // OutputStream file = new FileOutputStream(new File("C:\\Users\\edward.cervantes\\Desktop\\Test.pdf"));
- //
- // Document document = new Document();
- // PdfWriter.getInstance(document, file);
- // document.open();
- // document.add(new Paragraph("Hello Kiran"));
- // document.add(new Paragraph(new Date().toString()));
- //
- // document.close();
- // file.close();
- //
- // } catch (Exception e) {
- //
- // e.printStackTrace();
- // }
- // }
- public void setApplicationContext(ApplicationContext applicationContext) {
- this.applicationContext = applicationContext;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement