Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.87 KB | None | 0 0
  1. package gov.bsp.lcmis.internal.test;
  2.  
  3. import java.math.BigDecimal;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7. import javax.naming.NamingException;
  8.  
  9. import org.junit.BeforeClass;
  10. import org.junit.Test;
  11. import org.junit.runner.RunWith;
  12. import org.slf4j.Logger;
  13. import org.slf4j.LoggerFactory;
  14. import org.springframework.context.ApplicationContext;
  15. import org.springframework.context.ApplicationContextAware;
  16. import org.springframework.jdbc.datasource.DriverManagerDataSource;
  17. import org.springframework.mock.jndi.SimpleNamingContextBuilder;
  18. import org.springframework.test.context.ActiveProfiles;
  19. import org.springframework.test.context.ContextConfiguration;
  20. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  21. import org.springframework.test.context.web.WebAppConfiguration;
  22.  
  23. import com.ibm.icu.impl.Assert;
  24.  
  25. import gov.bsp.lcmis.internal.rates.domain.ELRates;
  26. import gov.bsp.lcmis.internal.report.domain.ComputedRvcReportItem;
  27. import gov.bsp.lcmis.internal.report.domain.ElReleaseValue;
  28. import gov.bsp.lcmis.internal.report.domain.PromissoryNote;
  29. import gov.bsp.lcmis.internal.utilities.DateConverter;
  30. import gov.bsp.lcmis.internal.utilities.domain.ELRvcReportItemProcessorRateAdapter;
  31.  
  32. @RunWith(SpringJUnit4ClassRunner.class)
  33. @WebAppConfiguration
  34. @ContextConfiguration(value = "file:src/main/webapp/WEB-INF/dispatcher-servlet.xml")
  35. @ActiveProfiles("test")
  36. public class ReusableUnitTest implements ApplicationContextAware {
  37.  
  38. private ApplicationContext applicationContext;
  39.  
  40. private static Logger log = LoggerFactory.getLogger(ReusableUnitTest.class);
  41.  
  42. /**
  43. * SET THE DATABASE CREDS and URL
  44. */
  45. private static String url = "jdbc:db2://localhost:50000/mydb2";
  46.  
  47. private static String username = "db2admin";
  48.  
  49. private static String password = "password123";
  50.  
  51. /**
  52. * Note to Architect : please setup an environment dependent datasource
  53. * to remove the need for commenting and uncommenting the @Test method.
  54. */
  55. @BeforeClass
  56. public static void setupClass() {
  57. //create the datasource
  58. DriverManagerDataSource datasource = new DriverManagerDataSource(url, username, password);
  59. datasource.setDriverClassName("com.ibm.db2.jcc.DB2Driver");
  60.  
  61. //bind to a jndi string
  62. SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
  63. builder.bind("lcmisbsp", datasource);
  64. builder.bind("${lcmissequencebsp.jndi.name}", datasource);
  65. builder.bind("${cfas.jndi.name}", datasource);
  66. builder.bind("${ops.jndi.name}", datasource);
  67.  
  68. try {
  69. builder.activate();
  70. } catch (IllegalStateException | NamingException e) {
  71. log.error("Error setting up test class, ", e);
  72. }
  73. }
  74.  
  75. @Test
  76. public void test() {
  77. try {
  78. log.info("MCI >> ReusableUnitTest");
  79. PromissoryNote rvb = new PromissoryNote();
  80.  
  81. rvb.setOutstandingPrincipal(BigDecimal.TEN);
  82.  
  83.  
  84. DateConverter conv = new DateConverter();
  85. rvb.setLoanGrantedDate(conv.convertStringToDate("12/12/2005"));
  86. rvb.setPnGrantedDate(conv.convertStringToDate("12/12/2005"));
  87. rvb.setPnMaturityDate(conv.convertStringToDate("06/22/2007"));
  88.  
  89. ELRates elRate = new ELRates();
  90. elRate.setRate(new BigDecimal("0.6"));
  91. elRate.setFromDate(conv.convertStringToDate("09/05/2005"));
  92.  
  93. ELRates elRate2 = new ELRates();
  94. elRate2.setRate(new BigDecimal("0.7"));
  95. elRate2.setFromDate(conv.convertStringToDate("10/06/2006"));
  96.  
  97. List<ELRvcReportItemProcessorRateAdapter> rates = new ArrayList<ELRvcReportItemProcessorRateAdapter>();
  98. rates.add(elRate);
  99. rates.add(elRate2);
  100.  
  101. ElReleaseValue erv = applicationContext.getBean("elReleaseValue", ElReleaseValue.class);
  102. erv.setPn(rvb);
  103. erv.setRates(rates);
  104. erv.of(rvb).at(conv.convertStringToDate("01/15/2010"));
  105.  
  106. Assert.assrt(erv != null);
  107.  
  108. log.info("list size: " + erv.getComputedRvcReportList().size());
  109.  
  110. for (ComputedRvcReportItem item : erv.getComputedRvcReportList()) {
  111. log.info(new StringBuilder("accrued interest income: ").append(item.getAir())
  112. .append(" | interest income: ").append(item.getInterestIncome())
  113. .append(" | liquidated damages: ").append(item.getLiquidatedDamages())
  114. .append(" | computation rate: ").append(item.getComputationRate())
  115. .append(" | repricing rate: ").append(item.getRepricingRate())
  116. .append(" | ld rate: ").append(item.getLdRate())
  117. .append("from date: " + item.getValueTerm().getFromDate() + " | to date: " + item.getValueTerm().getToDate())
  118. .toString());
  119. }
  120.  
  121. } catch (Exception e) {
  122. log.error("Error found. ", e);
  123. }
  124. log.info("MCO >> ReusableUnitTest");
  125. }
  126.  
  127. // public static void main(String[] args) {
  128. // try {
  129. // OutputStream file = new FileOutputStream(new File("C:\\Users\\edward.cervantes\\Desktop\\Test.pdf"));
  130. //
  131. // Document document = new Document();
  132. // PdfWriter.getInstance(document, file);
  133. // document.open();
  134. // document.add(new Paragraph("Hello Kiran"));
  135. // document.add(new Paragraph(new Date().toString()));
  136. //
  137. // document.close();
  138. // file.close();
  139. //
  140. // } catch (Exception e) {
  141. //
  142. // e.printStackTrace();
  143. // }
  144. // }
  145.  
  146. public void setApplicationContext(ApplicationContext applicationContext) {
  147. this.applicationContext = applicationContext;
  148. }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement